File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -65,13 +65,22 @@ class IterableWeakMap {
65
65
return true ;
66
66
}
67
67
68
- * [ SymbolIterator ] ( ) {
69
- for ( const ref of this . #refSet) {
70
- const key = ref . deref ( ) ;
71
- if ( ! key ) continue ;
68
+ [ SymbolIterator ] ( ) {
69
+ const iterator = this . #refSet[ SymbolIterator ] ( ) ;
70
+
71
+ const next = ( ) => {
72
+ const result = iterator . next ( ) ;
73
+ if ( result . done ) return result ;
74
+ const key = result . value . deref ( ) ;
75
+ if ( key == null ) return next ( ) ;
72
76
const { value } = this . #weakMap. get ( key ) ;
73
- yield value ;
74
- }
77
+ return { done : false , value } ;
78
+ } ;
79
+
80
+ return {
81
+ [ SymbolIterator ] ( ) { return this ; } ,
82
+ next,
83
+ } ;
75
84
}
76
85
}
77
86
Original file line number Diff line number Diff line change 1
1
// Flags: --expose-gc --expose-internals
2
2
'use strict' ;
3
3
4
- require ( '../common' ) ;
4
+ const common = require ( '../common' ) ;
5
5
const { deepStrictEqual, strictEqual } = require ( 'assert' ) ;
6
6
const { IterableWeakMap } = require ( 'internal/util/iterable_weak_map' ) ;
7
7
8
+ // Ensures iterating over the map does not rely on methods which can be
9
+ // mutated by users.
10
+ Reflect . getPrototypeOf ( function * ( ) { } ) . prototype . next = common . mustNotCall ( ) ;
11
+ Reflect . getPrototypeOf ( new Set ( ) [ Symbol . iterator ] ( ) ) . next =
12
+ common . mustNotCall ( ) ;
13
+
8
14
// It drops entry if a reference is no longer held.
9
15
{
10
16
const wm = new IterableWeakMap ( ) ;
You can’t perform that action at this time.
0 commit comments