diff --git a/worklets/Overview.bs b/worklets/Overview.bs index 9d8d656f..75d54393 100644 --- a/worklets/Overview.bs +++ b/worklets/Overview.bs @@ -12,7 +12,12 @@ Editor: Ian Kilpatrick, ikilpatrick@chromium.org
urlPrefix: http://heycam.github.io/webidl/#dfn-; type: dfn; + text: DOMException + text: SyntaxError text: inherit +urlPrefix: https://fetch.spec.whatwg.org/; type: dfn; + urlPrefix: #concept-; + text: fetch urlPrefix: https://html.spec.whatwg.org/multipage/browsers.html; type: dfn; text: effective script origin url: #origin-2; text: origin @@ -27,7 +32,6 @@ urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; type: dfn; text: code entry-point text: creation url text: document environment - text: entry settings object text: environment settings object text: event loop text: fetch a module script tree @@ -36,7 +40,9 @@ urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; type: dfn; text: incumbent settings object text: microtask queue text: module script + text: perform the request text: realm execution context + text: relevant settings object text: responsible browsing context text: responsible document text: responsible event loop @@ -174,16 +180,19 @@ When a user agent is to create a WorkletGlobalScope, for a given |wor 4. Associate the |settingsObject| with |workletGlobalScope|. - 5. For each |resolvedModuleURL| in the given |worklet|'s worklet's resolved module URLs, + 5. For each |entry| in the given |worklet|'s module responses map (in insertion order), run the following substeps: - 1. Let |script| be the result of fetch a module script tree given + + 1. Let |resolvedModuleURL| be |entry|'s key. + + 2. Let |script| be the result of fetch a module script tree given |resolvedModuleURL|, "anonymous" for the CORS setting attribute, and |settingsObject|. Note: Worklets follow web workers here in not allowing "use-credientials" for fetching resources. - 2. Run a module script given |script|. + 3. Run a module script given |script|. ### Script settings for worklets ### {#script-settings-for-worklets} @@ -247,7 +256,7 @@ The {{Worklet}} object provides the capability to import module scripts into itsinterface Worklet { - [NewObject] Promise<void> import(DOMString moduleURL); + [NewObject] Promise<void> import(USVString moduleURL); };@@ -259,42 +268,73 @@ Note: As an example the worklet global scope type might be a {{PaintWorkl A {{Worklet}} has a list of the worklet's WorkletGlobalScopes. Initially this list is empty; it is populated when the user agent chooses to create its {{WorkletGlobalScope}}. -A {{Worklet}} has a list of the worklet's resolved module URLs. Initially this list is -empty; it is populated when module scripts resolved. +A {{Worklet}} has a module responses map. This is a ordered map of module URLs to values +that are a fetch responses. The map's entries are ordered based on their insertion order. +Access to this map should be thread-safe. + +The module responses map 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 import(|moduleURL|) method is called on a {{Worklet}} object, the user agent must run the following steps: 1. Let |promise| be a new promise. - 2. Run the following steps in parallel: - 1. Let |resolvedModuleURL| be the result of resolving the |moduleURL| relative to the - API base URL specified by the entry settings object when the method was - invoked. + 2. Let |resolvedModuleURL| be the result of parsing the |moduleURL| argument relative to + the relevant settings object of this. + + 3. If this fails, reject |promise| with a "SyntaxError" DOMException and abort + these steps. - 2. If this fails, reject |promise| with a SyntaxError exception and abort these - steps. + 4. Ensure that there is at least one {{WorkletGlobalScope}} in the worklet's + WorkletGlobalScopes. If not create a WorkletGlobalScope given the current + {{Worklet}}. - 3. Add |resolvedModuleURL| to the list of worklet's resolved module URLs. + The user-agent may also create additional {{WorkletGlobalScope}}s at this time. - 4. Ensure that there is at least one {{WorkletGlobalScope}} in the worklet's - WorkletGlobalScopes. If not create a WorkletGlobalScope given the current - {{Worklet}}. + 5. Let |outsideSettings| be the relevant settings object of this. - 5. For each {{WorkletGlobalScope}} in the worklet's WorkletGlobalScopes, run these + 6. Run the following steps in parallel: + + 1. For each {{WorkletGlobalScope}} in the worklet's WorkletGlobalScopes, run these substeps: - 1. Let |settings| be the {{WorkletGlobalScope}}'s associated environment settings - object. - 2. Let |script| be the result of fetch a module script tree given - |resolvedModuleURL|, "anonymous" for the CORS setting attribute, and - |settings|. + 1. Let |insideSettings| be the {{WorkletGlobalScope}}'s associated environment + settings object. + + 2. Fetch a module script tree given |resolvedModuleURL|, "omit", the empty string + (as no cryptographic nonce is present for worklets), "not parser-inserted", + "script", |outsideSettings|, and |insideSettings|. + + To perform the request given |request|, perform the following steps: + + 1. Let |cache| be the current {{Worklet}}'s module responses map. + + 2. Let |url| be |request|'s url. + + 3. If |cache| contains an entry with key |url| whose value is "fetching", wait + (in parallel) 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. Fetch |request|. + + 7. Let |response| be the result of fetch 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|. - Note: Worklets follow web workers here in not allowing "use-credientials" for - fetching resources. + 3. Let |script| be the result of fetch a module script tree when it + asynchronously completes. - 3. Run a module script given |script|. + 4. Run a module script given |script|. - 6. If all the steps above succeeded (in particular, if all of the scripts parsed + 2. If all the steps above succeeded (in particular, if all of the scripts parsed and loaded into the global scopes), resolve |promise|.
Otherwise, reject |promise|. @@ -302,9 +342,10 @@ the user agent must run the following steps: reject the promise; if the script throws an error while first evaluating the promise should resolve as a classes may have been registered correctly. - 3. Return |promise|. + 7. Return |promise|. -Issue(w3c/css-houdini-drafts#47): Need ability to load code into {{WorkletGlobalScope}} declaratively. +Issue(w3c/css-houdini-drafts#47): Need ability to load code into a {{WorkletGlobalScope}} + declaratively. Lifetime of the Worklet {#lifetime-of-the-worklet} --------------------------------------------------