for-await-resolution-and-error-agen-yield.js (2203B)
1 // |reftest| async 2 // Copyright (C) 2018 Leo Balter. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 description: > 6 Resolve multiple imports through a for await loop in an async generator yielding imports 7 esid: sec-finishdynamicimport 8 info: | 9 Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion ) 10 11 2. Otherwise, 12 a. Assert: completion is a normal completion and completion.[[Value]] is undefined. 13 b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier). 14 c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed. 15 d. Let namespace be GetModuleNamespace(moduleRecord). 16 ... 17 f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »). 18 flags: [async] 19 features: [dynamic-import, async-iteration] 20 includes: [asyncHelpers.js] 21 ---*/ 22 23 async function * agen1() { 24 yield import('./for-await-resolution-and-error-a_FIXTURE.js'); 25 yield import('./for-await-resolution-and-error-b_FIXTURE.js'); 26 yield import('./for-await-resolution-and-error-poisoned_FIXTURE.js'); 27 } 28 29 async function * agen2() { 30 yield await import('./for-await-resolution-and-error-a_FIXTURE.js'); 31 yield await import('./for-await-resolution-and-error-b_FIXTURE.js'); 32 yield await import('./for-await-resolution-and-error-poisoned_FIXTURE.js'); 33 } 34 35 var aiter1 = agen1(); 36 var aiter2 = agen2(); 37 38 async function fn() { 39 var a = aiter1.next(); 40 var b = aiter1.next(); 41 var c = aiter1.next(); 42 var d = aiter2.next(); 43 var e = aiter2.next(); 44 var f = aiter2.next(); 45 46 assert.sameValue((await a).value.x, 42, 'a'); 47 assert.sameValue((await b).value.x, 39, 'b'); 48 49 var error; 50 try { 51 await c; 52 } catch (err) { 53 error = err; 54 } 55 56 assert.sameValue(error, 'foo', 'c'); 57 58 assert.sameValue((await d).value.x, 42, 'd'); 59 assert.sameValue((await e).value.x, 39, 'e'); 60 61 error = null; 62 try { 63 await f; 64 } catch (err) { 65 error = err; 66 } 67 68 assert.sameValue(error, 'foo', 'f'); 69 } 70 71 asyncTest(fn);