Skip to content

Commit 9230f22

Browse files
authored
process: remove support for undocumented symbol
PR-URL: nodejs#56552 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent c61504b commit 9230f22

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

lib/internal/process/per_thread.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,17 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
420420

421421
const { arch, platform, version } = process;
422422

423+
let refSymbol;
423424
function ref(maybeRefable) {
424-
const fn = maybeRefable?.[SymbolFor('nodejs.ref')] || maybeRefable?.[SymbolFor('node:ref')] || maybeRefable?.ref;
425+
if (maybeRefable == null) return;
426+
const fn = maybeRefable[refSymbol ??= SymbolFor('nodejs.ref')] || maybeRefable.ref;
425427
if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable);
426428
}
427429

430+
let unrefSymbol;
428431
function unref(maybeRefable) {
429-
const fn = maybeRefable?.[SymbolFor('nodejs.unref')] ||
430-
maybeRefable?.[SymbolFor('node:unref')] ||
431-
maybeRefable?.unref;
432+
if (maybeRefable == null) return;
433+
const fn = maybeRefable[unrefSymbol ??= SymbolFor('nodejs.unref')] || maybeRefable.unref;
432434
if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable);
433435
}
434436

test/parallel/test-process-ref-unref.js

-17
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,20 @@ class Foo2 {
3333
}
3434
}
3535

36-
// TODO(aduh95): remove support for undocumented symbol
37-
class Foo3 {
38-
refCalled = 0;
39-
unrefCalled = 0;
40-
[Symbol.for('node:ref')]() {
41-
this.refCalled++;
42-
}
43-
[Symbol.for('node:unref')]() {
44-
this.unrefCalled++;
45-
}
46-
}
47-
4836
describe('process.ref/unref work as expected', () => {
4937
it('refs...', () => {
5038
// Objects that implement the new Symbol-based API
5139
// just work.
5240
const foo1 = new Foo();
5341
const foo2 = new Foo2();
54-
const foo3 = new Foo3();
5542
process.ref(foo1);
5643
process.unref(foo1);
5744
process.ref(foo2);
5845
process.unref(foo2);
59-
process.ref(foo3);
60-
process.unref(foo3);
6146
strictEqual(foo1.refCalled, 1);
6247
strictEqual(foo1.unrefCalled, 1);
6348
strictEqual(foo2.refCalled, 1);
6449
strictEqual(foo2.unrefCalled, 1);
65-
strictEqual(foo3.refCalled, 1);
66-
strictEqual(foo3.unrefCalled, 1);
6750

6851
// Objects that implement the legacy API also just work.
6952
const i = setInterval(() => {}, 1000);

0 commit comments

Comments
 (0)