From cde272a066923a1b93a10a8121b0ce572308d13c Mon Sep 17 00:00:00 2001 From: Jimmy Thomson Date: Wed, 9 Aug 2017 08:58:10 -0700 Subject: [PATCH] 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 --- lib/internal/bootstrap_node.js | 4 +--- test/parallel/test-process-prototype.js | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index cf517cdcf2b5ef..a576eeb5e579f6 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -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); diff --git a/test/parallel/test-process-prototype.js b/test/parallel/test-process-prototype.js index 0a0de8123d127d..6eb442fd96e4d6 100644 --- a/test/parallel/test-process-prototype.js +++ b/test/parallel/test-process-prototype.js @@ -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');