we (web engine): Experimental web browser project to understand the limits of Claude
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

WebAssembly JS API: Module, Instance, Memory, Table, Global #226

open opened by pierrelf.com

Expose the WebAssembly engine to scripts as the WebAssembly.* JS namespace per https://webassembly.github.io/spec/js-api/. Depends on the instantiation pipeline and the existing we-js engine.

Scope:

  • WebAssembly global object with namespace methods: validate(bufferSource), compile(bufferSource), instantiate(bufferSourceOrModule, importObject).
  • Constructors: WebAssembly.Module(bufferSource), WebAssembly.Instance(module, importObject), WebAssembly.Memory({initial, maximum, shared?}), WebAssembly.Table({element, initial, maximum}), WebAssembly.Global({value, mutable}, initialValue).
  • ArrayBuffer / TypedArray plumbing: accept BufferSource for binary input; WebAssembly.Memory.prototype.buffer exposes a detachable ArrayBuffer view that aliases the live memory (re-issued after each grow per spec).
  • Memory.prototype.grow(delta) and Table.prototype.grow(delta, init?) with the spec's return semantics.
  • Global.prototype.value getter/setter and Global.prototype.valueOf().
  • Function imports: a JS callable supplied via importObject is wrapped as a wasm function; on call, arguments are coerced per ToWebAssemblyValue, the JS callable runs, and the result is coerced back via FromWebAssemblyValue. Exceptions thrown by JS propagate out of the wasm activation as WebAssembly.RuntimeError or as the original JS error per spec.
  • Error types: WebAssembly.CompileError, WebAssembly.LinkError, WebAssembly.RuntimeError; map parser/validator/instantiation/runtime traps to the right type.
  • Module static helpers: imports(module), exports(module), customSections(module, name).

Acceptance criteria:

  • A JS file can call WebAssembly.instantiate with a Uint8Array and an importObject containing JS functions, then call exported functions and observe traps as WebAssembly.RuntimeError.
  • ArrayBuffer aliasing on Memory.buffer is verified by writing through Uint8Array and reading the value from wasm.
  • Promise-returning APIs (compile, instantiate) use the existing JS Promise/microtask machinery.
  • Unit tests cover argument coercion (i32/i64/f32/f64 ↔ Number/BigInt), error variant mapping, and Memory.buffer detachment after grow.
  • cargo clippy --workspace -- -D warnings passes; no external dependencies.
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mm2tmfj22m2c