inner-iterator-created-in-order.js (1565B)
1 // |reftest| shell-option(--enable-iterator-sequencing) skip-if(!Iterator.concat||!xulRuntime.shell) -- iterator-sequencing is not enabled unconditionally, requires shell-options 2 // Copyright (C) 2024 André Bargull. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-iterator.concat 7 description: > 8 Inner iterators created in order 9 info: | 10 Iterator.concat ( ...items ) 11 12 ... 13 3. Let closure be a new Abstract Closure with no parameters that captures iterables and performs the following steps when called: 14 a. For each Record iterable of iterables, do 15 i. Let iter be ? Call(iterable.[[OpenMethod]], iterable.[[Iterable]]). 16 ... 17 v. Repeat, while innerAlive is true, 18 ... 19 features: [iterator-sequencing] 20 includes: [compareArray.js] 21 ---*/ 22 23 let calledIterator = []; 24 25 let iterable1 = { 26 [Symbol.iterator]() { 27 calledIterator.push("iterable1"); 28 return [1][Symbol.iterator](); 29 } 30 }; 31 32 let iterable2 = { 33 [Symbol.iterator]() { 34 calledIterator.push("iterable2"); 35 return [2][Symbol.iterator](); 36 } 37 }; 38 39 let iterator = Iterator.concat(iterable1, iterable2); 40 41 assert.compareArray(calledIterator, []); 42 43 let iterResult = iterator.next(); 44 assert.sameValue(iterResult.done, false); 45 assert.sameValue(iterResult.value, 1); 46 47 assert.compareArray(calledIterator, ["iterable1"]); 48 49 iterResult = iterator.next(); 50 assert.sameValue(iterResult.done, false); 51 assert.sameValue(iterResult.value, 2); 52 53 assert.compareArray(calledIterator, ["iterable1", "iterable2"]); 54 55 reportCompare(0, 0);