From d20235b6cb5d12fe2a039bb352624cbe26cb7dfa Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Tue, 22 Dec 2020 20:43:32 +0800 Subject: [PATCH] lib: fix diagnostics_channel hasSubscribers error Fixes: https://github.com/nodejs/node/issues/36598 PR-URL: https://github.com/nodejs/node/pull/36599 Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- lib/diagnostics_channel.js | 3 +-- .../test-diagnostics-channel-has-subscribers.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-diagnostics-channel-has-subscribers.js diff --git a/lib/diagnostics_channel.js b/lib/diagnostics_channel.js index 0a3552dc975040..c29c9ff0052405 100644 --- a/lib/diagnostics_channel.js +++ b/lib/diagnostics_channel.js @@ -8,7 +8,6 @@ const { ObjectGetPrototypeOf, ObjectSetPrototypeOf, SymbolHasInstance, - WeakRefPrototypeGet } = primordials; const { @@ -107,7 +106,7 @@ function channel(name) { function hasSubscribers(name) { let channel; const ref = channels[name]; - if (ref) channel = WeakRefPrototypeGet(ref); + if (ref) channel = ref.get(); if (!channel) { return false; } diff --git a/test/parallel/test-diagnostics-channel-has-subscribers.js b/test/parallel/test-diagnostics-channel-has-subscribers.js new file mode 100644 index 00000000000000..de37267555089e --- /dev/null +++ b/test/parallel/test-diagnostics-channel-has-subscribers.js @@ -0,0 +1,10 @@ +'use strict'; +require('../common'); +const assert = require('assert'); +const { channel, hasSubscribers } = require('diagnostics_channel'); + +const dc = channel('test'); +assert.ok(!hasSubscribers('test')); + +dc.subscribe(() => {}); +assert.ok(hasSubscribers('test'));