Skip to content

Iterator protocol: make GetIterator require and honor @@iterator #752

Description

@chrisbbreuer

Parents: #475, #493
Related: #750, #751

Problem

The shared iteratorOf entry point is more permissive than ECMA-262 GetIterator:

  • an ordinary object with a .next property but no Symbol.iterator is accepted as iterable;
  • generator objects are returned before their observable Symbol.iterator property is read, so an override, getter, deletion, or non-callable value is ignored.

A current-main probe returns false,1,1,0 for [manualObjectThrew, manualNextCalls, overriddenGeneratorSum, iteratorGetterCalls]; the specified result is true,0,7,1. This affects consumers such as Math.sumPrecise even though their subsequent IteratorStep behavior is correct.

Scope

  • Make the language GetIterator path perform ordinary GetMethod on @@iterator, require it to be callable, call it once with the input as receiver, and require an Object result.
  • Honor observable overrides/deletions on generator and other built-in iterator objects.
  • Keep deliberate GetIteratorDirect/GetIteratorFlattenable consumers distinct.
  • Audit every iteratorOf caller for the correct abstract operation and retain one captured [[NextMethod]] per iterator record.
  • Preserve intrinsic array/string/Map/Set iteration behavior without changing their iterator storage or next implementations.

No-workaround rules

  • No .next-property duck typing for GetIterator, generator/builtin bypass, array-only shortcut that skips observable @@iterator, repeated method lookup, source rewriting, or silent fallback after a missing/non-callable method.
  • No stack, queue, job, Promise, Worker, or Map/Set iterator implementation changes.

Acceptance

  • Plain .next objects are rejected without calling next; an explicit @@iterator makes them iterable.
  • Generator/builtin @@iterator getters, overrides, deletion, non-callable values, receiver, and result validation are observed in spec order.
  • Every iteratorOf caller is classified as GetIterator, GetIteratorDirect, or GetIteratorFlattenable and captures [[NextMethod]] once where required.
  • Focused units, affected Test262 iterator/builtin subtrees, and full integration gates pass with exact nonzero accounting and zero unrelated flips.

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