Skip to content

Commit 89bd5f0

Browse files
wacky6tidoust
andauthored
spec: update remaining "in parallel" steps to use tasks (#37)
Update queryHandwritingRecognizer and createHandwritingRecognizer to adopt in parallel algorithm best practices. Co-authored-by: François Daoust <fd@tidoust.net>
1 parent 1588579 commit 89bd5f0

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

spec.bs

+29-18
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,21 @@ The same {{HandwritingModelConstraint}} can be used to invoke {{Navigator/create
191191
<div algorithm="navigator-query-handwriting-recognizer">
192192
When {{Navigator/queryHandwritingRecognizer(constraint)}} method is invoked, do the following:
193193

194-
1. If |constraint| doesn't have a {{HandwritingModelConstraint/languages}} member, [=exception/throw=] a new {{TypeError}}
194+
1. If |constraint| doesn't have a {{HandwritingModelConstraint/languages}} member, return [=a promise rejected with=] a new {{TypeError}}.
195195
1. Let |p| be [=a new promise=].
196-
1. Run the following step [=in parallel=]
197-
1. If |constraint|'s {{HandwritingModelConstraint/languages}} member is an empty array, [=/resolve=] |p| with `null` and abort.
196+
1. Run the following steps [=in parallel=]:
198197
1. <a lt="convert">Convert |constraint| into a suitable form for handwriting recognizer</a>.
199-
1. If the user agent can't find or create a [=handwriting recognizer=] that satisfies the converted |constraint|, [=/resolve=] |p| with `null` and abort.
200-
1. Let |result| be a new {{HandwritingRecognizerQueryResult}}
201-
1. <a lt="convert">Convert the handwriting recognizer's feature description</a>, and fills in all members of |result|,.
202-
1. [=/Resolve=] |p| with |result|.
198+
1. If any of the following is true:
199+
* |constraint|'s {{HandwritingModelConstraint/languages}} member is an empty [=list=].
200+
* The user agent can't find or create a platform-dependent [=handwriting recognizer=] that satisfies the converted |constraint|.
201+
202+
[=Queue a handwriting recognition API task=] to resolve |p| with `null` and abort the remaining steps.
203+
204+
1. Otherwise, [=queue a handwriting recognition API task=] to:
205+
1. Let |result| be a new {{HandwritingRecognizerQueryResult}}
206+
1. <a lt="convert">Convert the handwriting recognizer's feature description</a>, and populate all members of |result|.
207+
1. [=/Resolve=] |p| with |result|.
208+
1. Return |p|.
203209

204210
The implementation should follow these rules when converting to {{HandwritingRecognizerQueryResult}} and {{HandwritingHintsQueryResult}}:
205211
* If the recognizer doesn't accept any hint, set {{HandwritingRecognizerQueryResult/hints}} to `null`.
@@ -317,18 +323,23 @@ This method creates a {{HandwritingRecognizer}} object that satisfies the provid
317323
<div algorithm="navigator-create-handwriting-recognizer">
318324
When {{Navigator/createHandwritingRecognizer(constraint)}} method is invoked, do the following:
319325

320-
1. If |constraint| doesn't have a {{HandwritingModelConstraint/languages}} member, [=exception/throw=] a new {{TypeError}}
326+
1. If |constraint| doesn't have a {{HandwritingModelConstraint/languages}} member, return [=a promise rejected with=] {{TypeError}}.
321327
1. Let |p| be [=a new promise=].
322-
1. Run the following step [=in parallel=]
323-
1. If |constraint|'s {{HandwritingModelConstraint/languages}} is an empty array, [=/reject=] |p| with a new {{DOMException}} whose {{DOMException/name}} attribute is {{"NotSupportedError"}} and abort.
324-
1. <a lt="convert">Convert |constraint| into a suitable form</a> for [=handwriting recognizer=].
325-
1. If the user agent can't find a [=handwriting recognizer=] that satisfies the converted |constraint|, [=/reject=] |p| with a new {{DOMException}} whose {{DOMException/name}} attribute is {{"NotSupportedError"}} and abort.
326-
1. If creating a [=handwriting recognizer=] would cause the user agent to exceed its limit for total number of active recognizer, [=/reject=] |p| with a new {{DOMException}} whose {{DOMException/name}} attribute is {{"QuotaExceededError"}}.
327-
1. If the user agent can't prepare [=handwriting recognizer=] to perform recognitions, [=/reject=] |p| with a new {{DOMException}} object whose name depending on the failure cause and abort:
328-
* If the web application shouldn't retry, {{"OperationError"}}.
329-
* Otherwise {{"UnknownError"}}.
330-
1. Let |result| be a new {{HandwritingRecognizer}} object, whose [=HandwritingRecognizer/active=] flag is `true`
331-
1. [=/Resolve=] |p| with |result|.
328+
1. Run the following steps [=in parallel=]:
329+
1. <a lt="convert">Convert |constraint| into a suitable form</a> for creating a platform-dependent [=handwriting recognizer=].
330+
1. [=Queue a Handwriting Recognition API task=] to:
331+
1. If the user agent can't create or prepare a [=handwriting recognizer=] to perform recognitions, [=/reject=] |p| with a new {{DOMException}} according to the failure cause:
332+
* If |constraint|'s {{HandwritingModelConstraint/languages}} is an empty [=list=], {{"NotSupportedError"}}.
333+
* If the user agent can't find a platform-dependent [=handwriting recognizer=] that satisfies the converted |constraint|, {{"NotSupportedError"}}.
334+
* If creating a [=handwriting recognizer=] would cause the user agent to exceed its limit for total number of active recognizer, {{"QuotaExceededError"}}.
335+
* If the web application can retry calling this method, {{OperationError}}.
336+
* For all other failure causes, {{"UnknownError"}}
337+
1. Otherwise:
338+
1. Let |result| be a new {{HandwritingRecognizer}} object.
339+
1. Associate |result| with the platform-dependent [=handwriting recognizer=] created in the previous step.
340+
1. Set |result|.[=HandwritingRecognizer/active=] flag to `true`.
341+
1. [=/Resolve=] |p| with |result|.
342+
1. Return |p|
332343
</div>
333344

334345
<h2 id="using-a-recognizer">Use a recognizer</h2>

0 commit comments

Comments
 (0)