Skip to content

Commit

Permalink
lib: move process prototype manipulation into setupProcessObject
Browse files Browse the repository at this point in the history
Since no operation is requiring process to be an EventEmitter before
setupProcessObject is called, it's safe to set up the prototype chain
in setupProcessObject and make the main code path more readable.

PR-URL: #24089
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joyeecheung authored and MylesBorins committed Dec 3, 2018
1 parent a67e04e commit a0b4f7a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
const isMainThread = internalBinding('worker').threadId === 0;

function startup() {
const EventEmitter = NativeModule.require('events');

const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);

EventEmitter.call(process);

setupProcessObject();

// Do this good and early, since it handles errors.
Expand Down Expand Up @@ -335,6 +328,11 @@
}

function setupProcessObject() {
const EventEmitter = NativeModule.require('events');
const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
EventEmitter.call(process);

_setupProcessObject(pushValueToArray);

function pushValueToArray() {
Expand Down

0 comments on commit a0b4f7a

Please sign in to comment.