iterator-zip-iteration-strict-iterator-close-i-is-not-zero-abrupt-completion.js (3170B)
1 // Copyright (C) 2025 André Bargull. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-iterator.zipkeyed 6 description: > 7 Handle abrupt completion from IteratorCloseAll in IteratorZip. 8 info: | 9 Iterator.zipKeyed ( iterables [ , options ] ) 10 ... 11 16. Return IteratorZip(iters, mode, padding, finishResults). 12 13 IteratorZip ( iters, mode, padding, finishResults ) 14 3. Let closure be a new Abstract Closure with no parameters that captures 15 iters, iterCount, openIters, mode, padding, and finishResults, and 16 performs the following steps when called: 17 ... 18 b. Repeat, 19 ... 20 iii. For each integer i such that 0 ≤ i < iterCount, in ascending order, do 21 ... 22 3. Else, 23 ... 24 d. If result is done, then 25 i. Remove iter from openIters. 26 ... 27 iii. Else if mode is "strict", then 28 i. If i ≠ 0, then 29 i. Return ? IteratorCloseAll(openIters, ThrowCompletion(a newly created TypeError object)). 30 ... 31 32 IteratorCloseAll ( iters, completion ) 33 1. For each element iter of iters, in reverse List order, do 34 a. Set completion to Completion(IteratorClose(iter, completion)). 35 2. Return ? completion. 36 37 IteratorClose ( iteratorRecord, completion ) 38 1. Assert: iteratorRecord.[[Iterator]] is an Object. 39 2. Let iterator be iteratorRecord.[[Iterator]]. 40 3. Let innerResult be Completion(GetMethod(iterator, "return")). 41 4. If innerResult is a normal completion, then 42 a. Let return be innerResult.[[Value]]. 43 b. If return is undefined, return ? completion. 44 c. Set innerResult to Completion(Call(return, iterator)). 45 5. If completion is a throw completion, return ? completion. 46 ... 47 includes: [compareArray.js] 48 features: [joint-iteration] 49 ---*/ 50 51 var log = []; 52 53 var first = { 54 next() { 55 log.push("call first next"); 56 return {done: false}; 57 }, 58 return() { 59 // Called with the correct receiver and no arguments. 60 assert.sameValue(this, first); 61 assert.sameValue(arguments.length, 0); 62 63 // NB: Log after above asserts, because failures aren't propagated. 64 log.push("call first return"); 65 66 return {}; 67 } 68 }; 69 70 var second = { 71 next() { 72 log.push("call second next"); 73 return {done: true}; 74 }, 75 return() { 76 log.push("unexpected call second return"); 77 } 78 }; 79 80 var third = { 81 next() { 82 log.push("unexpected call third next"); 83 }, 84 return() { 85 // Called with the correct receiver and no arguments. 86 assert.sameValue(this, third); 87 assert.sameValue(arguments.length, 0); 88 89 // NB: Log after above asserts, because failures aren't propagated. 90 log.push("call third return"); 91 92 // IteratorClose ignores new exceptions when called with a Throw completion. 93 throw new Test262Error(); 94 } 95 }; 96 97 var it = Iterator.zipKeyed({first, second, third}, {mode: "strict"}); 98 99 assert.throws(TypeError, function() { 100 it.next(); 101 }); 102 103 assert.compareArray(log, [ 104 "call first next", 105 "call second next", 106 "call third return", 107 "call first return", 108 ]); 109 110 reportCompare(0, 0);