Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
process: keep process prototype in inheritance chain
The global `process` object had its prototype replaced with a
fresh object that had `EventEmitter.prototype` as its prototype.
With this change, the original `process.constructor.prototype` is
modified to have `EventEmitter.prototype` as its prototype, reflecting
that `process` objects are also `EventEmitter`s.

Fixes: #14699
  • Loading branch information
MSLaguana committed Aug 10, 2017
commit a0b4a4a47d914f7802dd1d2b486b49641cbdc181
4 changes: 1 addition & 3 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
process._eventsCount = 0;

const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(process, Object.create(EventEmitter.prototype, {
constructor: Object.getOwnPropertyDescriptor(origProcProto, 'constructor')
}));
Object.setPrototypeOf(origProcProto, EventEmitter.prototype);

EventEmitter.call(process);

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-process-prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const EventEmitter = require('events');

const proto = Object.getPrototypeOf(process);

assert(process instanceof process.constructor);
assert(proto instanceof EventEmitter);

const desc = Object.getOwnPropertyDescriptor(proto, 'constructor');
Expand Down