Stage 2.7 Draft / December 3, 2024

Iterator Sequencing

1 Iterator.concat ( ...items )

  1. Let iterables be a new empty List.
  2. For each element item of items, do
    1. If item is not an Object, throw a TypeError exception.
    2. Let method be ? GetMethod(item, %Symbol.iterator%).
    3. If method is undefined, throw a TypeError exception.
    4. Append the Record { [[OpenMethod]]: method, [[Iterable]]: item } to iterables.
  3. Let closure be a new Abstract Closure with no parameters that captures iterables and performs the following steps when called:
    1. For each Record iterable of iterables, do
      1. Let iter be ? Call(iterable.[[OpenMethod]], iterable.[[Iterable]]).
      2. If iter is not an Object, throw a TypeError exception.
      3. Let iteratorRecord be ? GetIteratorDirect(iter).
      4. Let innerAlive be true.
      5. Repeat, while innerAlive is true,
        1. Let iteratorResult be ? IteratorStep(iteratorRecord).
        2. If iteratorResult is done, then
          1. Perform ? IteratorValue(iteratorResult).
          2. Set innerAlive to false.
        3. Else,
          1. Let completion be Completion(GeneratorYield(iteratorResult)).
          2. If completion is an abrupt completion, then
            1. Return ? IteratorClose(iteratorRecord, completion).
    2. Return ReturnCompletion(undefined).
  4. Let gen be CreateIteratorFromClosure(closure, "Iterator Helper", %IteratorHelperPrototype%, « [[UnderlyingIterators]] »).
  5. Set gen.[[UnderlyingIterators]] to a new empty List.
  6. Return gen.