Skip to content

Commit 9c77873

Browse files
authored
Handle asynchronous modules (top-level await). (#1444)
1 parent d51e503 commit 9c77873

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

docs/index.bs

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ spec: push; urlPrefix: https://w3c.github.io/push-api/
5151
text: push; url: h-the-push-event
5252

5353
spec: ecma-262; urlPrefix: http://tc39.github.io/ecma262/
54+
type: abstract-op
55+
text: NormalCompletion; url: sec-normalcompletion
5456
type: dfn
5557
text: Assert; url: sec-algorithm-conventions
5658
text: [[Call]]; url: sec-ecmascript-function-objects-call-thisargument-argumentslist
@@ -64,6 +66,8 @@ spec: ecma-262; urlPrefix: http://tc39.github.io/ecma262/
6466
text: execution context; url: sec-execution-contexts
6567
text: abrupt completion; url: sec-completion-record-specification-type
6668
text: Completion; url: sec-completion-record-specification-type
69+
text: Module Record; url: sec-abstract-module-records
70+
text: Cyclic Module Record; url: sec-cyclic-module-records
6771

6872
spec: page-visibility; urlPrefix: https://www.w3.org/TR/page-visibility/
6973
type: enum; text: VisibilityState; url: VisibilityState
@@ -83,6 +87,9 @@ spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/
8387
text: delay the load event; for: document; url: delay-the-load-event
8488
urlPrefix: origin.html
8589
text: creating a policy container from a fetch response
90+
urlPrefix: webappapis.html
91+
text: module map; url: module-map
92+
text: resolve a module specifier; url: resolve-a-module-specifier
8693

8794
spec: fetch; urlPrefix: https://fetch.spec.whatwg.org/
8895
type: dfn
@@ -2704,16 +2711,15 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
27042711
Note: The control does not break the loop in this step to continue with all the imported scripts to populate the cache.
27052712
1. Asynchronously complete these steps with |response|.
27062713

2707-
If the algorithm asynchronously completes with null, then:
2714+
When the algorithm asynchronously completes, continue the rest of these steps, with |script| being the asynchronous completion value.
27082715

2709-
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
2710-
2711-
Note: This will do nothing if [=Reject Job Promise=] was previously invoked with "{{SecurityError}}" {{DOMException}}.
2716+
1. If |script| is null or [=Is Async Module=] with |script|'s [=script/record=], |script|'s [=script/base URL=], and « » is true, then:
2717+
1. Invoke [=Reject Job Promise=] with |job| and `TypeError`.
27122718

2713-
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|scopeURL|, [=URL serializer|serialized=]].
2714-
1. Invoke <a>Finish Job</a> with |job| and abort these steps.
2719+
Note: This will do nothing if [=Reject Job Promise=] was previously invoked with "{{SecurityError}}" {{DOMException}}.
27152720

2716-
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
2721+
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|scopeURL|, [=URL serializer|serialized=]].
2722+
1. Invoke [=Finish Job=] with |job| and abort these steps.
27172723
1. If |hasUpdatedResources| is false, then:
27182724
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
27192725
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
@@ -2930,8 +2936,17 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
29302936
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
29312937
1. If the <a>run CSP initialization for a global object</a> algorithm returns "<code>Blocked</code>" when executed upon |workerGlobalScope|, set |startFailed| to true and abort these steps.
29322938
1. If |serviceWorker| is an <a>active worker</a>, and there are any <a>tasks</a> queued in |serviceWorker|'s <a>containing service worker registration</a>'s [=service worker registration/task queues=], <a lt="queue a task">queue</a> them to |serviceWorker|'s <a>event loop</a>'s [=/task queues=] in the same order using their original <a>task sources</a>.
2933-
1. Let |evaluationStatus| be the result of <a lt="run a classic script">running the classic script</a> |script| if |script| is a <a>classic script</a>, otherwise, the result of <a lt="run a module script">running the module script</a> |script| if |script| is a [=module script=].
2934-
1. If |evaluationStatus|.\[[Value]] is empty, this means the script was not evaluated. Set |startFailed| to true and abort these steps.
2939+
1. Let |evaluationStatus| be null.
2940+
1. If |script| is a [=classic script=], then:
2941+
1. Set |evaluationStatus| to the result of [=run a classic script|running the classic script=] |script|.
2942+
1. If |evaluationStatus|.\[[Value]] is empty, this means the script was not evaluated. Set |startFailed| to true and abort these steps.
2943+
1. Otherwise, if |script| is a [=module script=], then:
2944+
1. Let |evaluationPromise| be the result of [=run a module script|running the module script=] |script|, with report errors set to false.
2945+
1. Assert: |evaluationPromise|.\[[PromiseState]] is not "pending".
2946+
1. If |evaluationPromise|.\[[PromiseState]] is "rejected":
2947+
1. Set |evaluationStatus| to [$ThrowCompletion$](|evaluationPromise|.\[[PromiseResult]]).
2948+
1. Otherwise:
2949+
1. Set |evaluationStatus| to [$NormalCompletion$](undefined).
29352950
1. If the script was aborted by the [=Terminate Service Worker=] algorithm, set |startFailed| to true and abort these steps.
29362951
1. Set |serviceWorker|'s [=start status=] to |evaluationStatus|.
29372952
1. If |script|'s <a>has ever been evaluated flag</a> is unset, then:
@@ -3593,6 +3608,33 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
35933608

35943609
Note: When an exception is [=throw|thrown=], the implementation does undo (roll back) any changes made to the cache storage during the batch operation job.
35953610
</section>
3611+
3612+
<section algorithm>
3613+
<h3 id="is-async-module-algorithm"><dfn>Is Async Module</dfn></h3>
3614+
3615+
: Input
3616+
:: |record|, a [=Module Record=]
3617+
:: |moduleMap|, a [=/module map=]
3618+
:: |base|, a [=/URL=]
3619+
:: |seen|, a [=/set=] of [=/URLs=]
3620+
: Output
3621+
:: a boolean
3622+
3623+
1. If |record| is not a [=Cyclic Module Record=], then:
3624+
1. Return false.
3625+
1. If |record|.\[[Async]] is true, then:
3626+
1. Return true.
3627+
1. [=list/For each=] string |requested| of |record|.\[[RequestedModules]]:
3628+
1. Let |url| be the result of [=resolve a module specifier|resolving a module specifier=] given |base| and |requested|.
3629+
1. Assert: |url| is never failure, because [=resolve a module specifier|resolving a module specifier=] must have been previously successful with these same two arguments.
3630+
1. If |seen| does not [=set/contain=] |url|, then:
3631+
1. [=set/Append=] |url| to |seen|.
3632+
1. If |moduleMap|[|url|] does not have a [=script/record=], then:
3633+
1. Return false.
3634+
1. If [=Is Async Module=] for |moduleMap|[|url|]'s [=script/record=], |moduleMap|, |base|, and |seen| is true, then:
3635+
1. Return true.
3636+
1. Return false.
3637+
</section>
35963638
</section>
35973639

35983640
<section>

0 commit comments

Comments
 (0)