File tree Expand file tree Collapse file tree 5 files changed +25
-6
lines changed
js-native-api/test_reference Expand file tree Collapse file tree 5 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export default defineConfig([
1515 loadAddon : "readonly" ,
1616 mustCall : "readonly" ,
1717 mustNotCall : "readonly" ,
18+ gc : "readonly" ,
1819 gcUntil : "readonly" ,
1920 experimentalFeatures : "readonly" ,
2021 onUncaughtException : "readonly" ,
Original file line number Diff line number Diff line change 1+ // Capture the engine-provided gc (Node exposes it under --expose-gc) before
2+ // we overwrite globalThis.gc with the harness wrapper below.
3+ const engineGc = globalThis . gc ;
4+ if ( typeof engineGc !== "function" ) {
5+ throw new Error (
6+ "Node harness expects globalThis.gc to be available (run with --expose-gc)" ,
7+ ) ;
8+ }
9+
10+ const gc = ( ) => {
11+ engineGc ( ) ;
12+ } ;
13+
114const gcUntil = async ( name , condition ) => {
215 let count = 0 ;
316 while ( ! condition ( ) ) {
417 await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
518 if ( ++ count < 10 ) {
6- globalThis . gc ( ) ;
19+ engineGc ( ) ;
720 } else {
821 throw new Error ( `GC test "${ name } " failed after ${ count } attempts` ) ;
922 }
1023 }
1124} ;
1225
13- Object . assign ( globalThis , { gcUntil } ) ;
26+ Object . assign ( globalThis , { gc , gcUntil } ) ;
Original file line number Diff line number Diff line change 1+ if ( typeof gc !== 'function' ) {
2+ throw new Error ( 'Expected a global gc function' ) ;
3+ }
4+
15if ( typeof gcUntil !== 'function' ) {
26 throw new Error ( 'Expected a global gcUntil function' ) ;
37}
48
9+ // gc should run synchronously without throwing
10+ gc ( ) ;
11+
512// gcUntil should resolve once the condition becomes true
613let count = 0 ;
714await gcUntil ( 'test-passes' , ( ) => {
Original file line number Diff line number Diff line change @@ -164,6 +164,5 @@ runTests();
164164for ( let i = 0 ; i < 1000 ; i ++ ) {
165165 const wrapObject = new Object ( ) ;
166166 test_reference . validateDeleteBeforeFinalize ( wrapObject ) ;
167- let gcCount = 1 ;
168- gcUntil ( "test" , ( ) => gcCount -- <= 0 ) ;
167+ gc ( ) ;
169168}
Original file line number Diff line number Diff line change @@ -19,6 +19,5 @@ onUncaughtException(
1919 } ) ,
2020 ) ;
2121 }
22- let gcCount = 1 ;
23- await gcUntil ( "test" , ( ) => gcCount -- > 0 ) ;
22+ gc ( ) ;
2423} ) ( ) . then ( mustCall ( ) ) ;
You can’t perform that action at this time.
0 commit comments