Skip to content

WASM support #6

Closed
Closed
@kabergstrom

Description

@kabergstrom

I investigated if it would be possible to add WASM support and it looks like there might be a way. While I have not found a similar start/end convention that works, WASM supports custom data sections which can be accessed as an array from JS. wasm_bindgen has a hidden and somewhat unsupported function that can get a handle to the WebAssembly.Module, while js-sys exposes bindings for fetching data from a custom section. This code compiles:

    let module = js_sys::WebAssembly::Module::new(&wasm_bindgen::module()).unwrap(); 
    let data = js_sys::WebAssembly::Module::custom_sections(&module, "thingies");

@ibaryshnikov created a more complete and runnable example here:
https://github.com/ibaryshnikov/wasm-custom-sections/blob/master/src/lib.rs

Unfortunately, webpack does not expose the WebAssembly.Module object in javascript:
webpack/webpack#8157

Here's another similar issue:
WebAssembly/esm-integration#14

So this approach seems to work, but the WebAssembly.Module handle is not exposed in certain cases. Better than nothing I guess? 😁

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions