Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle module scripts that include top-level await. #984

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions worklets/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ When a user agent is to <dfn export>create a WorkletGlobalScope</dfn>, given |wo

6. Invoke the <a>initialize a global object's CSP list</a> algorithm given |workletGlobalScope|.

7. For each |entry| in the given |moduleResponsesMap| (in insertion order), run the following
7. Let |scripts| be «».

8. For each |entry| in the given |moduleResponsesMap| (in insertion order), run the following
substeps:

1. Let |moduleURLRecord| be |entry|'s key.
Expand All @@ -249,14 +251,19 @@ When a user agent is to <dfn export>create a WorkletGlobalScope</dfn>, given |wo
|moduleResponsesMap|, |outsideSettings|, and |insideSettings| when
it asynchronously completes.

3. <a>Run a module script</a> given |script|.
3. Let |promise| be the result of <a lt="run a module script">running a module script</a>
given |script|.

4. [=list/Append=] |promise| to |scripts|.

Note: <a>Fetch a worklet script</a> won't actually perform a network request as it will hit
the worklet's <a>module responses map</a>. It also won't have a parsing error as at this
point it should have successfully been parsed by another worklet global scope. I.e.
|script| should never be null here.

6. Run the <a>responsible event loop</a> specified by |insideSettings|.
9. [=Wait for all=] |scripts|, with success steps and failure steps both given by:

1. Run the <a>responsible event loop</a> specified by |insideSettings|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't right. Without an inner event loop, the microtask queue (and thus any awaits) cannot run.

I see two possible semantics here:

  • Ignore the promises returned; their errors will be reported appropriately, and that's all one would do with them.
  • Run the module scripts "sequentially", waiting for one to complete (i.e. the promise to settle) before moving on to the next.

I think the first of these is probably more correct, since (IIRC) it aligns with what happens if you have multiple TLA-using <script type=module>s.

</div>

### Script settings for worklets ### {#script-settings-for-worklets}
Expand Down Expand Up @@ -457,18 +464,21 @@ When the user agent is to <dfn>fetch and invoke a worklet script</dfn> given |wo

2. Reject |promise| with <a>error to rethrow</a>.

5. <a>Run a module script</a> given |script|.
5. Let |promise| be the result of <a lt="run a module script">running a module script</a> given
|script|.

6. <a>Queue a task</a> on |outsideSettings|'s <a>responsible event loop</a> to run these steps:
6. [=promise/React=] to |promise|:
* If |promise| was fulfilled or rejected, then:
1. <a>Queue a task</a> on |outsideSettings|'s <a>responsible event loop</a> to run these steps:

1. If |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> is not <b>-1</b>, then
run these steps:
1. If |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> is not <b>-1</b>, then
run these steps:

1. Decrement |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> by
<b>1</b>.
1. Decrement |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> by
<b>1</b>.

2. If |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> is <b>0</b>, then
resolve |promise|.
2. If |pendingTaskStruct|'s <a for="pending tasks struct">counter</a> is <b>0</b>, then
resolve |promise|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you shadowed an existing |promise| variable.

</div>

<div algorithm>
Expand Down