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 authored and Ruben Bridgewater committed 2018-11-13 23:37:32 +01:00
1 parent 6a6b036042
commit 453c96ed2d
1 file changed
+5 -7
+5 -7
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() {