Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: move process prototype manipulation into setupProcessObject
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.
  • Loading branch information
joyeecheung committed Nov 4, 2018
commit 32077cf684efc34cb357865fe7dadd231f88e3cf
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