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: https://github.com/nodejs/node/issues/14699
PR-URL: https://github.com/nodejs/node/pull/14715
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Jimmy Thomson 2017-08-09 08:58:10 -07:00 committed by Anna Henningsen
parent 062beb08df
commit cde272a066
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
2 changed files with 2 additions and 3 deletions

View File

@ -14,9 +14,7 @@
process._eventsCount = 0; process._eventsCount = 0;
const origProcProto = Object.getPrototypeOf(process); const origProcProto = Object.getPrototypeOf(process);
Object.setPrototypeOf(process, Object.create(EventEmitter.prototype, { Object.setPrototypeOf(origProcProto, EventEmitter.prototype);
constructor: Object.getOwnPropertyDescriptor(origProcProto, 'constructor')
}));
EventEmitter.call(process); EventEmitter.call(process);

View File

@ -5,6 +5,7 @@ const EventEmitter = require('events');
const proto = Object.getPrototypeOf(process); const proto = Object.getPrototypeOf(process);
assert(process instanceof process.constructor);
assert(proto instanceof EventEmitter); assert(proto instanceof EventEmitter);
const desc = Object.getOwnPropertyDescriptor(proto, 'constructor'); const desc = Object.getOwnPropertyDescriptor(proto, 'constructor');