errors-iterabletolist.js (1795B)
1 // Copyright (C) 2019 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-aggregate-error 6 description: > 7 Iteration of errors 8 info: | 9 AggregateError ( errors, message ) 10 11 ... 12 3. Let errorsList be ? IterableToList(errors). 13 4. Set O.[[AggregateErrors]] to errorsList. 14 ... 15 6. Return O. 16 17 Runtime Semantics: IterableToList ( items [ , method ] ) 18 19 1. If method is present, then 20 ... 21 2. Else, 22 b. Let iteratorRecord be ? GetIterator(items, sync). 23 3. Let values be a new empty List. 24 4. Let next be true. 25 5. Repeat, while next is not false 26 a. Set next to ? IteratorStep(iteratorRecord). 27 b. If next is not false, then 28 i. Let nextValue be ? IteratorValue(next). 29 ii. Append nextValue to the end of the List values. 30 6. Return values. 31 32 GetIterator ( obj [ , hint [ , method ] ] ) 33 34 ... 35 3. If method is not present, then 36 a. If hint is async, then 37 ... 38 b. Otherwise, set method to ? GetMethod(obj, @@iterator). 39 4. Let iterator be ? Call(method, obj). 40 5. If Type(iterator) is not Object, throw a TypeError exception. 41 6. Let nextMethod be ? GetV(iterator, "next"). 42 ... 43 8. Return iteratorRecord. 44 features: [AggregateError, Symbol.iterator] 45 includes: [compareArray.js] 46 ---*/ 47 48 var count = 0; 49 var values = []; 50 var case1 = { 51 [Symbol.iterator]() { 52 return { 53 next() { 54 count += 1; 55 return { 56 done: count === 3, 57 get value() { 58 values.push(count) 59 } 60 }; 61 } 62 }; 63 } 64 }; 65 66 new AggregateError(case1); 67 68 assert.sameValue(count, 3); 69 assert.compareArray(values, [1, 2]); 70 71 assert.throws(TypeError, () => { 72 new AggregateError(); 73 }, 'GetMethod(obj, @@iterator) returns undefined'); 74 75 reportCompare(0, 0);