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.

PR-URL: https://github.com/nodejs/node/pull/24089
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
Joyee Cheung 2018-11-05 02:06:23 +08:00 committed by Rich Trott
parent 7bd8bbaabf
commit 56ce6f191d

View File

@ -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();
@ -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() {