| 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 |
| 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 * agen() { |
| 24 |
for await (let imported of [ |
| 25 |
import('./for-await-resolution-and-error-a_FIXTURE.js'), |
| 26 |
import('./for-await-resolution-and-error-b_FIXTURE.js'), |
| 27 |
import('./for-await-resolution-and-error-poisoned_FIXTURE.js'), |
| 28 |
]) { |
| 29 |
yield imported.x; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
var aiter = agen(); |
| 34 |
|
| 35 |
async function fn() { |
| 36 |
var a = aiter.next(); |
| 37 |
var b = aiter.next(); |
| 38 |
var c = aiter.next(); |
| 39 |
|
| 40 |
assert.sameValue((await a).value, 42); |
| 41 |
assert.sameValue((await b).value, 39); |
| 42 |
|
| 43 |
var error; |
| 44 |
try { |
| 45 |
await c; |
| 46 |
} catch (e) { |
| 47 |
error = e; |
| 48 |
} |
| 49 |
|
| 50 |
assert.sameValue(error, 'foo'); |
| 51 |
} |
| 52 |
|
| 53 |
asyncTest(fn); |