cloudflare / cloudflare/workerd
Improving V8's error thrown when WebAssembly.instantiate(...) is used with a buffer
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
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()`](https://source.chromium.org/chromium/chromium/src/+/main:v8/src/objects/contexts.cc;l=772-778;bpv=1;bpt=1?q=%22wasm%20code%20generation%20disallowed%20by%20embedder%22&ss=chromium) is `Wasm code generation disallowed by embedder`.
This sometimes leads to confusion by users or developers of WASM libraries:


Some libraries, like [`xxhash-wasm`](https://github.com/jungomi/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
Contributor guide
Assessment
This issue has not been assessed yet.