process: maintain constructor descriptor

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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
Bryan English 2016-10-26 15:21:36 -07:00 committed by Anna Henningsen
parent 2141d37452
commit e0bc5a7361
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
2 changed files with 17 additions and 3 deletions

View File

@ -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);

View File

@ -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);