Skip to content

Iterator Helper Abstract Closures return Return Completions, violating 6.2.8 #3799

@arcde40

Description

@arcde40

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()GeneratorYieldIteratorClose 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.

Possible resolutions

  1. Relax 6.2.8 to permit return completions for Abstract Closures used as generator bodies.
  2. Change the Iterator Helper algorithms to avoid returning return completions from the Abstract Closure (as noted in Editorial: non-syntactic async/generator functions use NormalCompletion #3606, this may be non-trivial).

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions