Skip to content

Commit

Permalink
Ensure object creation specifies the realm (#810)
Browse files Browse the repository at this point in the history
* Ensure object creation specifies the realm

"Realm" is an ECMAScript concept best explained in
https://html.spec.whatwg.org/multipage/webappapis.html#realms-and-their-counterparts
Newly created JS objects must be associated with a Realm; while older
specs didn't do this explicitly, best practice is to be explicit about
this, especially for steps running "in parallel", or in algorithms
separate from method steps. Do so!

This also adds lint tests to try and catch future violations. Note
that dictionaries (e.g. MLOperatorDescriptor) are Infra "ordered maps"
it the body of spec algorithms, not JS objects, so they don't have a
realm. Conversion to a JS object when returning a dictionary to script
is handled by WebIDL bindings logic.

Also note that DOMExceptions, either thrown or as promise rejection
values, are not given a realm. This is a known issue across all web
specs and is tracked in whatwg/webidl#135.

Resolves #793.

* Don't double-init realm; and don't need realm for dicts

* Variable name improvement from @fdwr
  • Loading branch information
inexorabletash authored and zolkis committed Feb 6, 2025
1 parent 74b5ae5 commit 94bd729
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ Note: `dispatch()` itself provides no signal that graph execution has completed.
'C': outputTensorC
};
context.dispatch(graph, inputs, outputs);

// 6. Read back the computed result.
const result = await context.readTensor(outputTensorC);
console.log('Output value:', new Float32Array(result)); // [1, 1, 1, 1]
Expand Down

0 comments on commit 94bd729

Please sign in to comment.