From 4202c3ea807b9b67a5c471dc63763da99bf1b2ac Mon Sep 17 00:00:00 2001 From: DJ Date: Mon, 12 Oct 2026 15:13:51 +0900 Subject: [PATCH 1/2] [js-api] Fix `AddressValueToU64`'s type errors --- document/js-api/index.bs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 64dfd22f77..4d41639d0c 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -256,6 +256,7 @@ urlPrefix: https://webidl.spec.whatwg.org/; spec: WebIDL text: [EnforceRange]; url: #EnforceRange text: unsigned long; url: #idl-unsigned-long text: js-unsigned-long; url: #js-unsigned-long + text: converted to a JavaScript value; url: #dfn-convert-idl-to-javascript-value urlPrefix: https://webassembly.github.io/js-types/js-api/; spec: WebAssembly JS API (JS Type Reflection) type: abstract-op; text: FromValueType; url: abstract-opdef-fromvaluetype urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal @@ -1487,16 +1488,17 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va
-The algorithm AddressValueToU64(|v|, |addrtype|) converts a JavaScript value to a WebAssembly [=u64=] for use in embedding operations. It is designed to act like [=[EnforceRange]=] [=unsigned long=] for {{AddressType}} "i32", and to extend these semantics to {{AddressType}} "i64", by performing the following steps: +The algorithm AddressValueToU64(|v|, |addrtype|) converts an IDL value to a WebAssembly [=u64=] for use in embedding operations. It is designed to act like [=[EnforceRange]=] [=unsigned long=] for {{AddressType}} "i32", and to extend these semantics to {{AddressType}} "i64", by performing the following steps: +1. Let |V| be |v|, [=converted to a JavaScript value=]. 1. If |addrtype| is [=i32=], - 1. Let |n| be [=?=] [$ConvertToInt$](|v|, 32, "unsigned"), where the destination type is associated with [=[EnforceRange]=]. + 1. Let |n| be [=?=] [$ConvertToInt$](|V|, 32, "unsigned"), where the destination type is associated with [=[EnforceRange]=]. Note: This is equivalent to the [=js-unsigned-long|JS conversion rules=] for [=[EnforceRange]=] [=unsigned long=]. 1. Return [=ℝ=](|n|) as a WebAssembly [=u64=]. 1. If |addrtype| is [=i64=], - 1. Let |n| be [=?=] [$ToBigInt$](|v|). - 1. If |n| < 0 or |n| > 264 − 1, [=throw=] a {{TypeError}}. + 1. Let |n| be [=?=] [$ToBigInt$](|V|). + 1. If [=ℝ=](|n|) < 0 or [=ℝ=](|n|) > 264 − 1, [=throw=] a {{TypeError}}. Note: This operation is designed to emulate [=[EnforceRange]=]. 1. Return [=ℝ=](|n|) as a WebAssembly [=u64=]. From 11f8bf974bca34594734c7b84d24047eb91ad251 Mon Sep 17 00:00:00 2001 From: DJ Date: Tue, 13 Oct 2026 19:49:23 +0900 Subject: [PATCH 2/2] Address review feedback on AddressValueToU64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename V to jsValue, add a note explaining the any-to-JS-value conversion, and bind ℝ(n) once instead of three times. --- document/js-api/index.bs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 4d41639d0c..11f3ecea06 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1490,18 +1490,21 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va
The algorithm AddressValueToU64(|v|, |addrtype|) converts an IDL value to a WebAssembly [=u64=] for use in embedding operations. It is designed to act like [=[EnforceRange]=] [=unsigned long=] for {{AddressType}} "i32", and to extend these semantics to {{AddressType}} "i64", by performing the following steps: -1. Let |V| be |v|, [=converted to a JavaScript value=]. +1. Let |jsValue| be |v|, [=converted to a JavaScript value=]. + + Note: The IDL `any` type is a discriminated union, not a transparent wrapper around a JavaScript value. 1. If |addrtype| is [=i32=], - 1. Let |n| be [=?=] [$ConvertToInt$](|V|, 32, "unsigned"), where the destination type is associated with [=[EnforceRange]=]. + 1. Let |n| be [=?=] [$ConvertToInt$](|jsValue|, 32, "unsigned"), where the destination type is associated with [=[EnforceRange]=]. Note: This is equivalent to the [=js-unsigned-long|JS conversion rules=] for [=[EnforceRange]=] [=unsigned long=]. 1. Return [=ℝ=](|n|) as a WebAssembly [=u64=]. 1. If |addrtype| is [=i64=], - 1. Let |n| be [=?=] [$ToBigInt$](|V|). - 1. If [=ℝ=](|n|) < 0 or [=ℝ=](|n|) > 264 − 1, [=throw=] a {{TypeError}}. + 1. Let |n| be [=?=] [$ToBigInt$](|jsValue|). + 1. Let |r| be [=ℝ=](|n|). + 1. If |r| < 0 or |r| > 264 − 1, [=throw=] a {{TypeError}}. Note: This operation is designed to emulate [=[EnforceRange]=]. - 1. Return [=ℝ=](|n|) as a WebAssembly [=u64=]. + 1. Return |r| as a WebAssembly [=u64=]. 1. Assert: This step is not reached.