invoke-resolve-error-close.js (1389B)
1 // |reftest| async 2 // Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 description: > 7 Explicit iterator closing in response to error 8 esid: sec-promise.any 9 info: | 10 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability). 11 6. If result is an abrupt completion, then 12 a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). 13 b. IfAbruptRejectPromise(result, promiseCapability). 14 15 Runtime Semantics: PerformPromiseAny 16 17 8. Repeat 18 ... 19 i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). 20 flags: [async] 21 features: [Promise.any, Symbol.iterator, computed-property-names, Symbol, arrow-function] 22 ---*/ 23 24 let error = new Test262Error(); 25 let nextCount = 0; 26 let returnCount = 0; 27 let iter = { 28 [Symbol.iterator]() { 29 return { 30 next() { 31 nextCount += 1; 32 return { 33 value: null, 34 done: false 35 }; 36 }, 37 return() { 38 returnCount += 1; 39 } 40 }; 41 } 42 }; 43 44 Promise.resolve = function() { 45 throw error; 46 }; 47 48 Promise.any(iter).then(() => { 49 $DONE('The promise should be rejected, but was resolved'); 50 }, (reason) => { 51 assert.sameValue(nextCount, 1); 52 assert.sameValue(returnCount, 1); 53 assert.sameValue(reason, error); 54 }).then($DONE, $DONE);