Repository: nodejs/node
File: lib/internal/worker.js (JavaScript)

Code before:
    const stdout = new ReadableWorkerStdio(this[kPort], 'stdout');
    if (!options.stdout) {
      stdout[kIncrementsPortRef] = false;
      pipeWithoutWarning(stdout, process.stdout);
    }
    const stderr = new ReadableWorkerStdio(this[kPort], 'stderr');
    if (!options.stderr) {
      stderr[kIncrementsPortRef] = false;
      pipeWithoutWarning(stderr, process.stderr);
    }

    this[kParentSideStdio] = { stdin, stdout, stderr };

    const { port1, port2 } = new MessageChannel();
    const transferList = [port2];
    // If transferList is provided.
    if (options.transferList)
      ArrayPrototypePush(transferList,
                         ...new SafeArrayIterator(options.transferList));

    this[kPublicPort] = port1;
    const {
      port1: toWorkerThread,
      port2: toHooksThread,
    } = new MessageChannel();
    if (!isInternal) {
      // This is not an internal hooks thread => it needs a channel to the hooks thread:
      // - send it one side of a channel here
      ArrayPrototypePush(transferList, toHooksThread);
    }
    ArrayPrototypeForEach(['message', 'messageerror'], (event) => {
      this[kPublicPort].on(event, (message) => this.emit(event, message));
    });
    setupPortReferencing(this[kPublicPort], this, 'message');
    this[kPort].postMessage({
      argv,
      type: messageTypes.LOAD_SCRIPT,
      filename,
      doEval,
      isInternal,
      cwdCounter: cwdCounter || workerIo.sharedCwdCounter,
      workerData: options.workerData,
      environmentData,
      publicPort: port2,
      hooksPort: !isInternal ? toHooksThread : undefined,
      manifestURL: getOptionValue('--experimental-policy') ?
        require('internal/process/policy').url :
        null,
      manifestSrc: getOptionValue('--experimental-policy') ?
        require('internal/process/policy').src :
        null,

Review comment (suggestion):
is the `isInternal` flag only used by hooks thread?
if yes, the name should be likely changed (maybe in a followup).

Code after:
    if (!options.stdout) {
      stdout[kIncrementsPortRef] = false;
      pipeWithoutWarning(stdout, process.stdout);
    }
    const stderr = new ReadableWorkerStdio(this[kPort], 'stderr');
    if (!options.stderr) {
      stderr[kIncrementsPortRef] = false;
      pipeWithoutWarning(stderr, process.stderr);
    }

    this[kParentSideStdio] = { stdin, stdout, stderr };

    const { port1, port2 } = new MessageChannel();
    const transferList = [port2];
    // If transferList is provided.
    if (options.transferList)
      ArrayPrototypePush(transferList,
                         ...new SafeArrayIterator(options.transferList));

    this[kPublicPort] = port1;
    const {
      port1: toWorkerThread,
      port2: toHooksThread,
    } = new MessageChannel();
    if (!isInternal) {
      // This is not an internal hooks thread => it needs a channel to the hooks thread:
      // - send it one side of a channel here
      ArrayPrototypePush(transferList, toHooksThread);
    }
    ArrayPrototypeForEach(['message', 'messageerror'], (event) => {
      this[kPublicPort].on(event, (message) => this.emit(event, message));
    });
    setupPortReferencing(this[kPublicPort], this, 'message');
    this[kPort].postMessage({
      argv,
      type: messageTypes.LOAD_SCRIPT,
      filename,
      doEval,
      isInternal,
      cwdCounter: cwdCounter || workerIo.sharedCwdCounter,
      workerData: options.workerData,
      environmentData,
      publicPort: port2,
      hooksPort: !isInternal ? toHooksThread : undefined,
      hasStdin: !!options.stdin,
    }, transferList);

    const loaderModule = require('internal/modules/esm/loader');
    const hasCustomizations = loaderModule.hasCustomizations();

    if (!isInternal && hasCustomizations) {