Skip to content

Commit 415963a

Browse files
joyeecheungcodebytere
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 <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 517d6f3 commit 415963a

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
@@ -28,13 +28,6 @@
2828
const isMainThread = internalBinding('worker').threadId === 0;
2929

3030
function startup() {
31-
const EventEmitter = NativeModule.require('events');
32-
33-
const origProcProto = Object.getPrototypeOf(process);
34-
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
35-
36-
EventEmitter.call(process);
37-
3831
setupProcessObject();
3932

4033
// Do this good and early, since it handles errors.
@@ -335,6 +328,11 @@
335328
}
336329

337330
function setupProcessObject() {
331+
const EventEmitter = NativeModule.require('events');
332+
const origProcProto = Object.getPrototypeOf(process);
333+
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
334+
EventEmitter.call(process);
335+
338336
_setupProcessObject(pushValueToArray);
339337

340338
function pushValueToArray() {

0 commit comments

Comments
 (0)