Skip to content

Can't return bigint from async function in Asyncify #23441

Open
@kainino0x

Description

@kainino0x

This works in JSPI but is broken in Asyncify. The problem seems to be somewhere in Asyncify.handleAsync.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.1 (89ce854a99238d04116a3d9b5afe241eec90c6c3)
clang version 20.0.0git (https:/github.com/llvm/llvm-project a32e36faf84bd7da3df0c7d50bb9020568128417)
Target: wasm32-unknown-emscripten
Thread model: posix

Failing command line in full:
Repro here: https://github.com/kainino0x/asyncify-bigint-bug
(live here http://kai.graphics/asyncify-bigint-bug/main_asyncify_bigint.html)
Just call make.
The args are in the makefile:

all:

ARGS := -g -sASYNCIFY_IMPORTS=my_async_i64,my_async_u64

# These don't work
main_asyncify_bigint.html: main.cpp Makefile
	em++ main.cpp -o $@ ${ARGS} -sASYNCIFY=1 -sWASM_BIGINT=1
main_asyncify_wasm64.html: main.cpp Makefile
	em++ main.cpp -o $@ ${ARGS} -sASYNCIFY=1 -sMEMORY64=1

# These do work
main_jspi_bigint.html: main.cpp Makefile
	em++ main.cpp -o $@ ${ARGS} -sJSPI=1 -sWASM_BIGINT=1
main_jspi_wasm64.html: main.cpp Makefile
	em++ main.cpp -o $@ ${ARGS} -sJSPI=1 -sMEMORY64=1

Code:

EM_JS(int64_t, my_async_i64, (), {
  return Asyncify.handleAsync(async () => {
    return -123n; // bigint
  });
});

EM_JS(uint64_t, my_async_u64, (), {
  return Asyncify.handleAsync(async () => {
    return -123n; // bigint
  });
});

int main() {
    int64_t i = my_async_i64();
    uint64_t u = my_async_u64();
    printf("got: %lli %llu\n", i, u);
}

Full link command and output with -v appended:

There isn't anything notable in the link output, the problem is a crash:

Uncaught TypeError: Cannot convert 0 to a BigInt
    at main_asyncify_bigint.wasm.__original_main (main_asyncify_bigint.wasm:0x580)
    at main_asyncify_bigint.wasm.main (main_asyncify_bigint.wasm:0x780)
    at ret.<computed> (main_asyncify_bigint.js:1273:24)
    at main_asyncify_bigint.js:718:12
    at callMain (main_asyncify_bigint.js:1832:15)
    at doRun (main_asyncify_bigint.js:1884:24)
    at main_asyncify_bigint.js:1893:7

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