diff options
Diffstat (limited to 'lib/internal/worker/io.js')
-rw-r--r-- | lib/internal/worker/io.js | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index ba2150e530..a672dac94c 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -1,6 +1,13 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectAssign, + ObjectCreate, + ObjectDefineProperty, + ObjectGetOwnPropertyDescriptors, + ObjectGetPrototypeOf, + ObjectSetPrototypeOf, +} = primordials; const { handle_onclose: handleOnCloseSymbol, @@ -48,12 +55,12 @@ const messageTypes = { // not provide methods that are not present in the Browser and not documented // on our side (e.g. hasRef). // Save a copy of the original set of methods as a shallow clone. -const MessagePortPrototype = Object.create( - Object.getPrototypeOf(MessagePort.prototype), - Object.getOwnPropertyDescriptors(MessagePort.prototype)); +const MessagePortPrototype = ObjectCreate( + ObjectGetPrototypeOf(MessagePort.prototype), + ObjectGetOwnPropertyDescriptors(MessagePort.prototype)); // Set up the new inheritance chain. -Object.setPrototypeOf(MessagePort, EventEmitter); -Object.setPrototypeOf(MessagePort.prototype, EventEmitter.prototype); +ObjectSetPrototypeOf(MessagePort, EventEmitter); +ObjectSetPrototypeOf(MessagePort.prototype, EventEmitter.prototype); // Copy methods that are inherited from HandleWrap, because // changing the prototype of MessagePort.prototype implicitly removed them. MessagePort.prototype.ref = MessagePortPrototype.ref; @@ -73,7 +80,7 @@ MessagePort.prototype[kOnMessageListener] = function onmessage(event) { // This is for compatibility with the Web's MessagePort API. It makes sense to // provide it as an `EventEmitter` in Node.js, but if somebody overrides // `onmessage`, we'll switch over to the Web API model. -Object.defineProperty(MessagePort.prototype, 'onmessage', { +ObjectDefineProperty(MessagePort.prototype, 'onmessage', { enumerable: true, configurable: true, get() { @@ -96,7 +103,7 @@ function oninit() { setupPortReferencing(this, this, 'message'); } -Object.defineProperty(MessagePort.prototype, onInitSymbol, { +ObjectDefineProperty(MessagePort.prototype, onInitSymbol, { enumerable: true, writable: false, value: oninit @@ -107,7 +114,7 @@ function onclose() { this.emit('close'); } -Object.defineProperty(MessagePort.prototype, handleOnCloseSymbol, { +ObjectDefineProperty(MessagePort.prototype, handleOnCloseSymbol, { enumerable: false, writable: false, value: onclose @@ -119,7 +126,7 @@ MessagePort.prototype.close = function(cb) { MessagePortPrototype.close.call(this); }; -Object.defineProperty(MessagePort.prototype, inspect.custom, { +ObjectDefineProperty(MessagePort.prototype, inspect.custom, { enumerable: false, writable: false, value: function inspect() { // eslint-disable-line func-name-matching @@ -129,14 +136,14 @@ Object.defineProperty(MessagePort.prototype, inspect.custom, { // e.g. when accessing the prototype directly. ref = MessagePortPrototype.hasRef.call(this); } catch { return this; } - return Object.assign(Object.create(MessagePort.prototype), - ref === undefined ? { - active: false, - } : { - active: true, - refed: ref - }, - this); + return ObjectAssign(ObjectCreate(MessagePort.prototype), + ref === undefined ? { + active: false, + } : { + active: true, + refed: ref + }, + this); } }); |