cloudflare / cloudflare/workerd

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

Open
#3,345 0 comments 0 reactions 0 assignees View on GitHub
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:

![Image](https://github.com/user-attachments/assets/17ab820e-468f-440c-9184-72843c882ac8)

![Image](https://github.com/user-attachments/assets/9cedb02e-d7a3-4bcf-be9d-5ac778fa6e5b)

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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.