@@ -88,7 +88,8 @@ Worklets are similar to <a>web workers</a> however they:
88
88
- Are not event API based. Instead classes are registered on the global scope, whose methods are to
89
89
be invoked by the user agent.
90
90
- Have a reduced API surface on the <a>javascript global environment</a> (global scope).
91
- - Have a lifetime tied to running a method or set of methods on a class.
91
+ - Have a lifetime for the global scope which is defined by subsequent specifications or user
92
+ agents. They aren't tied to the lifetime of the document.
92
93
93
94
As worklets have a relatively high overhead, they should be used sparingly. Due to this worklets are
94
95
expected to be shared between separate scripts. This is similar to the <a>document environment</a> .
@@ -134,8 +135,7 @@ interface WorkletGlobalScope {
134
135
};
135
136
</pre>
136
137
137
- A {{WorkletGlobalScope}} has an associated <a>environment settings object</a>
138
- <b> settings object</b> .
138
+ A {{WorkletGlobalScope}} has an associated <a>environment settings object</a> .
139
139
140
140
Note:
141
141
The {{WorkletGlobalScope}} has a limited global scope when compared to a
@@ -155,7 +155,7 @@ WorkletGlobalScope</a> algorithm.
155
155
When a user agent is to <dfn>create a WorkletGlobalScope</dfn> , for a given |worklet|, it
156
156
<em> must</em> run the following steps:
157
157
158
- 1. Let |workletGlobalScopeType| be the |worklet|'s <b > worklet global scope type</b > .
158
+ 1. Let |workletGlobalScopeType| be the |worklet|'s <a >worklet global scope type</a > .
159
159
160
160
2. Call the JavaScript <a>InitializeHostDefinedRealm</a> abstract operation with the following
161
161
customizations:
@@ -172,7 +172,7 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, for a given |wor
172
172
173
173
4. Associate the |settingsObject| with |workletGlobalScope|.
174
174
175
- 5. For each |resolvedModuleURL| in the given |worklet|'s <b >worklet' s resolved module URLs</b > ,
175
+ 5. For each |resolvedModuleURL| in the given |worklet|'s <a >worklet' s resolved module URLs</a > ,
176
176
run the following substeps:
177
177
1. Let |script| be the result of <a>fetch a module script tree</a> given
178
178
|resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a> , and
@@ -249,77 +249,79 @@ interface Worklet {
249
249
};
250
250
</pre>
251
251
252
- A {{Worklet}} has a <b > worklet global scope type</b > . This is used for creating new
252
+ A {{Worklet}} has a <dfn export >worklet global scope type</dfn > . This is used for creating new
253
253
{{WorkletGlobalScope}} and the type must <a>inherit</a> from {{WorkletGlobalScope}} .
254
254
255
- Note: As an example the <b > worklet global scope type</b > might be a {{PaintWorkletGlobalScope}} .
255
+ Note: As an example the <a >worklet global scope type</a > might be a {{PaintWorkletGlobalScope}} .
256
256
257
- A {{Worklet}} has a list of the <b > worklet's WorkletGlobalScopes</b > . Initially this list is empty;
258
- it is populated when the user agent chooses to create its {{WorkletGlobalScope}} .
257
+ A {{Worklet}} has a list of the <dfn export >worklet's WorkletGlobalScopes</dfn > . Initially this list
258
+ is empty; it is populated when the user agent chooses to create its {{WorkletGlobalScope}} .
259
259
260
- A {{Worklet}} has a list of the <b > worklet's resolved module URLs</b > . Initially this list is empty; it is
261
- populated when module scripts resolved.
260
+ A {{Worklet}} has a list of the <dfn >worklet's resolved module URLs</dfn > . Initially this list is
261
+ empty; it is populated when module scripts resolved.
262
262
263
- When the <dfn method for=Worklet>import(moduleURL)</dfn> method is called on a {{Worklet}} object,
263
+ When the <dfn method for=Worklet>import(| moduleURL| )</dfn> method is called on a {{Worklet}} object,
264
264
the user agent <em> must</em> run the following steps:
265
- 1. Let |promise| be <a>a new promise</a> .
265
+ 1. Let |promise| be <a>a new promise</a> .
266
266
267
- 2. Run the following steps <a>in parallel</a> :
268
- 1. If there are no arguments, return without doing anything. Abort these steps.
267
+ 2. Run the following steps <a>in parallel</a> :
268
+ 1. If there are no arguments, return without doing anything. Abort these steps.
269
269
270
- 2. 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.
270
+ 2. 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.
273
273
274
- 3. If this fails, reject |promise| with a <a>SyntaxError</a> exception and abort these steps.
274
+ 3. If this fails, reject |promise| with a <a>SyntaxError</a> exception and abort these
275
+ steps.
275
276
276
- 4. Add |resolvedModuleURL| to the list of <b > worklet's resolved module URLs</b > .
277
+ 4. Add |resolvedModuleURL| to the list of <a >worklet's resolved module URLs</a > .
277
278
278
- 5. Ensure that there is at least one {{WorkletGlobalScope}} in the <b > worklet's
279
- WorkletGlobalScopes</b > . If not <a>create a WorkletGlobalScope</a> given the current
280
- {{Worklet}} .
279
+ 5. 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}} .
281
282
282
- 6. For each {{WorkletGlobalScope}} in the <b > worklet's WorkletGlobalScopes</b > , run these
283
- substeps:
284
- 1. Let |settings| be the {{WorkletGlobalScope}} 's associated
285
- <a>environment settings object</a> .
283
+ 6. For each {{WorkletGlobalScope}} in the <a >worklet's WorkletGlobalScopes</a > , run these
284
+ substeps:
285
+ 1. Let |settings| be the {{WorkletGlobalScope}} 's associated <a>environment settings
286
+ object</a> .
286
287
287
- 2. Let |script| be the result of <a>fetch a module script tree</a> given
288
- |resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a> , and |settings|.
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|.
289
291
290
- Note: Worklets follow <a>web workers</a> here in not allowing "use-credientials" for
291
- fetching resources.
292
+ Note: Worklets follow <a>web workers</a> here in not allowing "use-credientials" for
293
+ fetching resources.
292
294
293
- 3. <a>Run a module script</a> given |script|.
295
+ 3. <a>Run a module script</a> given |script|.
294
296
295
- 7. If <em> all</em> the steps above succeeded (in particular, if all of the scripts parsed and
296
- loaded into the global scopes), resolve |promise|
297
- <br> Otherwise, reject |promise|.
297
+ 7. If <em> all</em> the steps above succeeded (in particular, if all of the scripts parsed
298
+ and loaded into the global scopes), resolve |promise|.
299
+ <br> Otherwise, reject |promise|.
298
300
299
- 3. Return |promise|.
301
+ Note: Specifically, if a script fails to parse or fails to load over the network, it should
302
+ reject the promise; if the script throws an error while first evaluating the promise
303
+ should resolve as a classes may have been registered correctly.
300
304
301
- Issue(w3c/css-houdini-drafts#51): What should happen when a script throws an exception while executing for the first time?
305
+ 3. Return |promise|.
302
306
303
307
Issue(w3c/css-houdini-drafts#47): Need ability to load code into {{WorkletGlobalScope}} declaratively.
304
308
305
- Issue: TODO write initialization for Worklet.
306
-
307
309
Lifetime of the Worklet {#lifetime-of-the-worklet}
308
310
--------------------------------------------------
309
311
310
312
The lifetime of a {{Worklet}} is tied to the object it belongs to, for example the {{Window}} .
311
313
312
- The lifetime of a {{WorkletGlobalScope}} is tied to the execution lifetime of a method or set of
313
- methods on a class, not to the lifetime of the {{Worklet}} object .
314
+ The lifetime of a {{WorkletGlobalScope}} should be defined by subsequent specifications which
315
+ inherit from {{WorkletGlobalScope}} .
314
316
315
- The user agent <em> may</em> terminate a {{WorkletGlobalScope}} at any time it has no callbacks to
316
- handle or detects abnormal operation such as infinite loops and callbacks exceeding imposed time
317
- limits.
317
+ Subsequent specifications <em> may</em> define that a {{WorkletGlobalScope}} can be terminated at any
318
+ time particularly if there are no pending operations, or detects abnormal operation such as infinite
319
+ loops and callbacks exceeding imposed time limits.
318
320
319
- Issue(w3c/css-houdini-drafts#53): Worth adding dispose to classes to allow clean-up?
321
+ Security Considerations {#security-considerations}
322
+ ==================================================
320
323
321
- Processing Model {#processing-model}
322
- ------------------------------------
324
+ Issue(w3c/css-houdini-drafts#92): Need to decide if to allow worklets for unsecure context, etc.
323
325
324
326
Examples {#examples}
325
327
====================
@@ -343,11 +345,11 @@ interface FakeWorkletGlobalScope : WorkletGlobalScope {
343
345
};
344
346
</pre>
345
347
346
- Each {{FakeWorkletGlobalScope}} has a map of the <b> registered class constructors</b> .
347
-
348
- When the <dfn method for=FakeWorkletGlobalScope>registerAnArbitaryClass(type, classConstructor)</dfn> method is called,
349
- the user agent will add the <em> classConstructor</em> of <em> type</em> to the map of <b> registered class constructors</b> .
348
+ Each {{FakeWorkletGlobalScope}} has a map of the <dfn>registered class constructors map</dfn> .
350
349
350
+ When the <dfn method for=FakeWorkletGlobalScope>
351
+ registerAnArbitaryClass(|type|, |classConstructor|)</dfn> method is called, the user agent will add
352
+ the |classConstructor| of |type| to the map of <a>registered class constructors map</a> .
351
353
352
354
Loading scripts into a worklet. {#example-single}
353
355
-------------------------------------------------
@@ -378,11 +380,28 @@ Create a registered class and invoke a method. {#example-class}
378
380
379
381
<pre class='lang-javascript'>
380
382
// Inside FakeWorkletGlobalScope
381
- registerAnArbitaryClass('foo ' , class FooClass {
383
+ registerAnArbitaryClass('key ' , class FooClass {
382
384
process(arg) {
383
385
return !arg;
384
386
}
385
387
});
386
388
</pre>
387
389
388
- Issue: Add example prose for invoking "process".
390
+ As an example, if the user agent wants to invoke "process" on a new class instance, the user agent
391
+ could follow the following steps:
392
+ 1. Let |workletGlobalScope| be a {{FakeWorkletGlobalScope}} from the list of <a>worklet's
393
+ WorkletGlobalScopes</a> from the fake {{Worklet}} .
394
+
395
+ The user agent <em> may</em> also <a>create a WorkletGlobalScope</a> given the fake
396
+ {{Worklet}} and use that.
397
+
398
+ 2. Let |classCtor| be the result of performing a lookup in <a>registered class constructors
399
+ map</a> with "key" as the key.
400
+
401
+ 3. Let |classInstance| be the result of <a>Construct</a> (|classCtor|).
402
+
403
+ 4. Let |result| be the result of <a>Invoke</a> (O=|classInstance|, P="process",
404
+ Arguments=["true"] ).
405
+
406
+ 5. Return |result|.
407
+
0 commit comments