Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit c157e61

Browse files
authored
Rework IndexValueToU64 to allow more inputs to BigInts (#86)
* Rework IndexValueToU64 to allow more inputs to BigInts * Address #86 feedback
1 parent 615bd1f commit c157e61

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

document/js-api/index.bs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL
208208
type: dfn
209209
text: create a namespace object; url: create-a-namespace-object
210210
text: [EnforceRange]; url: #EnforceRange
211+
text: unsigned long; url: #idl-unsigned-long
212+
text: js-unsigned-long; url: #js-unsigned-long
211213
urlPrefix: https://webassembly.github.io/js-types/js-api/; spec: WebAssembly JS API (JS Type Reflection)
212214
type: abstract-op; text: FromValueType; url: abstract-opdef-fromvaluetype
213215
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal
@@ -569,7 +571,7 @@ enum IndexType {
569571
"i64",
570572
};
571573

572-
typedef ([EnforceRange] unsigned long or bigint) IndexValue;
574+
typedef any IndexValue;
573575

574576
dictionary ModuleExportDescriptor {
575577
required USVString name;
@@ -1356,20 +1358,19 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|) coerces a JavaScript va
13561358
</div>
13571359

13581360
<div algorithm>
1359-
The algorithm <dfn>IndexValueToU64</dfn>(|v|, |indextype|) asserts that a JavaScript value is the appropriate variant of {{IndexValue}} for an {{IndexType}}, and ensures that its value is in [=u64=] range for WebAssembly embedding operations, by performing the following steps:
1361+
The algorithm <dfn>IndexValueToU64</dfn>(|v|, |indextype|) converts a JavaScript value to a WebAssembly [=u64=] for use in embedding operations. It is designed to act like [=[EnforceRange]=] [=unsigned long=] for {{IndexType}} "i32", and to extend these semantics to {{IndexType}} "i64", by performing the following steps:
13601362

13611363
1. If |indextype| is "i32",
1362-
1. If |v| [=is a Number=],
1363-
1. Assert: Due to WebIDL types and [=[EnforceRange]=], 0 ≤ [=ℝ=](|v|) < 2<sup>64</sup>.
1364-
1. Return [=ℝ=](|v|) as a WebAssembly [=u64=].
1365-
1. Otherwise, [=throw=] a {{TypeError}}.
1366-
1. Else if |indextype| is "i64",
1367-
1. If |v| [=is a BigInt=],
1368-
1. If |v| is not equal to [=!=] [$ToBigUint64$](|v|), [=throw=] a {{TypeError}}.
1369-
1370-
Note: This operation is designed to mirror [=[EnforceRange]=], which [=throws=] a {{TypeError}} for out-of-range numeric values.
1371-
1. Return [=ℝ=](|v|) as a WebAssembly [=u64=].
1372-
1. Otherwise, [=throw=] a {{TypeError}}.
1364+
1. Let |n| be [=?=] [$ConvertToInt$](|v|, 32, "unsigned"), where the destination type is associated with [=[EnforceRange]=].
1365+
1366+
Note: This is equivalent to the [=js-unsigned-long|JS conversion rules=] for [=[EnforceRange]=] [=unsigned long=].
1367+
1. Return [=ℝ=](|n|) as a WebAssembly [=u64=].
1368+
1. If |indextype| is "i64",
1369+
1. Let |n| be [=?=] [$ToBigInt$](|v|).
1370+
1. If |n| &lt; 0 or |n| &gt; 2<sup>64</sup> &minus; 1, [=throw=] a {{TypeError}}.
1371+
1372+
Note: This operation is designed to emulate [=[EnforceRange]=].
1373+
1. Return [=ℝ=](|n|) as a WebAssembly [=u64=].
13731374
1. Assert: This step is not reached.
13741375

13751376
</div>

0 commit comments

Comments
 (0)