Skip to content

Commit 1340ce3

Browse files
committed
[worklets] Fix up worklets <dfn>'s, add example for invoking a method
prose. Change prose about lifetime of WorkletGlobalScopes.
1 parent 0a49c4f commit 1340ce3

File tree

1 file changed

+72
-53
lines changed

1 file changed

+72
-53
lines changed

worklets/Overview.bs

+72-53
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ Worklets are similar to <a>web workers</a> however they:
8888
- Are not event API based. Instead classes are registered on the global scope, whose methods are to
8989
be invoked by the user agent.
9090
- 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.
9293

9394
As worklets have a relatively high overhead, they should be used sparingly. Due to this worklets are
9495
expected to be shared between separate scripts. This is similar to the <a>document environment</a>.
@@ -134,8 +135,7 @@ interface WorkletGlobalScope {
134135
};
135136
</pre>
136137

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>.
139139

140140
Note:
141141
The {{WorkletGlobalScope}} has a limited global scope when compared to a
@@ -155,7 +155,7 @@ WorkletGlobalScope</a> algorithm.
155155
When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, for a given |worklet|, it
156156
<em>must</em> run the following steps:
157157

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>.
159159

160160
2. Call the JavaScript <a>InitializeHostDefinedRealm</a> abstract operation with the following
161161
customizations:
@@ -172,7 +172,7 @@ When a user agent is to <dfn>create a WorkletGlobalScope</dfn>, for a given |wor
172172

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

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>,
176176
run the following substeps:
177177
1. Let |script| be the result of <a>fetch a module script tree</a> given
178178
|resolvedModuleURL|, "anonymous" for the <a>CORS setting attribute</a>, and
@@ -249,77 +249,79 @@ interface Worklet {
249249
};
250250
</pre>
251251

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
253253
{{WorkletGlobalScope}} and the type must <a>inherit</a> from {{WorkletGlobalScope}}.
254254

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}}.
256256

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}}.
259259

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.
262262

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,
264264
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>.
266266

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.
269269

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.
273273

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.
275276

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>.
277278

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}}.
281282

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>.
286287

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|.
289291

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.
292294

293-
3. <a>Run a module script</a> given |script|.
295+
3. <a>Run a module script</a> given |script|.
294296

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|.
298300

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.
300304

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|.
302306

303307
Issue(w3c/css-houdini-drafts#47): Need ability to load code into {{WorkletGlobalScope}} declaratively.
304308

305-
Issue: TODO write initialization for Worklet.
306-
307309
Lifetime of the Worklet {#lifetime-of-the-worklet}
308310
--------------------------------------------------
309311

310312
The lifetime of a {{Worklet}} is tied to the object it belongs to, for example the {{Window}}.
311313

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}}.
314316

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.
318320

319-
Issue(w3c/css-houdini-drafts#53): Worth adding dispose to classes to allow clean-up?
321+
Security Considerations {#security-considerations}
322+
==================================================
320323

321-
Processing Model {#processing-model}
322-
------------------------------------
324+
Issue(w3c/css-houdini-drafts#92): Need to decide if to allow worklets for unsecure context, etc.
323325

324326
Examples {#examples}
325327
====================
@@ -343,11 +345,11 @@ interface FakeWorkletGlobalScope : WorkletGlobalScope {
343345
};
344346
</pre>
345347

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>.
350349

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>.
351353

352354
Loading scripts into a worklet. {#example-single}
353355
-------------------------------------------------
@@ -378,11 +380,28 @@ Create a registered class and invoke a method. {#example-class}
378380

379381
<pre class='lang-javascript'>
380382
// Inside FakeWorkletGlobalScope
381-
registerAnArbitaryClass('foo', class FooClass {
383+
registerAnArbitaryClass('key', class FooClass {
382384
process(arg) {
383385
return !arg;
384386
}
385387
});
386388
</pre>
387389

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

Comments
 (0)