Support WebAssembly.instantiateStreaming
I think it's better support WebAssembly.instantiateStreaming.
It makes more easy to use WebAssembly and we can get more compatibility for Web.
It already implemented in Google Chrome, Firefox and some browsers.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
instantiateStreaming already exists in deps/v8/src/wasm/wasm-js.cc but cannot cover this branch.
| if (isolate->wasm_compile_streaming_callback() != nullptr) { | |
| InstallFunc(isolate, webassembly, "compileStreaming", | |
| WebAssemblyCompileStreaming, 1); | |
| InstallFunc(isolate, webassembly, "instantiateStreaming", | |
| WebAssemblyInstantiateStreaming, 1); | |
| } |
To cover this branch, we must call SetWasmCompileStreamingCallback.
| void SetWasmCompileStreamingCallback(ApiImplementationCallback callback); |
| CALLBACK_SETTER(WasmCompileStreamingCallback, ApiImplementationCallback, | |
| wasm_compile_streaming_callback) |
In chromium, implemented here:
https://github.com/chromium/chromium/blob/51459d663d841c6430747aec97be9f7e7a7ca41f/third_party/blink/renderer/bindings/core/v8/v8_wasm_response_extensions.cc#L194-L222
And use it here:
https://github.com/chromium/chromium/blob/51459d663d841c6430747aec97be9f7e7a7ca41f/third_party/blink/renderer/bindings/core/v8/v8_wasm_response_extensions.cc#L228
Why we must inject the actual implementation,
It's said that this is for layering reasons.
WebAssembly/design#1085
Discussion
- How about it?
- How to make
instantiateStreamingcompatible with design.- ex.
instantiateStreaming(fs.promises.readFile('./some.wasm'), importObject)- It's not compatible with design.
- readFile returns
Buffer, notArrayBuffer.
- ex.