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

[worklets] Fix module loading when creating a new worklet global scope. #264

Closed
wants to merge 2 commits 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
100 changes: 58 additions & 42 deletions worklets/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ urlPrefix: http://heycam.github.io/webidl/#dfn-; type: dfn;
urlPrefix: https://fetch.spec.whatwg.org/; type: dfn;
urlPrefix: #concept-;
text: fetch
url: request-url; text: url;
urlPrefix: https://html.spec.whatwg.org/multipage/browsers.html; type: dfn;
text: effective script origin
url: #origin-2; text: origin
Expand Down Expand Up @@ -180,17 +181,14 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, for a given |wor

4. Associate the |settingsObject| with |workletGlobalScope|.

5. For each |entry| in the given |worklet|'s <a>module responses map</a> (in insertion order),
run the following substeps:
5. For each |resolvedModuleURL| in the given |worklet|'s <a>top level module url list</a> (in
insertion order), run the following substeps:

1. Let |resolvedModuleURL| be |entry|'s key.
1. <a>Fetch a module worklet script tree</a> given |worklet|, |resolvedModuleURL|,
|outsideSettings|, and |settingsObject|.

2. Let |script| be the result of <a>fetch a module script tree</a> given
|resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a>, and
|settingsObject|.

Note: Worklets follow <a>web workers</a> here in not allowing "use-credientials" for
fetching resources.
2. Let |script| be the result of <a>fetch a module worklet script tree</a> when it
asynchronously completes.

3. <a>Run a module script</a> given |script|.

Expand Down Expand Up @@ -247,6 +245,44 @@ When a user agent is to <dfn>set up a worklet environment settings object</dfn>,

Issue: Merge this with https://html.spec.whatwg.org/multipage/workers.html#set-up-a-worker-environment-settings-object

### Fetching a module worklet script tree ### {#fetching-a-module-worklet-script-tree}

When a user agent is to <dfn>fetch a module worklet script tree</dfn>, given |worklet|,
|resolvedModuleURL|, |outsideSettings|, and |insideSettings|, it must run the following steps:

1. <a>Fetch a module worker script tree</a> given |resolvedModuleURL|, |outsideSettings|,
"script", "omit", and |insideSettings|.

To <a>perform the fetch</a> given |request|, and the |isTopLevel| flag, perform the
following steps:

1. Let |cache| be |worklet|'s <a>module responses map</a>.

2. Let |url| be |request|'s <a>url</a>.

3. If |cache| contains an entry with key |url| whose value is "fetching", wait
(<a>in parallel</a>) until that entry's value changes, then proceed to the
next step.

4. If |cache| contains an entry with key |url|, asynchronously complete this
algorithm with that entry's value, and abort these steps.

5. Create an entry in |cache| with key |url| and value "fetching".

6. <a>Fetch</a> |request|.

7. Let |response| be the result of <a>fetch</a> when it asynchronously
completes.

8. If |isTopLevel| is set, append |resolvedModuleURL| the |worklet|'s <a>top level
module url list</a>

9. Set the value of the entry in |cache| whose key is |url| to |response|, and
asynchronously complete this algorithm with |response|.

2. Asynchronously complete this algorithm with the result of <a>fetch a module worker script
tree</a> when it completes.

Worklet {#worklet-section}
--------------------------

Expand All @@ -268,13 +304,17 @@ Note: As an example the <a>worklet global scope type</a> might be a {{PaintWorkl
A {{Worklet}} has a list of the <dfn export>worklet's WorkletGlobalScopes</dfn>. Initially this list
is empty; it is populated when the user agent chooses to create its {{WorkletGlobalScope}}.

A {{Worklet}} has a <dfn>module responses map</dfn>. This is a ordered map of module URLs to values
that are a <a>fetch</a> responses. The map's entries are ordered based on their insertion order.
Access to this map should be thread-safe.
A {{Worklet}} has a <dfn>module responses map</dfn>. This is a map of module URLs to values that are
a <a>fetch</a> responses. Access to this map should be thread-safe.

A {{Worklet}} has a <dfn>top level module url list</dfn>. This is a ordered list of module URLs. The
list's entries are ordered based on their insertion order. Access to this list should be
thread-safe.

The <a>module responses map</a> exists to ensure that {{WorkletGlobalScope}}s created at different
times contain the same set of script source text and have the same behaviour. The creation of
additional {{WorkletGlobalScope}}s should be transparent to the author.
The <a>module responses map</a> and <a>top level module url list</a> exists to ensure that
{{WorkletGlobalScope}}s created at different times contain the same set of script source text and
have the same behaviour. The creation of additional {{WorkletGlobalScope}}s should be transparent to
the author.

When the <dfn method for=Worklet>import(|moduleURL|)</dfn> method is called on a {{Worklet}} object,
the user agent <em>must</em> run the following steps:
Expand Down Expand Up @@ -302,34 +342,10 @@ the user agent <em>must</em> run the following steps:
1. Let |insideSettings| be the {{WorkletGlobalScope}}'s associated <a>environment
settings object</a>.

2. <a>Fetch a module script tree</a> given |resolvedModuleURL|, "omit", the empty string
(as no cryptographic nonce is present for worklets), "not parser-inserted",
"script", |outsideSettings|, and |insideSettings|.

To <a>perform the request</a> given |request|, perform the following steps:

1. Let |cache| be the current {{Worklet}}'s <a>module responses map</a>.

2. Let |url| be |request|'s <a >url</a>.

3. If |cache| contains an entry with key |url| whose value is "fetching", wait
(<a>in parallel</a>) until that entry's value changes, then proceed to the
next step.

4. If |cache| contains an entry with key |url|, asynchronously complete this
algorithm with that entry's value, and abort these steps.

5. Create an entry in |cache| with key |url| and value "fetching".

6. <a>Fetch</a> |request|.

7. Let |response| be the result of <a>fetch</a> when it asynchronously
completes.

8. Set the value of the entry in |cache| whose key is |url| to |response|, and
asynchronously complete this algorithm with |response|.
2. <a>Fetch a module worklet script tree</a> given the current {{Worklet}},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "the current Worklet" is not defined here. I think you want to add a step at the top of this method definition that does "Let worklet be this Worklet object" or similar. (Other acceptable phrasing: "the Worklet object on which this method was called".) Then you can use worklet later.

|resolvedModuleURL|, |outsideSettings|, and |settingsObject|.

3. Let |script| be the result of <a>fetch a module script tree</a> when it
3. Let |script| be the result of <a>fetch a module worklet script tree</a> when it
asynchronously completes.

4. <a>Run a module script</a> given |script|.
Expand Down