You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm a student studying ecma262. I'm not very experienced with the spec, so apologies if I'm off base here.
Possible Bug
Section 6.2.8 states that an Abstract Closure may only return a normal completion or a throw completion. It seems like the Abstract Closures in Iterator Helper methods explicitly return return completions, which would violate this constraint.
As of the ES2027 draft (April 2026), this appears to be present in the current spec text. Except for Iterator.concat, these methods seem to have carried this since their introduction in ES2025.
For example, Iterator.prototype.drop step 10 defines an Abstract Closure whose body contains:
10. Let closure be a new Abstract Closure with no parameters that captures iterated and integerLimit and performs the following steps when called:
...
b. Repeat, while remaining > 0,
...
iii. If next is done, return ReturnCompletion(undefined).
c. Repeat,
i. Let value be ? IteratorStepValue(iterated).
ii. If value is done, return ReturnCompletion(undefined).
Both return ReturnCompletion(undefined) statements seem to directly violate 6.2.8.
I also noticed that the .return() → GeneratorYield → IteratorClose path could propagate a return completion out of the Abstract Closure as well, as noted in #3606.
Affected methods
All Iterator Helper methods using CreateIteratorFromClosure whose Abstract Closures contain ReturnCompletion:
Iterator.prototype.drop (27.1.2.1)
Iterator.prototype.take (27.1.2.8)
Iterator.prototype.filter (27.1.2.3)
Iterator.prototype.map (27.1.2.5)
Iterator.prototype.flatMap (27.1.2.4)
Iterator.concat (27.1.2.1.1)
Related
This seems to overlap with existing issues, but if I'm reading correctly, eliminating ReturnCompletion here would be mandatory per the spec rather than a matter of preference.
Hi, I'm a student studying ecma262. I'm not very experienced with the spec, so apologies if I'm off base here.
Possible Bug
Section 6.2.8 states that an Abstract Closure may only return a normal completion or a throw completion. It seems like the Abstract Closures in Iterator Helper methods explicitly return return completions, which would violate this constraint.
As of the ES2027 draft (April 2026), this appears to be present in the current spec text. Except for
Iterator.concat, these methods seem to have carried this since their introduction in ES2025.For example,
Iterator.prototype.dropstep 10 defines an Abstract Closure whose body contains:Both
return ReturnCompletion(undefined)statements seem to directly violate 6.2.8.I also noticed that the
.return()→GeneratorYield→IteratorClosepath could propagate a return completion out of the Abstract Closure as well, as noted in #3606.Affected methods
All Iterator Helper methods using
CreateIteratorFromClosurewhose Abstract Closures containReturnCompletion:Iterator.prototype.drop(27.1.2.1)Iterator.prototype.take(27.1.2.8)Iterator.prototype.filter(27.1.2.3)Iterator.prototype.map(27.1.2.5)Iterator.prototype.flatMap(27.1.2.4)Iterator.concat(27.1.2.1.1)Related
This seems to overlap with existing issues, but if I'm reading correctly, eliminating
ReturnCompletionhere would be mandatory per the spec rather than a matter of preference.%IteratorHelperPrototype%.return()/IteratorClosepath)Possible resolutions
If this is confirmed as a bug, I'd be happy to submit a PR once an approach is decided on. Thanks for your time and for maintaining the spec!