Skip to content

Support WebAssembly.instantiateStreaming #21130

Closed
@Leko

Description

@Leko

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);

node/deps/v8/src/api.cc

Lines 8876 to 8877 in de73272

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

  1. How about it?
  2. How to make instantiateStreaming compatible with design.
    • ex. instantiateStreaming(fs.promises.readFile('./some.wasm'), importObject)
      • It's not compatible with design.
      • readFile returns Buffer, not ArrayBuffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Issues and PRs that require attention from people who are familiar with C++.discussIssues opened for discussions and feedbacks.feature requestIssues that request new features to be added to Node.js.stalledIssues and PRs that are stalled.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions