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 Michaël Zasso committed 2021-05-01 09:44:47 +02:00
1 parent 317a1d7a0d
commit 08b69fb1e8
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'));