Commit 9230f22 1 parent c61504b commit 9230f22 Copy full SHA for 9230f22
File tree 2 files changed +6
-21
lines changed
2 files changed +6
-21
lines changed Original file line number Diff line number Diff line change @@ -420,15 +420,17 @@ function toggleTraceCategoryState(asyncHooksEnabled) {
420
420
421
421
const { arch, platform, version } = process ;
422
422
423
+ let refSymbol ;
423
424
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 ;
425
427
if ( typeof fn === 'function' ) FunctionPrototypeCall ( fn , maybeRefable ) ;
426
428
}
427
429
430
+ let unrefSymbol ;
428
431
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 ;
432
434
if ( typeof fn === 'function' ) FunctionPrototypeCall ( fn , maybeRefable ) ;
433
435
}
434
436
Original file line number Diff line number Diff line change @@ -33,37 +33,20 @@ class Foo2 {
33
33
}
34
34
}
35
35
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
-
48
36
describe ( 'process.ref/unref work as expected' , ( ) => {
49
37
it ( 'refs...' , ( ) => {
50
38
// Objects that implement the new Symbol-based API
51
39
// just work.
52
40
const foo1 = new Foo ( ) ;
53
41
const foo2 = new Foo2 ( ) ;
54
- const foo3 = new Foo3 ( ) ;
55
42
process . ref ( foo1 ) ;
56
43
process . unref ( foo1 ) ;
57
44
process . ref ( foo2 ) ;
58
45
process . unref ( foo2 ) ;
59
- process . ref ( foo3 ) ;
60
- process . unref ( foo3 ) ;
61
46
strictEqual ( foo1 . refCalled , 1 ) ;
62
47
strictEqual ( foo1 . unrefCalled , 1 ) ;
63
48
strictEqual ( foo2 . refCalled , 1 ) ;
64
49
strictEqual ( foo2 . unrefCalled , 1 ) ;
65
- strictEqual ( foo3 . refCalled , 1 ) ;
66
- strictEqual ( foo3 . unrefCalled , 1 ) ;
67
50
68
51
// Objects that implement the legacy API also just work.
69
52
const i = setInterval ( ( ) => { } , 1000 ) ;
You can’t perform that action at this time.
0 commit comments