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 BridgeAR committed Nov 13, 2018
1 parent 6a6b036 commit 453c96e
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 @@ -30,13 +30,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);

setupTraceCategoryState();

setupProcessObject();
Expand Down Expand Up @@ -378,6 +371,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 453c96e

Please sign in to comment.