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

Code before:
      transferList.push(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,
      hasStdin: !!options.stdin,
    }, transferList);
    const loaderModule = require('internal/modules/esm/loader');
    const hasCustomizations = loaderModule.hasCustomizations();
    if (!isInternal && hasCustomizations) {
      // - send the second side of the channel to the hooks thread
      loaderModule.getHooksProxy().makeAsyncRequest(
        '#registerWorkerClient', [toWorkerThread], toWorkerThread);
    }
    // Use this to cache the Worker's loopStart value once available.
    this[kLoopStartTime] = -1;
    this[kIsOnline] = false;
    this.performance = {
      eventLoopUtilization: FunctionPrototypeBind(eventLoopUtilization, this),
    };
    // Actually start the new thread now that everything is in place.
    this[kHandle].startThread();

    process.nextTick(() => process.emit('worker', this));
    if (workerThreadsChannel.hasSubscribers) {
      workerThreadsChannel.publish({
        worker: this,
      });
    }
  }

  [kOnExit](code, customErr, customErrReason) {
    debug(`[${threadId}] hears end event for Worker ${this.threadId}`);

Review comment (suggestion):
nit (whitespace)

```suggestion

    const loaderModule = require('internal/modules/esm/loader');
    const hasCustomizations = loaderModule.hasCustomizations();

    if (!isInternal && hasCustomizations) {
```

Code after:
      // 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) {
      // - send the second side of the channel to the hooks thread,
      // also announce the threadId of the Worker that will use that port.
      // This is needed for the cleanup stage
      loaderModule.getHooksProxy().makeSyncRequest(
        '#registerWorkerClient', [toWorkerThread], toWorkerThread, this.threadId);
    }
    // Use this to cache the Worker's loopStart value once available.
    this[kLoopStartTime] = -1;
    this[kIsOnline] = false;
    this.performance = {
      eventLoopUtilization: FunctionPrototypeBind(eventLoopUtilization, this),
    };
    // Actually start the new thread now that everything is in place.
    this[kHandle].startThread();

    process.nextTick(() => process.emit('worker', this));
    if (workerThreadsChannel.hasSubscribers) {
      workerThreadsChannel.publish({
        worker: this,
      });
    }
  }

  [kOnExit](code, customErr, customErrReason) {
    debug(`[${threadId}] hears end event for Worker ${this.threadId}`);