tc39 / proposal-set-methods

Proposal for new Set methods in JS
https://tc39.github.io/proposal-set-methods/
Other
655 stars 15 forks source link

Define for-each iteration when the underlying list is modified? #82

Closed anba closed 1 year ago

anba commented 1 year ago

The main spec never uses for each element iteration when the iterated-over list can be modified. Therefore it's not quite clear what the intended semantics should be, i.e. are newly added elements visible or not? Maybe it's necessary to rewrite this to an index-based loop.

The modification can happen either through user-code, e.g. in Set.prototype.intersection when calling otherRec.[[Has]]. Or it can happen through direct modification, e.g. in Set.prototype.difference when an element is removed from resultSetData during iteration over resultSetData.

bakkot commented 1 year ago

Good catch. The main spec actually did do this until recently, but I changed it to be index-based for just this reason. I'll change it here as well.

zloirock commented 1 year ago

It seems here should be used an approach similar to Set.prototype.forEach for avoiding cases like #83.