diff --git a/index.bs b/index.bs index 2f2c6f3b..9b25c343 100644 --- a/index.bs +++ b/index.bs @@ -583,36 +583,40 @@ interface ML { }; -The {{ML/createContext()}} method steps are: -1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, then throw a "{{SecurityError!!exception}}" {{DOMException}} and abort these steps. -1. Let |promise| be [=a new promise=]. -1. Let |context| be a new {{MLContext}} object. -1. Switch on the method's first argument: -
webnn".
Its default allowlist is 'self'.
+### The {{ML/createContext()}} method ### {#api-ml-createcontext}
+The {{ML/createContext()}} method steps are:
+1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, return [=a new promise=] [=rejected=] with a "{{SecurityError}}" {{DOMException}} and abort these steps.
+
+1. Let |promise| be [=a new promise=].
+1. Return |promise| and run the following steps [=in parallel=].
+1. Let |options| be the first argument.
+1. Run the create context steps given |options|:
+ 1. Let |context| be a new {{MLContext}} object.
+ 1. If |options| is a {{GPUDevice}} object,
+ 1. Set |context|.{{[[contextType]]}} to "[=webgpu-context|webgpu=]".
+ 1. Set |context|.{{[[deviceType]]}} to "[=device-type-gpu|gpu=]".
+ 1. Set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]".
+ 1. Otherwise,
+ 1. Set |context|.{{[[contextType]]}} to "[=default-context|default=]".
+ 1. If |options|["{{deviceType}}"] [=map/exists=], then set |context|.{{[[deviceType]]}} to |options|["{{deviceType}}"]. Otherwise, set |context|.{{[[deviceType]]}} to "[=device-type-cpu|cpu=]".
+ 1. If |options|["{{powerPreference}}"] [=map/exists=], then set |context|.{{[[powerPreference]]}} to |options|["{{powerPreference}}"]. Otherwise, set |context|.{{[[powerPreference]]}} to "[=power-preference-default|default=]".
+1. If the validate MLContext steps given |context| return `false`, [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}} and abort these steps.
+1. [=Resolve=] |promise| with |context|.
+
+### The {{ML/createContextSync()}} method ### {#api-ml-createcontextsync}
+The {{ML/createContextSync()}} method steps are:
+1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, throw a "{{SecurityError}}" and abort these steps.
+1. Let |options| be the first argument.
+1. Let |context| be the result of running the create context steps given |options|.
+1. If the validate MLContext steps given |context| return `false`, throw a "{{NotSupportedError}}" {{DOMException}} and abort these steps.
+1. Return |context|.
+
## The MLContext interface ## {#api-mlcontext}
The {{MLContext}} interface represents a global state of neural network compute workload and execution processes. Each {{MLContext}} object has associated [=context type=], [=device type=] and [=power preference=].
@@ -661,15 +665,20 @@ interface MLContext {};
: \[[powerPreference]] of type [=power preference=]
::
The {{MLContext}}'s [=power preference=].
- : \[[implementation]]
- ::
- The underlying implementation provided by the User Agent.