From 471a85d737ec6e3bca19f7f918b7231ea5ed83bb Mon Sep 17 00:00:00 2001 From: Bryan English Date: Wed, 26 Oct 2016 15:21:36 -0700 Subject: [PATCH] process: maintain constructor descriptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the original property descriptor instead of just taking the value, which would, by default, be non-writable and non-configurable. PR-URL: https://github.com/nodejs/node/pull/9306 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Michaƫl Zasso --- lib/internal/bootstrap_node.js | 5 ++--- test/parallel/test-process-prototype.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-process-prototype.js diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 18a3afc4df5..ac6c71dd56b 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -13,10 +13,9 @@ const EventEmitter = NativeModule.require('events'); process._eventsCount = 0; + const origProcProto = Object.getPrototypeOf(process); Object.setPrototypeOf(process, Object.create(EventEmitter.prototype, { - constructor: { - value: process.constructor - } + constructor: Object.getOwnPropertyDescriptor(origProcProto, 'constructor') })); EventEmitter.call(process); diff --git a/test/parallel/test-process-prototype.js b/test/parallel/test-process-prototype.js new file mode 100644 index 00000000000..0a0de8123d1 --- /dev/null +++ b/test/parallel/test-process-prototype.js @@ -0,0 +1,15 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const EventEmitter = require('events'); + +const proto = Object.getPrototypeOf(process); + +assert(proto instanceof EventEmitter); + +const desc = Object.getOwnPropertyDescriptor(proto, 'constructor'); + +assert.strictEqual(desc.value, process.constructor); +assert.strictEqual(desc.writable, true); +assert.strictEqual(desc.enumerable, false); +assert.strictEqual(desc.configurable, true);