@@ -5,18 +5,22 @@ const {
5
5
ObjectFreeze,
6
6
SafeFinalizationRegistry,
7
7
SafeMap,
8
- SafeWeakMap,
9
8
SafeWeakRef,
10
9
SymbolIterator,
11
10
} = primordials ;
11
+ const {
12
+ privateSymbols : {
13
+ source_map_data_private_symbol,
14
+ } ,
15
+ } = internalBinding ( 'util' ) ;
12
16
13
17
/**
14
18
* Specialized WeakMap that caches source map entries by `filename` and `sourceURL`.
15
19
* Cached entries can be iterated with `for..of`.
16
20
*
17
21
* The cache map maintains the cache entries by:
18
22
* - `weakTargetMap`(Map): a strong sourceURL -> WeakRef(Module),
19
- * - `weakMap`(WeakMap): a Module instance object -> source map data.
23
+ * - WeakRef(Module[source_map_data_private_symbol]): source map data.
20
24
*
21
25
* Obsolete `weakTargetMap` entries are removed by the `finalizationRegistry` callback.
22
26
* This pattern decouples the strong url reference to the source map data and allow the
@@ -33,7 +37,6 @@ class SourceMapCacheMap {
33
37
* the cache by the `finalizationRegistry`.
34
38
*/
35
39
#weakTargetMap = new SafeMap ( ) ;
36
- #weakMap = new SafeWeakMap ( ) ;
37
40
38
41
#cleanup = ( { keys } ) => {
39
42
// Delete the entry if the weak target has been reclaimed.
@@ -58,7 +61,7 @@ class SourceMapCacheMap {
58
61
set ( keys , value , weakTarget ) {
59
62
const weakRef = new SafeWeakRef ( weakTarget ) ;
60
63
ArrayPrototypeForEach ( keys , ( key ) => this . #weakTargetMap. set ( key , weakRef ) ) ;
61
- this . #weakMap . set ( weakTarget , value ) ;
64
+ weakTarget [ source_map_data_private_symbol ] = value ;
62
65
this . #finalizationRegistry. register ( weakTarget , { keys } ) ;
63
66
}
64
67
@@ -72,7 +75,7 @@ class SourceMapCacheMap {
72
75
if ( target === undefined ) {
73
76
return ;
74
77
}
75
- return this . #weakMap . get ( target ) ;
78
+ return target [ source_map_data_private_symbol ] ;
76
79
}
77
80
78
81
/**
@@ -92,7 +95,7 @@ class SourceMapCacheMap {
92
95
const { 0 : key , 1 : weakRef } = result . value ;
93
96
const target = weakRef . deref ( ) ;
94
97
if ( target == null ) return next ( ) ;
95
- const value = this . #weakMap . get ( target ) ;
98
+ const value = target [ source_map_data_private_symbol ] ;
96
99
return { done : false , value : [ key , value ] } ;
97
100
} ;
98
101
0 commit comments