diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-14 23:46:50 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-17 19:41:12 +0300 |
commit | 7f0c515fed92ffd5fdfb003f99f808968101d7da (patch) | |
tree | 39f12b55abcc19b5675a8ae2716522252242454c /lib/internal/worker | |
parent | 3fbf55a87c5c74fef93b16721834f9e270796cef (diff) |
worker: do not add removed methods to MessagePort
Do not put the `.stop()` and `.drain()` methods on the
`MessagePort` prototype if we are going to remove them
later on anyway.
PR-URL: https://github.com/nodejs/node/pull/26109
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/internal/worker')
-rw-r--r-- | lib/internal/worker/io.js | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index a72868916ca..e88991aaaba 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -6,7 +6,9 @@ const { } = internalBinding('symbols'); const { MessagePort, - MessageChannel + MessageChannel, + drainMessagePort, + stopMessagePort } = internalBinding('messaging'); const { threadId } = internalBinding('worker'); @@ -33,13 +35,6 @@ const messageTypes = { LOAD_SCRIPT: 'loadScript' }; -// Original drain from C++ -const originalDrain = MessagePort.prototype.drain; - -function drainMessagePort(port) { - return originalDrain.call(port); -} - // We have to mess with the MessagePort prototype a bit, so that a) we can make // it inherit from EventEmitter, even though it is a C++ class, and b) we do // not provide methods that are not present in the Browser and not documented @@ -51,9 +46,8 @@ const MessagePortPrototype = Object.create( // Set up the new inheritance chain. Object.setPrototypeOf(MessagePort, EventEmitter); Object.setPrototypeOf(MessagePort.prototype, EventEmitter.prototype); -// Finally, purge methods we don't want to be public. -delete MessagePort.prototype.stop; -delete MessagePort.prototype.drain; +// Copy methods that are inherited from HandleWrap, because +// changing the prototype of MessagePort.prototype implicitly removed them. MessagePort.prototype.ref = MessagePortPrototype.ref; MessagePort.prototype.unref = MessagePortPrototype.unref; @@ -84,7 +78,7 @@ Object.defineProperty(MessagePort.prototype, 'onmessage', { MessagePortPrototype.start.call(this); } else { this.unref(); - MessagePortPrototype.stop.call(this); + stopMessagePort(this); } } }); @@ -152,7 +146,7 @@ function setupPortReferencing(port, eventEmitter, eventName) { }); eventEmitter.on('removeListener', (name) => { if (name === eventName && eventEmitter.listenerCount(eventName) === 0) { - MessagePortPrototype.stop.call(port); + stopMessagePort(port); port.unref(); } }); |