Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Commit 2626450

Browse files
authored
Use webidl algorithms for construction and invocation (#104)
We resolved to continue using the "cache" props approach [here](w3c/css-houdini-drafts#743 (comment)) but we still need to be consistent in using webidl algorithms for invoking and construction operation. The following changes fix this: - Use VoidFunction type for constructor, and Function type for animate and destroy callbacks - Use convert algorithm to convert incoming values to proper types upon registration - Use invoke/construct algorithms to call or construct. This ensure the proper setup in place which addresses the original reported issue. Fixes #94
1 parent 98f3282 commit 2626450

File tree

2 files changed

+109
-77
lines changed

2 files changed

+109
-77
lines changed

index.bs

+43-32
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ urlPrefix: https://heycam.github.io/webidl/; type: dfn;
2626
text: exception
2727
text: throw
2828
url: throw; text: thrown
29-
url: es-invoking-callback-functions; text: Invoke
29+
urlPrefix: #;
30+
url: Function; text: Function
31+
url: VoidFunction; text: VoidFunction
32+
url: invoke-a-callback-function; text: Invoke
33+
url: construct-a-callback-function; text: constructing
34+
url: es-type-mapping; text: converting
3035
urlPrefix: https://html.spec.whatwg.org/#; type: dfn;
3136
url: run-the-animation-frame-callbacks; text: running the animation frame callbacks
3237
urlPrefix: http://w3c.github.io/html/infrastructure.html#; type: dfn;
@@ -62,16 +67,13 @@ urlPrefix: https://w3c.github.io/web-animations/level-2/#;
6267
text: group effect
6368
text: child effect
6469
urlPrefix: https://tc39.github.io/ecma262/#sec-; type: dfn;
65-
text: constructor
66-
text: Construct
6770
text: IsCallable
6871
text: IsConstructor
6972
text: HasProperty
7073
url: ecmascript-data-types-and-values; text: Type
7174
url: map-objects; text:map object
7275
url: get-o-p; text: Get
7376
url: set-o-p-v-throw; text: Set
74-
url: terms-and-definitions-function; text: function
7577
urlPrefix: native-error-types-used-in-this-standard-
7678
text: TypeError
7779
urlPrefix: https://www.w3.org/TR/hr-time-2/#dom-; type: dfn
@@ -178,8 +180,6 @@ partial namespace CSS {
178180
</xmp>
179181

180182
<xmp class='idl'>
181-
callback VoidFunction = void ();
182-
183183
[ Exposed=AnimationWorklet, Global=AnimationWorklet ]
184184
interface AnimationWorkletGlobalScope : WorkletGlobalScope {
185185
void registerAnimator(DOMString name, VoidFunction animatorCtor);
@@ -210,19 +210,21 @@ animation as needed by {{AnimationWorkletGlobalScope}}. It consists of:
210210

211211
- An <dfn>animator name</dfn> <<ident>>#.
212212

213-
- A <dfn>class constructor</dfn> which is the class <a>constructor</a>.
213+
- A <dfn>class constructor</dfn> which is a <a>VoidFunction</a> <a>callback function</a> type.
214+
215+
- An <dfn>animate function</dfn> which is a <a>Function</a> <a>callback function</a> type.
214216

215-
- An <dfn>animate function</dfn> which is the animate <a>function</a> callback.
217+
- A <dfn>destroy function</dfn> which is a <a>Function</a> <a>callback function</a> type.
216218

217219

218220
Registering an Animator Definition {#registering-animator-definition}
219221
-------------------------------------
220222
An {{AnimationWorkletGlobalScope}} has a <dfn>animator name to animator definition map</dfn>.
221-
The map gets populated when {{registerAnimator(name, animatorCtor)}} is called.
223+
The map gets populated when {{registerAnimator(name, animatorCtorValue)}} is called.
222224

223225
<div algorithm="register-animator">
224226

225-
When the <dfn method for=AnimationWorkletGlobalScope>registerAnimator(|name|, |animatorCtor|)</dfn>
227+
When the <dfn method for=AnimationWorkletGlobalScope>registerAnimator(|name|, |animatorCtorValue|)</dfn>
226228
method is called in a {{AnimationWorkletGlobalScope}}, the user agent <em>must</em> run the
227229
following steps:
228230

@@ -232,28 +234,43 @@ following steps:
232234
2. If |name| exists as a key in the <a>animator name to animator definition map</a>,
233235
<a>throw</a> a <a>NotSupportedError</a> and abort all these steps.
234236

235-
3. If the result of <a>IsConstructor</a>(|animatorCtor|) is false, <a>throw</a> a
237+
3. If the result of <a>IsConstructor</a>(|animatorCtorValue|) is false, <a>throw</a> a
236238
<a>TypeError</a> and abort all these steps.
237239

238-
4. Let |prototype| be the result of <a>Get</a>(|animatorCtor|, "prototype").
240+
4. Let |animatorCtor| be the result of <a>converting</a> animatorCtorValue to the
241+
<a>VoidFunction</a> <a>callback function</a> type. If an exception is thrown, rethrow the
242+
exception and abort all these steps.
243+
244+
4. Let |prototype| be the result of <a>Get</a>(|animatorCtorValue|, "prototype").
239245

240246
5. If the result of <a>Type</a>(|prototype|) is not Object, <a>throw</a> a <a>TypeError</a>
241247
and abort all these steps.
242248

243-
6. Let |animate| be the result of <a>Get</a>(|prototype|, "animate").
249+
6. Let |animateValue| be the result of <a>Get</a>(|prototype|, "animate").
250+
251+
7. Let |animate| be the result of <a>converting</a> |animateValue| to the <a>Function</a>
252+
<a>callback function</a> type. If an exception is thrown, rethrow the exception and abort
253+
all these steps.
244254

245-
7. If the result of <a>IsCallable</a>(|animate|) is false, <a>throw</a> a <a>TypeError</a> and
246-
abort all these steps.
255+
8. Let |destroyValue| be the result of <a>Get</a>(|prototype|, "onDestroy").
247256

248-
10. Let |definition| be a new <a>animator definition</a> with:
257+
9. Let |destroy| be the result of <a>converting</a> |destroyValue| to the <a>Function</a>
258+
<a>callback function</a> type. If an exception is thrown, rethrow the exception and abort
259+
all these steps.
260+
261+
262+
8. Let |definition| be a new <a>animator definition</a> with:
249263

250264
- <a>animator name</a> being |name|
251265

252266
- <a>class constructor</a> being |animatorCtor|
253267

254268
- <a>animate function</a> being |animate|
255269

256-
11. Add the key-value pair (|name| - |definition|) to the <a>animator name to animator
270+
- <a>destroy function</a> being |destroy|
271+
272+
273+
9. Add the key-value pair (|name| - |definition|) to the <a>animator name to animator
257274
definition map</a>.
258275
</div>
259276

@@ -308,10 +325,9 @@ To <dfn>create a new animator instance</dfn> given a |name|, |timeline|, |effect
308325

309326
5. Let |state| be <a>StructuredDeserialize</a>(|serializedState|).
310327

311-
6. Let |animatorInstance| be the result of <a>Construct</a>(|animatorCtor|, [|options|, |state|]).
312-
313-
If <a>Construct</a> throws an exception, abort the following steps.
314-
328+
6. Let |animatorInstance| be the result of <a>constructing</a> |animatorCtor| with
329+
[|options|, |state| as args. If an exception is thrown, rethrow the exception and abort all
330+
these steps.
315331

316332
7. Set the following on |animatorInstance| with:
317333
- <a>animator name</a> being |name|
@@ -410,22 +426,17 @@ To <dfn>migrate an animator instance</dfn> from one {{WorkletGlobalScope}} to an
410426

411427
If |definition| does not exist then abort the following steps.
412428

413-
3. Let |animatorCtor| be the <a>class constructor</a> of |definition|.
429+
3. Let |destroyFunction| be the <a>destroy function</a> of |definition|.
414430

415-
4. Let |prototype| be the result of <a>Get</a>(|animatorCtor|, "prototype").
416-
417-
5. Let |onDestroyFunction| be the result of <a>Get</a>(|prototype|, "onDestroy").
418-
419-
6. If the result of <a>IsCallable</a>(|onDestroyFunction|) is false then abort the following
420-
steps.
421431

422-
7. <a>Invoke</a> |onDestroyFunction| with |instance| as the <a>callback this value</a> and let
423-
|state| be the result of the invocation.
432+
4. <a>Invoke</a> |destroyFunction| with |instance| as the <a>callback this value</a> and
433+
let |state| be the result of the invocation. If any exception is thrown, rethrow the
434+
exception and abort the following steps.
424435

425-
8. Set |serializedState| to be the result of <a>StructuredSerialize</a>(|state|).
436+
5. Set |serializedState| to be the result of <a>StructuredSerialize</a>(|state|).
426437
If any exception is thrown, then abort the following steps.
427438

428-
9. Run the procedure to <a>remove an animator instance</a> given |instance|, and
439+
6. Run the procedure to <a>remove an animator instance</a> given |instance|, and
429440
|sourceWorkletGlobalScope|.
430441

431442
2. Wait for the above task to complete. If the task is aborted, abort the following steps.

0 commit comments

Comments
 (0)