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+ 'use strict' ;
2+
3+ const common = require ( '../common.js' ) ;
4+
5+ const bench = common . createBenchmark ( main , {
6+ urls : [ 1 , 100 ] ,
7+ n : [ 1e7 ] ,
8+ } , {
9+ flags : [ '--expose-internals' ] ,
10+ } ) ;
11+
12+ function main ( { urls, n } ) {
13+ const { LoadCache } = require ( 'internal/modules/esm/module_map' ) ;
14+ const cache = new LoadCache ( ) ;
15+ const job = ( ) => { } ;
16+ const keys = Array . from ( { length : urls } , ( _ , i ) => `file:///module-${ i } .mjs` ) ;
17+ for ( let i = 0 ; i < keys . length ; i ++ ) cache . set ( keys [ i ] , undefined , job ) ;
18+
19+ bench . start ( ) ;
20+ for ( let i = 0 ; i < n ; i ++ ) {
21+ if ( cache . get ( keys [ i % keys . length ] ) !== job ) {
22+ throw new Error ( 'Load cache miss' ) ;
23+ }
24+ }
25+ bench . end ( n ) ;
26+ }
Original file line number Diff line number Diff line change 66 ArrayPrototypeSort,
77 JSONStringify,
88 ObjectKeys,
9+ ObjectSetPrototypeOf,
910 SafeMap,
1011} = primordials ;
1112const { kImplicitTypeAttribute } = require ( 'internal/modules/esm/assert' ) ;
@@ -108,7 +109,7 @@ class LoadCache extends SafeMap {
108109 debug ( `Storing ${ url } (${
109110 type === kImplicitTypeAttribute ? 'implicit type' : type
110111 } ) in ModuleLoadMap`) ;
111- const cachedJobsForUrl = super . get ( url ) ?? { __proto__ : null } ;
112+ const cachedJobsForUrl = super . get ( url ) ?? ObjectSetPrototypeOf ( { } , null ) ;
112113 cachedJobsForUrl [ type ] = job ;
113114 return super . set ( url , cachedJobsForUrl ) ;
114115 }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ // Flags: --expose-internals
3+
4+ require ( '../common' ) ;
5+
6+ const assert = require ( 'assert' ) ;
7+ const { LoadCache } = require ( 'internal/modules/esm/module_map' ) ;
8+
9+ const cache = new LoadCache ( ) ;
10+ const url = 'file:///module.mjs' ;
11+ const job = ( ) => { } ;
12+
13+ assert . strictEqual ( cache . get ( url , '__proto__' ) , undefined ) ;
14+ assert . strictEqual ( cache . has ( url , 'constructor' ) , false ) ;
15+ cache . set ( url , '__proto__' , job ) ;
16+ assert . strictEqual ( cache . get ( url , '__proto__' ) , job ) ;
17+ assert . strictEqual ( cache . has ( url , '__proto__' ) , true ) ;
18+ assert . strictEqual ( cache . has ( url , 'constructor' ) , false ) ;
19+ cache . set ( url , 'constructor' , job ) ;
20+ assert . strictEqual ( cache . get ( url , 'constructor' ) , job ) ;
21+ cache . delete ( url , '__proto__' ) ;
22+ assert . strictEqual ( cache . get ( url , '__proto__' ) , undefined ) ;
You can’t perform that action at this time.
0 commit comments