Description
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
- Check out this test case and set up a local development environment for a basic
wasm-bindgen
-based project - Run
cargo test --target wasm32-unknown-unknown
; the test will pass. - 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 😩