Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malformed JavaScript binding with codegen-units = 1 #4220

Closed
cdata opened this issue Oct 23, 2024 · 1 comment · Fixed by #4241
Closed

Malformed JavaScript binding with codegen-units = 1 #4220

cdata opened this issue Oct 23, 2024 · 1 comment · Fixed by #4241
Labels

Comments

@cdata
Copy link

cdata commented Oct 23, 2024

Describe the Bug

The JavaScript binding for at least one API (JsValue::is_instance_of::<WebAssembly::Global>()) is malformed when building with a profile where codegen-units = 1, changing its behavior across build profiles in unexpected ways.

Steps to Reproduce

  1. Check out this test case and set up a local development environment for a basic wasm-bindgen-based project
  2. Run cargo test --target wasm32-unknown-unknown; the test will pass.
  3. Run cargo test --target wasm32-unknown-unknown --release; the test fails!

Expected Behavior

The test should pass under both build profiles.

Actual Behavior

The test fails when building for release (a profile which, in this case, is configured with codegen-units = 1).

Additional Context

I worked backwards to codegen-units = 1 from the symptom of the problem: malformed JavaScript bindings.

In the passing case, the binding that affected me looks like this:

imports.wbg.__wbg_instanceof_Global_8f08b576d8530762 = function() { return logError(function (arg0) {
        let result;
        try {
            result = arg0 instanceof WebAssembly.Global;
        } catch (_) {
            result = false;
        }
        const ret = result;
        _assertBoolean(ret);
        return ret;
    }, arguments) };

In the failing case, the binding looks like this:

imports.wbg.__wbg_instanceof_Global_8f08b576d8530762 = function() { return logError(function (arg0) {
        let result;
        try {
            result = getObject(arg0) instanceof Global;
        } catch (_) {
            result = false;
        }
        const ret = result;
        _assertBoolean(ret);
        return ret;
    }, arguments) };

Note the getObject(arg0) instanceof Global check - the RHS of this should be WebAssembly.Global (as it is in the passing case). In the failing case, Global is undefined and the binding returns the wrong answer 😩

@cdata cdata added the bug label Oct 23, 2024
@daxpedda
Copy link
Collaborator

Nice work!
Will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants