From 9230f22029f1c3fed9b91ebcf5b114d33b915a32 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 12 Jan 2025 16:05:44 +0100 Subject: [PATCH] process: remove support for undocumented symbol PR-URL: https://github.com/nodejs/node/pull/56552 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli --- lib/internal/process/per_thread.js | 10 ++++++---- test/parallel/test-process-ref-unref.js | 17 ----------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 134e99e2374722..7d591cd6517e66 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -420,15 +420,17 @@ function toggleTraceCategoryState(asyncHooksEnabled) { const { arch, platform, version } = process; +let refSymbol; function ref(maybeRefable) { - const fn = maybeRefable?.[SymbolFor('nodejs.ref')] || maybeRefable?.[SymbolFor('node:ref')] || maybeRefable?.ref; + if (maybeRefable == null) return; + const fn = maybeRefable[refSymbol ??= SymbolFor('nodejs.ref')] || maybeRefable.ref; if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable); } +let unrefSymbol; function unref(maybeRefable) { - const fn = maybeRefable?.[SymbolFor('nodejs.unref')] || - maybeRefable?.[SymbolFor('node:unref')] || - maybeRefable?.unref; + if (maybeRefable == null) return; + const fn = maybeRefable[unrefSymbol ??= SymbolFor('nodejs.unref')] || maybeRefable.unref; if (typeof fn === 'function') FunctionPrototypeCall(fn, maybeRefable); } diff --git a/test/parallel/test-process-ref-unref.js b/test/parallel/test-process-ref-unref.js index 6bd508c1dbb9cb..19665703cfe341 100644 --- a/test/parallel/test-process-ref-unref.js +++ b/test/parallel/test-process-ref-unref.js @@ -33,37 +33,20 @@ class Foo2 { } } -// TODO(aduh95): remove support for undocumented symbol -class Foo3 { - refCalled = 0; - unrefCalled = 0; - [Symbol.for('node:ref')]() { - this.refCalled++; - } - [Symbol.for('node:unref')]() { - this.unrefCalled++; - } -} - describe('process.ref/unref work as expected', () => { it('refs...', () => { // Objects that implement the new Symbol-based API // just work. const foo1 = new Foo(); const foo2 = new Foo2(); - const foo3 = new Foo3(); process.ref(foo1); process.unref(foo1); process.ref(foo2); process.unref(foo2); - process.ref(foo3); - process.unref(foo3); strictEqual(foo1.refCalled, 1); strictEqual(foo1.unrefCalled, 1); strictEqual(foo2.refCalled, 1); strictEqual(foo2.unrefCalled, 1); - strictEqual(foo3.refCalled, 1); - strictEqual(foo3.unrefCalled, 1); // Objects that implement the legacy API also just work. const i = setInterval(() => {}, 1000);