File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Flags: --expose-internals
2+ // Verifies that ModuleWrap instances created by import() are garbage-
3+ // collectible after clearCache with caches: 'all'. This is the strongest
4+ // guarantee that clearing works end-to-end: V8 itself can reclaim the
5+ // underlying module.
6+ 'use strict' ;
7+
8+ const common = require ( '../common' ) ;
9+
10+ const { pathToFileURL } = require ( 'node:url' ) ;
11+ const { clearCache } = require ( 'node:module' ) ;
12+ const { internalBinding } = require ( 'internal/test/binding' ) ;
13+ const { ModuleWrap } = internalBinding ( 'module_wrap' ) ;
14+ const { checkIfCollectableByCounting } = require ( '../common/gc' ) ;
15+
16+ const fixtureURL = new URL (
17+ '../fixtures/module-cache/esm-counter.mjs' ,
18+ pathToFileURL ( __filename ) ,
19+ ) ;
20+ const parentURL = pathToFileURL ( __filename ) . href ;
21+
22+ const outer = 8 ;
23+ const inner = 4 ;
24+
25+ const runIteration = common . mustCallAtLeast ( async ( i ) => {
26+ for ( let j = 0 ; j < inner ; j ++ ) {
27+ const url = `${ fixtureURL . href } ?hmr=${ i } -${ j } ` ;
28+ await import ( url ) ;
29+ clearCache ( url , {
30+ parentURL,
31+ resolver : 'import' ,
32+ caches : 'all' ,
33+ } ) ;
34+ }
35+ return inner ;
36+ } ) ;
37+
38+ checkIfCollectableByCounting ( runIteration , ModuleWrap , outer )
39+ . then ( common . mustCall ( ( ) => {
40+ delete globalThis . __module_cache_esm_counter ;
41+ } ) ) ;
You can’t perform that action at this time.
0 commit comments