diff options
author | Darshan Sen <raisinten@gmail.com> | 2022-05-02 07:39:39 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2022-05-02 15:39:33 +0300 |
commit | bf9240ae8c82f2b275109528eff4ffa43207fde1 (patch) | |
tree | bf8ea70f6457e5d5cc2f94f8901bc9a9337088cb /lib | |
parent | 1e7479d34c678e3f169f4a95f337d6cc9e4d346b (diff) |
worker: add hasRef() to MessagePort
Since we were removing the hasRef() method before exposing the
MessagePort object, the only way of knowing if the handle was keeping
the event loop active was to parse the string returned by
util.inspect(port), which is inconvenient and inconsistent with most of
the other async resources. So this change stops removing hasRef() from
the MessagePort prototype. The reason why this is also being documented
is that while reporting active resources, async_hooks returns the same
MessagePort object as the one that is accessible by users.
Refs: https://github.com/nodejs/node/issues/42091#issuecomment-1104793189
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/42849
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/worker/io.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 822b8672525..996d9899510 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -91,7 +91,7 @@ const messageTypes = { // We have to mess with the MessagePort prototype a bit, so that a) we can make // it inherit from NodeEventTarget, even though it is a C++ class, and b) we do // not provide methods that are not present in the Browser and not documented -// on our side (e.g. hasRef). +// on our side (e.g. stopMessagePort). // Save a copy of the original set of methods as a shallow clone. const MessagePortPrototype = ObjectCreate( ObjectGetPrototypeOf(MessagePort.prototype), @@ -103,6 +103,9 @@ ObjectSetPrototypeOf(MessagePort.prototype, NodeEventTarget.prototype); // changing the prototype of MessagePort.prototype implicitly removed them. MessagePort.prototype.ref = MessagePortPrototype.ref; MessagePort.prototype.unref = MessagePortPrototype.unref; +MessagePort.prototype.hasRef = function() { + return !!FunctionPrototypeCall(MessagePortPrototype.hasRef, this); +}; function validateMessagePort(port, name) { if (!checkMessagePort(port)) |