Skip to content

Commit

Permalink
process: remove support for undocumented symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jan 10, 2025
1 parent 3946f16 commit 58cb88e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
10 changes: 6 additions & 4 deletions lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 0 additions & 17 deletions test/parallel/test-process-ref-unref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 58cb88e

Please sign in to comment.