Repository navigation
fix: preserve full-width u32 and signed s64 values across embedding calls - #365
Open
philippedev101 wants to merge 1 commit into
Open
philippedev101 wants to merge 1 commit into
philippedev101 wants to merge 1 commit into
Conversation
…calls Convert JavaScript Numbers to core Wasm i32 via JS::ToInt32 in a new coreabi_from_int32 helper and accept both signed and unsigned 64-bit BigInts in coreabi_from_bigint64. SpiderMonkey stores u32 values above INT32_MAX as doubles, so calling toInt32() or loading the low 32 bits of a JS::Value inline silently corrupted values in 2147483648..4294967295. Similarly, checking only BigIntIsUint64 in coreabi_from_bigint64 and call() aborted on negative s64 values. Route CoreAbiSampleI32, singular i32/i64 returns in call(), and synthesized import trampolines in splice.rs through the same helpers, and add the integer-boundaries bindings test covering both directions.
philippedev101
requested review from
andreiltd,
tschneidereit and
vados-cosmonic
as code owners
November 28, 2026 19:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes silent corruption of
u32values aboveINT32_MAXand aborts on negatives64values when passing integers across JS/Wasm import and export boundaries. Components using full-range 32-bit unsigned handles or signed 64-bit timestamps and offsets now round-trip cleanly in both directions.There are two bugs in the embedding and splicer conversion paths:
u32values in2147483648..4294967295are stored by SpiderMonkey as boxed doubles rather thanInt32Value.CoreAbiSampleI32andcall()calltoInt32(), whilesynthesize_import_functionsloads the rawJS::Valuebits inline withi64.load+i32.wrap_i64. For a boxed double, that reads the low 32 mantissa bits instead of the integer value.from_bigint64andcall()check onlyJS::detail::BigIntIsUint64, which returns false for negatives64BigInts and aborts.This PR adds a
coreabi_from_int32helper usingJS::ToInt32(handle.toNumber()), updatescoreabi_from_bigint64to accept bothBigIntIsInt64andBigIntIsUint64, routesCoreAbiSampleI32, singulari32/i64returns incall(), andCoreTy::I32import trampolines insplice.rsthrough those helpers, and removes the temporarycoreabi_from_int32export after splicing.Added
test/cases/integer-boundariescovering boundary values foru32,s32,u64, ands64across both singular returns and multi-value records (pair(s64, u32)). Verified withcargo fmt -- --check,cargo clippy --locked --workspace --all-targets --all-features,cargo test --locked --workspace, a rebuilt release embedding and splicer, andnpm run test:release(80 passed, 1 skipped).