From 453c96ed2d61fb82dd9cc98fcffcc400b0d837b4 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 5 Nov 2018 02:06:23 +0800 Subject: [PATCH] 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 Reviewed-By: Gus Caplan Reviewed-By: Colin Ihrig --- lib/internal/bootstrap/node.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 324fdb71a62389..d95f1aa2939a76 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -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() {