@@ -12,7 +12,12 @@ Editor: Ian Kilpatrick, ikilpatrick@chromium.org
12
12
13
13
<pre class="anchors">
14
14
urlPrefix: http://heycam.github.io/webidl/#dfn-; type: dfn;
15
+ text: DOMException
16
+ text: SyntaxError
15
17
text: inherit
18
+ urlPrefix: https://fetch.spec.whatwg.org/; type: dfn;
19
+ urlPrefix: #concept-;
20
+ text: fetch
16
21
urlPrefix: https://html.spec.whatwg.org/multipage/browsers.html; type: dfn;
17
22
text: effective script origin
18
23
url: #origin-2; text: origin
@@ -27,7 +32,6 @@ urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; type: dfn;
27
32
text: code entry-point
28
33
text: creation url
29
34
text: document environment
30
- text: entry settings object
31
35
text: environment settings object
32
36
text: event loop
33
37
text: fetch a module script tree
@@ -36,7 +40,9 @@ urlPrefix: https://html.spec.whatwg.org/multipage/webappapis.html; type: dfn;
36
40
text: incumbent settings object
37
41
text: microtask queue
38
42
text: module script
43
+ text: perform the request
39
44
text: realm execution context
45
+ text: relevant settings object
40
46
text: responsible browsing context
41
47
text: responsible document
42
48
text: responsible event loop
@@ -174,16 +180,19 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, for a given |wor
174
180
175
181
4. Associate the |settingsObject| with |workletGlobalScope|.
176
182
177
- 5. For each |resolvedModuleURL | in the given |worklet|'s <a>worklet' s resolved module URLs </a> ,
183
+ 5. For each |entry | in the given |worklet|'s <a>module responses map </a> (in insertion order) ,
178
184
run the following substeps:
179
- 1. Let |script| be the result of <a>fetch a module script tree</a> given
185
+
186
+ 1. Let |resolvedModuleURL| be |entry|'s key.
187
+
188
+ 2. Let |script| be the result of <a>fetch a module script tree</a> given
180
189
|resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a> , and
181
190
|settingsObject|.
182
191
183
192
Note: Worklets follow <a>web workers</a> here in not allowing "use-credientials" for
184
193
fetching resources.
185
194
186
- 2 . <a>Run a module script</a> given |script|.
195
+ 3 . <a>Run a module script</a> given |script|.
187
196
188
197
### Script settings for worklets ### {#script-settings-for-worklets}
189
198
@@ -247,7 +256,7 @@ The {{Worklet}} object provides the capability to import module scripts into its
247
256
248
257
<pre class='idl'>
249
258
interface Worklet {
250
- [NewObject] Promise<void> import(DOMString moduleURL);
259
+ [NewObject] Promise<void> import(USVString moduleURL);
251
260
};
252
261
</pre>
253
262
@@ -259,52 +268,84 @@ Note: As an example the <a>worklet global scope type</a> might be a {{PaintWorkl
259
268
A {{Worklet}} has a list of the <dfn export>worklet's WorkletGlobalScopes</dfn> . Initially this list
260
269
is empty; it is populated when the user agent chooses to create its {{WorkletGlobalScope}} .
261
270
262
- A {{Worklet}} has a list of the <dfn>worklet's resolved module URLs</dfn> . Initially this list is
263
- empty; it is populated when module scripts resolved.
271
+ A {{Worklet}} has a <dfn>module responses map</dfn> . This is a ordered map of module URLs to values
272
+ that are a <a>fetch</a> responses. The map's entries are ordered based on their insertion order.
273
+ Access to this map should be thread-safe.
274
+
275
+ The <a>module responses map</a> exists to ensure that {{WorkletGlobalScope}} s created at different
276
+ times contain the same set of script source text and have the same behaviour. The creation of
277
+ additional {{WorkletGlobalScope}} s should be transparent to the author.
264
278
265
279
When the <dfn method for=Worklet>import(|moduleURL|)</dfn> method is called on a {{Worklet}} object,
266
280
the user agent <em> must</em> run the following steps:
267
281
1. Let |promise| be <a>a new promise</a> .
268
282
269
- 2. Run the following steps <a>in parallel</a> :
270
- 1. Let |resolvedModuleURL| be the result of <a>resolving</a> the |moduleURL| relative to the
271
- <a>API base URL</a> specified by the <a>entry settings object</a> when the method was
272
- invoked.
283
+ 2. Let |resolvedModuleURL| be the result of <a>parsing</a> the |moduleURL| argument relative to
284
+ the <a>relevant settings object</a> of <b> this</b> .
285
+
286
+ 3. If this fails, reject |promise| with a "<a>SyntaxError</a> " <a>DOMException</a> and abort
287
+ these steps.
273
288
274
- 2. If this fails, reject |promise| with a <a>SyntaxError</a> exception and abort these
275
- steps.
289
+ 4. Ensure that there is at least one {{WorkletGlobalScope}} in the <a>worklet's
290
+ WorkletGlobalScopes</a> . If not <a>create a WorkletGlobalScope</a> given the current
291
+ {{Worklet}} .
276
292
277
- 3. Add |resolvedModuleURL| to the list of <a>worklet's resolved module URLs</a> .
293
+ The user-agent may also create additional {{WorkletGlobalScope}} s at this time .
278
294
279
- 4. Ensure that there is at least one {{WorkletGlobalScope}} in the <a>worklet's
280
- WorkletGlobalScopes</a> . If not <a>create a WorkletGlobalScope</a> given the current
281
- {{Worklet}} .
295
+ 5. Let |outsideSettings| be the <a>relevant settings object</a> of <b> this</b> .
282
296
283
- 5. For each {{WorkletGlobalScope}} in the <a>worklet's WorkletGlobalScopes</a> , run these
297
+ 6. Run the following steps <a>in parallel</a> :
298
+
299
+ 1. For each {{WorkletGlobalScope}} in the <a>worklet's WorkletGlobalScopes</a> , run these
284
300
substeps:
285
- 1. Let |settings| be the {{WorkletGlobalScope}} 's associated <a>environment settings
286
- object</a> .
287
301
288
- 2. Let |script| be the result of <a>fetch a module script tree</a> given
289
- |resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a> , and
290
- |settings|.
302
+ 1. Let |insideSettings| be the {{WorkletGlobalScope}} 's associated <a>environment
303
+ settings object</a> .
304
+
305
+ 2. <a>Fetch a module script tree</a> given |resolvedModuleURL|, "omit", the empty string
306
+ (as no cryptographic nonce is present for worklets), "not parser-inserted",
307
+ "script", |outsideSettings|, and |insideSettings|.
308
+
309
+ To <a>perform the request</a> given |request|, perform the following steps:
310
+
311
+ 1. Let |cache| be the current {{Worklet}} 's <a>module responses map</a> .
312
+
313
+ 2. Let |url| be |request|'s <a >url</a> .
314
+
315
+ 3. If |cache| contains an entry with key |url| whose value is "fetching", wait
316
+ (<a>in parallel</a> ) until that entry's value changes, then proceed to the
317
+ next step.
318
+
319
+ 4. If |cache| contains an entry with key |url|, asynchronously complete this
320
+ algorithm with that entry's value, and abort these steps.
321
+
322
+ 5. Create an entry in |cache| with key |url| and value "fetching".
323
+
324
+ 6. <a>Fetch</a> |request|.
325
+
326
+ 7. Let |response| be the result of <a>fetch</a> when it asynchronously
327
+ completes.
328
+
329
+ 8. Set the value of the entry in |cache| whose key is |url| to |response|, and
330
+ asynchronously complete this algorithm with |response|.
291
331
292
- Note: Worklets follow <a>web workers </a> here in not allowing "use-credientials" for
293
- fetching resources .
332
+ 3. Let |script| be the result of <a>fetch a module script tree </a> when it
333
+ asynchronously completes .
294
334
295
- 3 . <a>Run a module script</a> given |script|.
335
+ 4 . <a>Run a module script</a> given |script|.
296
336
297
- 6 . If <em> all</em> the steps above succeeded (in particular, if all of the scripts parsed
337
+ 2 . If <em> all</em> the steps above succeeded (in particular, if all of the scripts parsed
298
338
and loaded into the global scopes), resolve |promise|.
299
339
<br> Otherwise, reject |promise|.
300
340
301
341
Note: Specifically, if a script fails to parse or fails to load over the network, it should
302
342
reject the promise; if the script throws an error while first evaluating the promise
303
343
should resolve as a classes may have been registered correctly.
304
344
305
- 3 . Return |promise|.
345
+ 7 . Return |promise|.
306
346
307
- Issue(w3c/css-houdini-drafts#47): Need ability to load code into {{WorkletGlobalScope}} declaratively.
347
+ Issue(w3c/css-houdini-drafts#47): Need ability to load code into a {{WorkletGlobalScope}}
348
+ declaratively.
308
349
309
350
Lifetime of the Worklet {#lifetime-of-the-worklet}
310
351
--------------------------------------------------
0 commit comments