Skip to content

Commit

Permalink
process: keep process prototype in inheritance chain
Browse files Browse the repository at this point in the history
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
PR-URL: #14715
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
MSLaguana authored and addaleax committed Aug 14, 2017
1 parent 062beb0 commit cde272a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
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

0 comments on commit cde272a

Please sign in to comment.