Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDarshan Sen <raisinten@gmail.com>2022-05-02 07:39:39 +0300
committerGitHub <noreply@github.com>2022-05-02 07:39:39 +0300
commit1d8a320a04d75b2143be0bc97b10dfcd9e64defa (patch)
treeacdd41199780556110b9d1a6591ec60754193cc3 /lib
parent7a53696c8aec068d89ad2cf017c74683b79525a0 (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.js5
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))