Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure object creation specifies the realm #810

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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