Skip to content

unint64_t is passed through to JS as a signed value instead #13902

Description

@cuberoot

While trying to pass std::numeric_limits<uint64_t>::max() through to JS in bigint mode, I hit an issue where I get a -1 on the JS side. I would expect the value to come through correctly as bigint can represent a number that large.

I can reproduce this with a cpp file with a JS library as follows:

Put this in main.cpp

#include <iostream>
#include <emscripten/bind.h>
#include <emscripten/emscripten.h>

extern "C" {
  extern void my_js(uint64_t value);
}

int main() {
    std::cout << std::numeric_limits<uint64_t>::max() << std::endl;
    my_js(std::numeric_limits<uint64_t>::max());

    return 0;
}

Put this in main.js:

mergeInto(LibraryManager.library, {
    my_js: function(value) {
        console.log('value', value);
    },
});

Then compile with this command:

emcc --js-library main.js -s WASM_BIGINT main.cpp -o test.html

This gives me the following output when I load test.html:

18446744073709551615
test.js:4286 value -1n

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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