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 @@ -54,13 +54,22 @@ class IterableWeakMap {
54
54
return true ;
55
55
}
56
56
57
- * [ SymbolIterator ] ( ) {
58
- for ( const ref of this . #refSet) {
59
- const key = ref . deref ( ) ;
60
- if ( ! key ) continue ;
57
+ [ SymbolIterator ] ( ) {
58
+ const iterator = this . #refSet[ SymbolIterator ] ( ) ;
59
+
60
+ const next = ( ) => {
61
+ const result = iterator . next ( ) ;
62
+ if ( result . done ) return result ;
63
+ const key = result . value . deref ( ) ;
64
+ if ( key == null ) return next ( ) ;
61
65
const { value } = this . #weakMap. get ( key ) ;
62
- yield value ;
63
- }
66
+ return { done : false , value } ;
67
+ } ;
68
+
69
+ return {
70
+ [ SymbolIterator ] ( ) { return this ; } ,
71
+ next,
72
+ } ;
64
73
}
65
74
}
66
75
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