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