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

Improving V8's error thrown when WebAssembly.instantiate(...) is used with a buffer #3345

Open
KianNH opened this issue Jan 16, 2025 · 0 comments

Comments

@KianNH
Copy link
Contributor

KianNH commented Jan 16, 2025

Some libraries will output WebAssembly as a byte array in a JavaScript file, and attempt to instantiate from that. Since this array could also be constructed dynamically or from external sources, it is classed as code generation and disallowed in the same way that eval and new Function are.

The error thrown from v8/src/objects/contexts.cc#Context::ErrorMessageForWasmCodeGeneration() is Wasm code generation disallowed by embedder.

This sometimes leads to confusion by users or developers of WASM libraries:

Image

Image

Some libraries, like xxhash-wasm, now have a specific workers export that uses the module rather than instantiating from a buffer:

https://github.com/jungomi/xxhash-wasm/blob/5923f26411ed763044bed17a1fec33fee74e47a0/src/index.js#L8

https://github.com/jungomi/xxhash-wasm/blob/5923f26411ed763044bed17a1fec33fee74e47a0/src/index.workerd.js#L3-L4

cc @jasnell

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

No branches or pull requests

1 participant