Skip to content

val.call<T>() can't return 64-bit integers #24547

Closed
@RReverser

Description

@RReverser

Simple demo (can be reproduced in test_i64_val.cpp):

val::global().call<int64_t>("BigInt", max_int64_t);

fails with:

TypeError: Cannot convert a BigInt value to a number
    at wasm://wasm/000d1786:wasm-function[165]:0x66f9
    at wasm://wasm/000d1786:wasm-function[85]:0x44b2
    at wasm://wasm/000d1786:wasm-function[55]:0x381d
    at wasm://wasm/000d1786:wasm-function[41]:0x2810
    at wasm://wasm/000d1786:wasm-function[180]:0x6ad0
    at D:\emscripten\out\test\test_i64_val.js:629:12
    at callMain (D:\emscripten\out\test\test_i64_val.js:5377:15)
    at doRun (D:\emscripten\out\test\test_i64_val.js:5430:24)
    at run (D:\emscripten\out\test\test_i64_val.js:5443:5)
    at removeRunDependency (D:\emscripten\out\test\test_i64_val.js:584:7)
    at receiveInstance (D:\emscripten\out\test\test_i64_val.js:734:5)
    at receiveInstantiationResult (D:\emscripten\out\test\test_i64_val.js:752:12)
    at createWasm (D:\emscripten\out\test\test_i64_val.js:778:17)
Thrown at:
    at $func165 (wasm://wasm/000d1786:1:26362)
    at $func85 (wasm://wasm/000d1786:1:17587)
    at $func55 (wasm://wasm/000d1786:1:14366)
    at $func41 (wasm://wasm/000d1786:1:10257)
    at $main (wasm://wasm/000d1786:1:27345)
    at D:\emscripten\out\test\test_i64_val.js:629:12
    at callMain (D:\emscripten\out\test\test_i64_val.js:5377:15)
    at doRun (D:\emscripten\out\test\test_i64_val.js:5430:24)
    at run (D:\emscripten\out\test\test_i64_val.js:5443:5)
    at removeRunDependency (D:\emscripten\out\test\test_i64_val.js:584:7)

This is due to generic wiretype being a double. I imagine the easiest fix would be changing so that the return value is stored on the stack instead of being actually returned from the function, so that you can store bigints via HEAP64 and all other numbers via HEAPF64 in the same ABI. cc @brendandahl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions