Skip to content

Commit

Permalink
Don't double-init realm; and don't need realm for dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Jan 29, 2025
1 parent 1f72cca commit aa9b161
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 1 addition & 4 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ The <dfn dfn-for=MLContextOptions dfn-type=dict-member>powerPreference</dfn> opt
1. Let |global| be [=this=]'s [=relevant global object=].
1. Let |realm| be [=this=]'s [=relevant realm=].
1. If |global|'s [=associated Document=] is not [=allowed to use=] the [=webnn-feature|webnn=] feature, return [=a new promise=] in |realm| [=rejected=] with a "{{SecurityError}}" {{DOMException}}.
1. Let |realm| be [=this=]'s [=relevant realm=].
1. Let |promise| be [=a new promise=] in |realm|.
1. Run the following steps [=in parallel=].
1. Let |context| be the result of [=creating a context=] given |realm| and |options|. If that returns failure, then [=queue an ML task=] with |global| to [=reject=] |promise| with a "{{NotSupportedError}}" {{DOMException}} and abort these steps.
Expand Down Expand Up @@ -1282,8 +1281,7 @@ The <dfn>context lost</dfn> steps for {{MLContext}} |context|, are:
<summary>
To <dfn for=MLContext>lose</dfn> {{MLContext}} |context| with {{DOMString}} |message|:
</summary>
1. Let |realm| be |context|'s [=relevant realm=].
1. Let |info| be a new {{MLContextLostInfo}} in |realm|.
1. Let |info| be a new {{MLContextLostInfo}}.
1. Set |info|.{{MLContextLostInfo/message}} to |message|.
1. [=Resolve=] |context|.{{MLContext/[[lost]]}} with |info|.
1. For each {{MLGraph}} |graph| where |graph|.{{MLGraph/[[context]]}} equals [=this=]:
Expand Down Expand Up @@ -1823,7 +1821,6 @@ Build a composed graph up to a given output operand into a computational graph a
1. [=list/For each=] |input| of |operand|.{{MLOperand/[[operator]]}}'s [=operator/inputs=]:
1. [=queue/Enqueue=] |input| to |queue|.
1. Let |global| be [=this=]'s [=relevant global object=].
1. Let |realm| be [=this=]'s [=relevant realm=].
1. Let |graph| be a new {{MLGraph}} in |realm|.
1. Set |graph|.{{MLGraph/[[context]]}} to [=this=].{{MLGraphBuilder/[[context]]}}.
1. Set |graph|.{{MLGraph/[[isDestroyed]]}} to false.
Expand Down
5 changes: 4 additions & 1 deletion tools/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,17 @@ for (const match of source.matchAll(/\|(\w+)\|\.{{(\w+)\/.*?}}/g)) {
});
}

// TODO: Generate this from the IDL itself.
const dictionaries = ['MLOperandDescriptor', 'MLContextLostInfo'];

// Ensure JS objects are created with explicit realm
for (const match of text.matchAll(/ a new promise\b(?! in realm)/g)) {
error(`Promise creation must specify realm: ${format(match)}`);
}
for (const match of text.matchAll(/ be a new ([A-Z]\w+)\b(?! in realm)/g)) {
const type = match[1];
// Dictionaries are just maps, so they don't need a realm.
if (type === 'MLOperandDescriptor')
if (dictionaries.includes(type))
continue;
error(`Object creation must specify realm: ${format(match)}`);
}
Expand Down

0 comments on commit aa9b161

Please sign in to comment.