Skip to content

Commit

Permalink
lib: fix diagnostics_channel hasSubscribers error
Browse files Browse the repository at this point in the history
Fixes: #36598

PR-URL: #36599
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
Lxxyx authored and danielleadams committed Jan 12, 2021
1 parent 93237c5 commit d20235b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/diagnostics_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const {
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
SymbolHasInstance,
WeakRefPrototypeGet
} = primordials;

const {
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-diagnostics-channel-has-subscribers.js
Original file line number Diff line number Diff line change
@@ -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'));

0 comments on commit d20235b

Please sign in to comment.