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 <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
ZiJian Liu authored and Danielle Adams committed 2021-01-12 07:07:54 -05:00
1 parent 93237c5999
commit d20235b6cb
2 files changed
+11 -2

No files matched your search

+1 -2
View File
@@ -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;
}
@@ -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'));