Skip to content

[js-api] Fix AddressValueToU64's type errors - #2275

Merged
rossberg merged 2 commits into
WebAssembly:mainfrom
kaist-plrg:fix/js-api-address-value-to-u64
Oct 13, 2026
Merged

rossberg merged 2 commits into
WebAssembly:mainfrom
kaist-plrg:fix/js-api-address-value-to-u64

Conversation

@f52985

@f52985 f52985 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes two type-related errors in the AddressValueToU64 algorithm.

The algorithm AddressValueToU64(v, addrtype) converts a JavaScript value to a WebAssembly u64 ..., by performing the following steps:

1. If addrtype is i32,
    1. Let n be ? ConvertToInt(v, 32, "unsigned"), where the destination type is associated with [EnforceRange].
    ...
1. If addrtype is i64,
    1. Let n be ? ToBigInt(v).
    1. If n < 0 or n > 2^64 − 1, throw a TypeError.
    ...

1. JavaScript value vs IDL value

v here isn't a JavaScript value, but an IDL value.

It's whatever the caller's own IDL-declared AddressValue argument resolved to after WebIDL's own argument-conversion step already ran.

Both ConvertToInt and ToBigInt are defined over genuine JavaScript values, so v needs converting back before either branch uses it:

1. Let V be v, converted to a JavaScript value.

Both branches then read V instead of v.

2. BigInt vs Mathematical value

The i64 branch's range check compares n (a BigInt bound the line above via ?ToBigInt) directly against the mathematical-value literals 0/2^64 − 1, with no conversion.

According to the ECMA-262 standard:

Numeric operators applied to mixed-type operands (such as a Number and a mathematical value) are not defined and should be considered an editorial error in this specification.

so the range check should be:

1. If ℝ(n) < 0 or ℝ(n) > 2^64 − 1, throw a TypeError.

@Ms2ger Ms2ger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying, thanks

Comment thread document/js-api/index.bs Outdated
Comment thread document/js-api/index.bs Outdated
Comment thread document/js-api/index.bs Outdated
Rename V to jsValue, add a note explaining the any-to-JS-value
conversion, and bind ℝ(n) once instead of three times.
@f52985

f52985 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

All done, this reads better now. Thanks for the feedback!

@Ms2ger Ms2ger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Will leave to @rossberg to merge as well

@rossberg
rossberg merged commit 340650f into WebAssembly:main Oct 13, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants