File tree Expand file tree Collapse file tree 2 files changed +6
-21
lines changed Expand file tree Collapse file tree 2 files changed +6
-21
lines changed Original file line number Diff line number Diff line change @@ -424,15 +424,17 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
424424
425425const { arch, platform, version } = process ;
426426
427+ let refSymbol ;
427428function ref ( maybeRefable ) {
428- const fn = maybeRefable ?. [ SymbolFor ( 'nodejs.ref' ) ] || maybeRefable ?. [ SymbolFor ( 'node:ref' ) ] || maybeRefable ?. ref ;
429+ if ( maybeRefable == null ) return ;
430+ const fn = maybeRefable [ refSymbol ??= SymbolFor ( 'nodejs.ref' ) ] || maybeRefable . ref ;
429431 if ( typeof fn === 'function' ) FunctionPrototypeCall ( fn , maybeRefable ) ;
430432}
431433
434+ let unrefSymbol ;
432435function unref ( maybeRefable ) {
433- const fn = maybeRefable ?. [ SymbolFor ( 'nodejs.unref' ) ] ||
434- maybeRefable ?. [ SymbolFor ( 'node:unref' ) ] ||
435- maybeRefable ?. unref ;
436+ if ( maybeRefable == null ) return ;
437+ const fn = maybeRefable [ unrefSymbol ??= SymbolFor ( 'nodejs.unref' ) ] || maybeRefable . unref ;
436438 if ( typeof fn === 'function' ) FunctionPrototypeCall ( fn , maybeRefable ) ;
437439}
438440
Original file line number Diff line number Diff 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-
4836describe ( '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 ) ;
You can’t perform that action at this time.
0 commit comments