From ec421574dade5e631ba9cb702ca071b52f026619 Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Tue, 28 Jan 2025 20:35:23 -0800 Subject: [PATCH] Ensure object creation specifies the realm (#810) * 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 --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index fb3c1f55..0696b09d 100644 --- a/index.bs +++ b/index.bs @@ -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]