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

Fix __wbg_set_wasm call order on nodejs-module #4093

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kawaemon
Copy link
Contributor

@kawaemon kawaemon commented Aug 25, 2024

When targeting experimental-nodejs-module and using #[wasm_bindgen(start)] attribute, current wasm-bindgen generates wasm.__wbindgen_start(); statement before __wbg_set_wasm call:

import { __wbg_set_wasm } from "./ej_bg.js";

let imports = {};
import * as import0 from './ej_bg.js';
imports['./ej_bg.js'] = import0;

// ... reducted... 

const wasm = wasmInstance.exports;
export const __wasm = wasm;


wasm.__wbindgen_start();

__wbg_set_wasm(wasm);
export * from "./ej_bg.js";

which causes runtime exception like below.

❯ node a/nm/ej.js
file:///tmp/ktmp/ej/a/nm/ej_bg.js:17
        cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
                                                      ^

TypeError: Cannot read properties of undefined (reading 'memory')
    at getUint8ArrayMemory0 (file:///tmp/ktmp/ej/a/nm/ej_bg.js:17:55)
    at getStringFromWasm0 (file:///tmp/ktmp/ej/a/nm/ej_bg.js:24:37)
    at __wbindgen_string_new (file:///tmp/ktmp/ej/a/nm/ej_bg.js:62:17)
    at ej.wasm.wasm_bindgen::JsValue::from_str::h94d293071ebb3387 (wasm://wasm/ej.wasm-00039026:wasm-function[87]:0x7bf7)

This PR fixes this issue.

@kawaemon kawaemon changed the title Fix __wbg_set_wasm call order Fix __wbg_set_wasm call order on nodejs-module Aug 25, 2024
@daxpedda
Copy link
Collaborator

Cc @Systemcluster, would appreciate your review here.

@daxpedda daxpedda added the needs review Needs a review by a maintainer. label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Needs a review by a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants