|
| 1 | +// Copyright (C) 2025 Michael Ficarra. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | + |
| 4 | +/*--- |
| 5 | +esid: sec-iterator.concat |
| 6 | +description: > |
| 7 | + Iterator.concat accesses the value of a done IteratorResult, matching the behaviour of yield* |
| 8 | +info: | |
| 9 | + Iterator.concat ( ...items ) |
| 10 | +
|
| 11 | + ... |
| 12 | + 3. Let closure be a new Abstract Closure with no parameters that captures iterables and performs the following steps when called: |
| 13 | + a. For each Record iterable of iterables, do |
| 14 | + ... |
| 15 | + v. Repeat, while innerAlive is true, |
| 16 | + 1. Let iteratorResult be ? IteratorNext(iteratorRecord). |
| 17 | + 2. Let done be Completion(IteratorComplete(iteratorResult)). |
| 18 | + 3. If done is a throw completion, then |
| 19 | + a. Set iteratorRecord.[[Done]] to true. |
| 20 | + b. Return ? done. |
| 21 | + 4. Set done to ! done. |
| 22 | + 5. If done is true, then |
| 23 | + a. Set iteratorRecord.[[Done]] to true. |
| 24 | + b. Perform ? IteratorValue(iteratorResult). |
| 25 | + ... |
| 26 | +features: [iterator-sequencing] |
| 27 | +---*/ |
| 28 | + |
| 29 | +let valueAccesses = 0; |
| 30 | +let iter = { |
| 31 | + [Symbol.iterator]() { |
| 32 | + return { |
| 33 | + next() { |
| 34 | + return { |
| 35 | + get value() { |
| 36 | + ++valueAccesses; |
| 37 | + }, |
| 38 | + done: true, |
| 39 | + }; |
| 40 | + }, |
| 41 | + }; |
| 42 | + } |
| 43 | +}; |
| 44 | + |
| 45 | +Array.from(function*() { yield* iter; }()); |
| 46 | + |
| 47 | +assert.sameValue(valueAccesses, 1, 'yield* accesses value getter after done'); |
| 48 | + |
| 49 | +Array.from(Iterator.concat(iter, iter, iter)); |
| 50 | + |
| 51 | +assert.sameValue(valueAccesses, 4, 'Iterator.concat also accesses value getter after each iterator is done'); |
0 commit comments