| 1 |
// |reftest| module async |
| 2 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-moduleevaluation |
| 7 |
description: > |
| 8 |
Evaluate imported module with unwrapped imported promises |
| 9 |
info: | |
| 10 |
Table 3: Additional Fields of Cyclic Module Records |
| 11 |
|
| 12 |
[[Async]] |
| 13 |
|
| 14 |
... |
| 15 |
Having an asynchronous dependency does not make the module asynchronous. This field must not change after the module is parsed. |
| 16 |
|
| 17 |
Evaluate ( ) Concrete Method |
| 18 |
|
| 19 |
... |
| 20 |
6. Let capability be ! NewPromiseCapability(%Promise%). |
| 21 |
7. Set module.[[TopLevelCapability]] to capability. |
| 22 |
8. Let result be InnerModuleEvaluation(module, stack, 0). |
| 23 |
9. If result is an abrupt completion, then |
| 24 |
... |
| 25 |
d. Perform ! Call(capability.[[Reject]], undefined, «result.[[Value]]»). |
| 26 |
10. Otherwise, |
| 27 |
... |
| 28 |
b. If module.[[AsyncEvaluating]] is false, then |
| 29 |
i. Perform ! Call(capability.[[Resolve]], undefined, «undefined»). |
| 30 |
... |
| 31 |
11. Return undefinedcapability.[[Promise]]. |
| 32 |
|
| 33 |
InnerModuleEvaluation( module, stack, index ) |
| 34 |
|
| 35 |
... |
| 36 |
14. If module.[[PendingAsyncDependencies]] is > 0, set module.[[AsyncEvaluating]] to true. |
| 37 |
15. Otherwise, if module.[[Async]] is true, perform ! ExecuteAsyncModule(module). |
| 38 |
16. Otherwise, perform ? module.ExecuteModule(). |
| 39 |
|
| 40 |
ExecuteAsyncModule ( module ) |
| 41 |
|
| 42 |
1. Assert: module.[[Status]] is "evaluating" or "evaluated". |
| 43 |
2. Assert: module.[[Async]] is true. |
| 44 |
3. Set module.[[AsyncEvaluating]] to true. |
| 45 |
4. Let capability be ! NewPromiseCapability(%Promise%). |
| 46 |
5. Let stepsFulfilled be the steps of a CallAsyncModuleFulfilled function as specified below. |
| 47 |
... |
| 48 |
8. Let stepsRejected be the steps of a CallAsyncModuleRejected function as specified below. |
| 49 |
... |
| 50 |
11. Perform ! PerformPromiseThen(capability.[[Promise]], onFulfilled, onRejected). |
| 51 |
12. Perform ! module.ExecuteModule(capability). |
| 52 |
13. Return. |
| 53 |
|
| 54 |
ExecuteModule ( [ capability ] ) |
| 55 |
|
| 56 |
... |
| 57 |
11. If module.[[Async]] is false, then |
| 58 |
a. Assert: capability was not provided. |
| 59 |
b. Push moduleCxt on to the execution context stack; moduleCxt is now the running execution context. |
| 60 |
c. Let result be the result of evaluating module.[[ECMAScriptCode]]. |
| 61 |
d. Suspend moduleCxt and remove it from the execution context stack. |
| 62 |
e. Resume the context that is now on the top of the execution context stack as the running execution context. |
| 63 |
f. Return Completion(result). |
| 64 |
12. Otherwise, |
| 65 |
a. Assert: capability is a PromiseCapability Record. |
| 66 |
b. Perform ! AsyncBlockStart(capability, module.[[ECMAScriptCode]], moduleCxt). |
| 67 |
c. Return. |
| 68 |
flags: [module, async] |
| 69 |
features: [top-level-await] |
| 70 |
---*/ |
| 71 |
|
| 72 |
import mod from './module-import-unwrapped_FIXTURE.js'; |
| 73 |
import { x, y } from './module-import-unwrapped_FIXTURE.js'; |
| 74 |
|
| 75 |
assert(mod instanceof Promise, 'mod is an instance of Promise'); |
| 76 |
assert(x instanceof Promise, 'x is an instance of Promise'); |
| 77 |
assert(y instanceof Promise, 'y is an instance of Promise'); |
| 78 |
|
| 79 |
assert.sameValue(Object.getPrototypeOf(mod), Promise.prototype, 'Proto of mod'); |
| 80 |
assert.sameValue(Object.getPrototypeOf(x), Promise.prototype, 'Proto of x'); |
| 81 |
assert.sameValue(Object.getPrototypeOf(y), Promise.prototype, 'Proto of y'); |
| 82 |
|
| 83 |
assert.sameValue(await mod, 'default'); |
| 84 |
assert.sameValue(await y, 'unwrapped resolution'); |
| 85 |
|
| 86 |
var err; |
| 87 |
try { |
| 88 |
await x; |
| 89 |
} catch (e) { |
| 90 |
err = e; |
| 91 |
} |
| 92 |
|
| 93 |
assert.sameValue(err, 'unwrapped rejection'); |
| 94 |
|
| 95 |
// $DONE is set at the end to reflect the async operations from the imported module |
| 96 |
$DONE(); |