New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial: Simplify algorithms by making (Async)IteratorClose idempotent #3276
base: main
Are you sure you want to change the base?
Conversation
This removes a lot of encapsulation-piercing _iteratorRecord_.[[Done]] checks.
Hmm. This does simplify the algorithms, but I'm not sure it's actually an improvement, especially given that many uses e.g. deterministically know that the iterator is not closed at the time they call IteratorClose. What if instead we add a new AO like |
I considered something like that, and decided that it wasn't very helpful but to be honest am still on the fence. However, rather than introducing a new operation, I'd prefer to precede selected steps with
|
There's another 7 coming in iterator helpers, another 2 in Set methods, and another 8 in temporal, all of which only call IteratorClose on iterators known to be open at the time of the call. These will increasingly be the common case - the ones currently in the spec are the unusual ones, which I don't want to optimize for. |
I think we could also make things more clear by refactoring IfAbruptCloseIterator to return the unwrapped value rather than using it for alias reassignment, such that rather than being a shorthand it is a local operation more similar to IteratorClose: - 1. IfAbruptCloseIterator(_key_, _iteratorRecord_).
+ 1. Set _key_ to ? IfAbruptCloseIterator(_key_, _iteratorRecord_). |
Unfortunately we can't make that change for IfAbruptRejectPromise, because in that case the macro is returning a normal completion (containing a rejected promise) from the containing algorithm. So the value of doing it for IfAbruptCloseIterator is somewhat diminished (because it would be out of sync with IfAbruptRejectPromise). Still maybe worth it on net; I'm not sure. |
Good point, and de-macroizing IfAbruptRejectPromise would require new steps. - 1. IfAbruptRejectPromise(_return_, _promiseCapability_).
+ 1. Let _rejected_ be IfAbruptRejectPromise(_return_, _promiseCapability_).
+ 1. If _rejected_ is not ~empty~, return _rejected_; else set _return_ to ! _return_. I'll leave this open for a few days of consideration. |
In editor call @michaelficarra was also not in favor of this PR as-is, and didn't think that |
This removes a lot of encapsulation-piercing iteratorRecord.[[Done]] checks.