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: nodejs#24089
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
joyeecheung authored and kiyomizumia committed Nov 15, 2018
1 parent d309cc5 commit 8590b73
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 8590b73

Please sign in to comment.