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:
parent
062beb08df
commit
cde272a066
4
lib/internal/bootstrap_node.js
vendored
4
lib/internal/bootstrap_node.js
vendored
@ -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);
|
||||||
|
|
||||||
|
@ -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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user