Skip to content

Commit 12fbfaf

Browse files
Ms2gerjakearchibaldcodehag
committed
Handle asynchronous modules (top-level await).
Fixes w3c#1407. Co-authored-by: Jake Archibald <[email protected]> Co-authored-by: yulia <[email protected]>
1 parent 4b5d041 commit 12fbfaf

File tree

1 file changed

+50
-9
lines changed

1 file changed

+50
-9
lines changed

docs/index.bs

+50-9
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
@@ -2710,16 +2717,15 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
27102717
Note: The control does not break the loop in this step to continue with all the imported scripts to populate the cache.
27112718
1. Asynchronously complete these steps with |response|.
27122719

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

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

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

2722-
Else, continue the rest of these steps after the algorithm's asynchronous completion, with |script| being the asynchronous completion value.
2727+
1. If |newestWorker| is null, then [=map/remove=] [=scope to registration map=][|scopeURL|, [=URL serializer|serialized=]].
2728+
1. Invoke [=Finish Job=] with |job| and abort these steps.
27232729
1. If |hasUpdatedResources| is false, then:
27242730
1. Set |registration|'s [=service worker registration/update via cache mode=] to |job|'s [=job/update via cache mode=].
27252731
1. Invoke [=Resolve Job Promise=] with |job| and |registration|.
@@ -2940,8 +2946,17 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
29402946
1. Create a new {{WorkerLocation}} object and associate it with |workerGlobalScope|.
29412947
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.
29422948
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>.
2943-
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=].
2944-
1. If |evaluationStatus|.\[[Value]] is empty, this means the script was not evaluated. Set |startFailed| to true and abort these steps.
2949+
1. Let |evaluationStatus| be null.
2950+
1. If |script| is a [=classic script=], then:
2951+
1. Set |evaluationStatus| to the result of [=run a classic script|running the classic script=] |script|.
2952+
1. If |evaluationStatus|.\[[Value]] is empty, this means the script was not evaluated. Set |startFailed| to true and abort these steps.
2953+
1. Otherwise, if |script| is a [=module script=], then:
2954+
1. Let |evaluationPromise| be the result of [=run a module script|running the module script=] |script|, with report errors set to false.
2955+
1. Assert: |evaluationPromise|.\[[PromiseState]] is not "pending".
2956+
1. If |evaluationPromise|.\[[PromiseState]] is "rejected":
2957+
1. Set |evaluationStatus| to [$ThrowCompletion$](|evaluationPromise|.\[[PromiseResult]]).
2958+
1. Otherwise:
2959+
1. Set |evaluationStatus| to [$NormalCompletion$](undefined).
29452960
1. If the script was aborted by the [=Terminate Service Worker=] algorithm, set |startFailed| to true and abort these steps.
29462961
1. Set |serviceWorker|'s [=start status=] to |evaluationStatus|.
29472962
1. If |script|'s <a>has ever been evaluated flag</a> is unset, then:
@@ -3603,6 +3618,32 @@ spec: webappsec-referrer-policy; urlPrefix: https://w3c.github.io/webappsec-refe
36033618

36043619
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.
36053620
</section>
3621+
3622+
<section algorithm>
3623+
<h3 id="is-async-module-algorithm"><dfn>Is Async Module</dfn></h3>
3624+
3625+
: Input
3626+
:: |record|, a [=Module Record=]
3627+
:: |moduleMap|, a [=/module map=]
3628+
:: |base|, a [=/URL=]
3629+
:: |seen|, a [=/set=] of [=/URLs=]
3630+
: Output
3631+
:: a boolean
3632+
3633+
1. If |record| is not a [=Cyclic Module Record=], then:
3634+
1. Return false.
3635+
1. If |record|.\[[Async]] is true, then:
3636+
1. Return true.
3637+
1. [=list/For each=] string |requested| of |record|.\[[RequestedModules]]:
3638+
1. Let |url| be the result of [=resolve a module specifier|resolving a module specifier=] given |base| and |requested|.
3639+
1. If |url| is *failure*:
3640+
1. Return false.
3641+
1. If |seen| does not [=set/contain=] |url|, then:
3642+
1. [=set/Append=] |url| to |seen|.
3643+
1. If [=Is Async Module=] for |moduleMap|[|url|]'s [=script/record=], |moduleMap|, |base|, and |seen| is true, then:
3644+
1. Return true.
3645+
1. Return false.
3646+
</section>
36063647
</section>
36073648

36083649
<section>

0 commit comments

Comments
 (0)