Skip to content

Commit 453c96e

Browse files
joyeecheungBridgeAR
authored andcommitted
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: #24089 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 6a6b036 commit 453c96e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/internal/bootstrap/node.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030
const isMainThread = internalBinding('worker').threadId === 0;
3131

3232
function startup() {
33-
const EventEmitter = NativeModule.require('events');
34-
35-
const origProcProto = Object.getPrototypeOf(process);
36-
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
37-
38-
EventEmitter.call(process);
39-
4033
setupTraceCategoryState();
4134

4235
setupProcessObject();
@@ -378,6 +371,11 @@
378371
}
379372

380373
function setupProcessObject() {
374+
const EventEmitter = NativeModule.require('events');
375+
const origProcProto = Object.getPrototypeOf(process);
376+
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
377+
EventEmitter.call(process);
378+
381379
_setupProcessObject(pushValueToArray);
382380

383381
function pushValueToArray() {

0 commit comments

Comments
 (0)