node icon indicating copy to clipboard operation
node copied to clipboard

WebAssembly source phase imports

Open legendecas opened this issue 1 year ago • 3 comments

TC39 proposal source phase imports reached to stage 3 and has been implemented in V8 (starting from M131).

import source FooModule from "./foo.wasm";
FooModule instanceof WebAssembly.Module; // true

The feature requires Node.js integration to support WebAssembly source phase imports. TLDR, if a SourceTextModule imports a source-phase WebAssembly module, create a module source object with v8::WasmModuleObject::Compile and return the WebAssembly.Module object from v8::Module::ResolveSourceCallback, and v8::HostImportModuleWithPhaseDynamicallyCallback.

See design doc for details.

WPT: https://github.com/web-platform-tests/wpt/blob/master/wasm/webapi/esm-integration/source-phase.tentative.html

/cc @guybedford

legendecas avatar Nov 28 '24 15:11 legendecas

This should ideally be implemented along with the ESM instance imports and should likely also go with unflagging --experimental-wasm-modules.

guybedford avatar Nov 28 '24 18:11 guybedford

There's not much reason to care about ESM instance imports without also having worker_threads support instantiating workers from a ModuleSource - which is worth doing, but is probably a bigger topic than wasm source phase imports (which are immediately useful).

bakkot avatar Dec 01 '24 21:12 bakkot

Emscripten would love to start using this feature as soon as its available: https://github.com/emscripten-core/emscripten/issues/23047

sbc100 avatar Dec 03 '24 02:12 sbc100

This landed in #56919.

guybedford avatar Feb 28 '25 23:02 guybedford