Editorial: Unify 'replace' step into single format#3767
Editorial: Unify 'replace' step into single format#3767jungwngkim wants to merge 1 commit intotc39:mainfrom
Conversation
| 1. For each element _e_ of _S_.[[SetData]], do | ||
| 1. Replace the element of _S_.[[SetData]] whose value is _e_ with an element whose value is ~empty~. | ||
| 1. Replace _e_ in _S_.[[SetData]] with ~empty~. |
There was a problem hiding this comment.
Alternatively,
| 1. For each element _e_ of _S_.[[SetData]], do | |
| 1. Replace the element of _S_.[[SetData]] whose value is _e_ with an element whose value is ~empty~. | |
| 1. Replace _e_ in _S_.[[SetData]] with ~empty~. | |
| 1. Set _S_.[[SetData]] to a new empty List. |
or
| 1. For each element _e_ of _S_.[[SetData]], do | |
| 1. Replace the element of _S_.[[SetData]] whose value is _e_ with an element whose value is ~empty~. | |
| 1. Replace _e_ in _S_.[[SetData]] with ~empty~. | |
| 1. Remove all elements from _S_.[[SetData]]. |
There was a problem hiding this comment.
I have a question on 1. Set _S_.[[SetData]] to a new empty List., since the spec states as below. If it isn't a problem, I'll include the update on Map.prototype.clear as well.
The existing [[SetData]] List is preserved because there may be existing Set Iterator objects that are suspended midway through iterating over that List.
There was a problem hiding this comment.
Ah, right, I thought there was a reason we didn't do that, but couldn't remember. Then the latter suggestion is fine.
There was a problem hiding this comment.
I would strongly prefer the spec language to continue setting [[MapData]]/[[SetData]] elements to ~empty~ rather than removing them, because the latter is in invitation for potential future refactorings to introduce spec bugs by failing to account for multiple consumers of the same List (hence multiple notes about "there may be existing {Map,Set} Iterator objects that are suspended midway through iterating" and "The value EMPTY is used as a specification device to indicate that an entry has been deleted. Actual implementations may take other actions such as physically removing the entry").
There was a problem hiding this comment.
In fact, I find the index notation used by e.g. Set.prototype.forEach to be even more clear. Thoughts on adopting that throughout the Set/WeakSet algorithms?
| 1. For each element _e_ of _S_.[[SetData]], do | |
| 1. Replace the element of _S_.[[SetData]] whose value is _e_ with an element whose value is ~empty~. | |
| 1. Replace _e_ in _S_.[[SetData]] with ~empty~. | |
| 1. Let _numEntries_ be the number of elements in _S_.[[SetData]]. | |
| 1. Let _index_ be 0. | |
| 1. Repeat, while _index_ < _numEntries_, | |
| 1. Set _S_.[[SetData]][_index_] to ~empty~. | |
| 1. Set _index_ to _index_ + 1. |
| 1. Set _r_.[[Value]] to ~empty~. | ||
| 1. For each WeakSet _set_ such that _set_.[[WeakSetData]] contains _value_, do | ||
| 1. Replace the element of _set_.[[WeakSetData]] whose value is _value_ with an element whose value is ~empty~. | ||
| 1. Replace _value_ in _set_.[[WeakSetData]] with ~empty~. |
There was a problem hiding this comment.
I would prefer we emphasis that we know there's only one such element.
| 1. Replace _value_ in _set_.[[WeakSetData]] with ~empty~. | |
| 1. Replace the sole occurrence of _value_ in _set_.[[WeakSetData]] with ~empty~. |
I think that's what we were trying to get at with the original wording here.
There was a problem hiding this comment.
I also prefer adding the phrase the sole occurrence of. I'll make the update as a single commit after above conversation is resolved.
This PR unifies 'replace' step into a consistent form.
Currently there are two forms of 'replace element of a List' step in spec.
Form 1 is merged into Form 2, as Form 2 expresses same meaning with brevity.
For your reference, the 'replace element of an Object' is left as a separate form. (appears 2 times in spec)