Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-53477] Implement WebAssembly/ES Module Integration #850

Open
2 tasks
fniephaus opened this issue Sep 26, 2024 · 0 comments
Open
2 tasks

[GR-53477] Implement WebAssembly/ES Module Integration #850

fniephaus opened this issue Sep 26, 2024 · 0 comments
Assignees
Labels
proposal ECMAScript Proposals

Comments

@fniephaus
Copy link
Member

fniephaus commented Sep 26, 2024

TL;DR

We plan to implement WebAssembly/ES Module Integration in GraalJS. This allows WebAssembly modules to be imported similarly to ES modules to improve the ergonomics of WebAssembly module instantiation.

Details

Currently, there is an imperative JS API for instantiating WebAssembly modules. This requires users to manually fetch a module file, wire up imports, and run WebAssembly.instantiate or WebAssembly.instantiateStreaming.

A declarative API would improve the ergonomics by making this work happen implicitly.

import { foo } from "./myModule.wasm";
foo();

Then by integrating with Source Phase Imports, arbitrary instantiations with custom imports can still be supported.

import source myModule from "./myModule.wasm";

const { foo: foo1 } = new WebAssembly.Instance(myModule, { ...imports1 });
foo1();

const { foo: foo2 } = new WebAssembly.Instance(myModule, { ...imports2 });
foo2();

For dynamically loaded modules, dynamic import() integration is also supported for both phases.

const { foo: foo1 } = await import("./myModule.wasm");

const myModule = await import.source("./myModule.wasm");
const { foo: foo2 } = await WebAssembly.instantiate(myModule, { ...imports });
  • Stage 1: Source Phase Imports (import source fibMod from "./fib.wasm)
  • Stage 2: Evaluation Phase Imports (import { fib } from "./fib.wasm)
@fniephaus fniephaus added the proposal ECMAScript Proposals label Sep 26, 2024
@fniephaus fniephaus moved this to Todo in GraalJS Roadmap Sep 26, 2024
@fniephaus fniephaus changed the title Implement WebAssembly/ES Module Integration [GR-53477] Implement WebAssembly/ES Module Integration Sep 26, 2024
@woess woess moved this from Todo to In Progress in GraalJS Roadmap Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal ECMAScript Proposals
Projects
Status: In Progress
Development

No branches or pull requests

2 participants