Skip to content

feat(js2wasm): add embedded Wasmtime module backend - #1

Open
ttraenkler wants to merge 6 commits into
mainfrom
codex/js2wasm-module-backend
Open

feat(js2wasm): add embedded Wasmtime module backend#1
ttraenkler wants to merge 6 commits into
mainfrom
codex/js2wasm-module-backend

Conversation

@ttraenkler

@ttraenkler ttraenkler commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Add an opt-in engine_js2wasm backend that preserves the public rusty_v8 API while executing ahead-of-time js2wasm artifacts through embedded Wasmtime 47.0.3.

The latest slice:

  • keeps the exact pinned deno_core 0.407.0 wrapper/module/application transaction in one context-owned Wasmtime instance
  • validates source hashes and order for primordials, infra, timers, core, ext:core/mod.js, and the exact hello_world usage
  • implements the value semantics reached by unchanged Rust deno_core: handles, objects/prototypes, templates/functions, weak handles, TryCatch, promises, synthetic/source modules, metadata, namespaces, external backing stores, and typed arrays
  • binds the real Rust-owned Deno.core.ops.op_sum and op_print Function handles through nine strict scalar imports while preserving their original External(OpCtx*) callback data
  • binds generic AOT replay to both the exact module graph and exact precompiled bytes with SHA-256, failing closed on a missing, stale, or mismatched sidecar
  • releases ContextState before reentrant Wasmtime callbacks and rejects recursive Store access cleanly
  • retains a Unix-only 237-symbol weak, fail-loud diagnostic ABI so every unimplemented executed path names itself and aborts

With companion compiler PR loopdive/js2#4766, unchanged pinned deno_core::hello_world exits 0 and prints exactly:

The sum of
1,2,3
is
6
Exception:
TypeError: serde_v8 error: invalid type; expected: array, got: Number

Verification

  • production and runtime-compiler/diagnostic feature checks passed; JSC-only dependency isolation also passed
  • 11/11 nonignored js2wasm semantic integration tests passed
  • public exact Script/Module/usage test passed and verifies stable Function identities, exact External data pointers, ordered 6-print/2-sum callbacks, inner exception consumption, and a clean outer TryCatch
  • graph-binding regressions reject missing, wrong-graph, and wrong-artifact bindings before deserialization
  • exact raw artifact precompile/bootstrap passed in two isolated stores
  • unchanged pinned Rust example exited 0 with the six lines above and no diagnostic weak-symbol abort

Scope

This remains a narrow synchronous POC. It does not claim general Rust/Wasm object identity, module live bindings, broad generated op tables, async promise/microtask semantics, dynamic imports, inspector support, or a complete portable Deno distribution.

Related: loopdive/js2#4766 and littledivy#74.

ttraenkler and others added 3 commits August 12, 2026 09:07
Add an opt-in engine_js2wasm backend that compiles linked TypeScript module graphs through js2wasm, owns the resulting Wasmtime instance in the v8x module handle, and exposes the first typed Deno.cwd host seam.

Cover both live compilation and compiler-free AOT artifact replay through the rusty_v8 module API.

Co-authored-by: Codex <codex@openai.com>
Move the embedded module backend from Wasmtime 45.0.3 to the latest stable release and regenerate the dependency lockfile.

Both live js2wasm compilation and compiler-free AOT replay retain their value-level Deno.cwd validation.

Co-authored-by: Codex <codex@openai.com>
Move Cranelift behind a development-only precompile feature and load trusted target-specific artifacts in production. Share the Engine, direct Deno host Linker, Module, and InstancePre while retaining a private Store and Instance for each evaluated module.

Extend the integration proof to require one module load, two isolated instantiations, exact Deno.cwd host-call counts, and compiler-free artifact replay.

Co-authored-by: Codex <codex@openai.com>
Load the standardized-EH-compatible Deno core artifact through the public classic-script path, retain one Wasmtime runtime per context, and validate the pinned source order and hashes.

Expose the first Rust-visible setUpAsyncStub callback bridge while keeping all non-manifest scripts fail-loud. Full Rust/Wasm object identity and extension execution remain follow-up work.

Co-authored-by: Codex <codex@openai.com>
Extend the Rust-owned v8x heap and ABI through the exact deno_core bootstrap path, including weak fail-loud diagnostics, source and synthetic module state, promises, TryCatch, prototypes, typed external buffers, stable namespaces, and function metadata.

Keep one prelinked Wasmtime instance alive across the pinned wrappers, module, and usage stages. Bind the exact Rust-owned op_sum and op_print Function handles through a strict scalar bridge, preserving External callback data, serde TypeError behavior, UTF-16 output, and per-store isolation.

Add public rusty_v8 value tests and the exact six-source transaction proof without claiming general V8, namespace, async, or Deno API completeness.

Co-authored-by: Codex <codex@openai.com>
Require generic precompiled modules to carry SHA-256 bindings for both the exact source graph and artifact bytes, and deserialize the verified bytes under a digest-aware cache key.\n\nMove the retained Deno runtime behind a reentrancy-checked RefCell so callbacks cannot alias ContextState, correct the Windows resolve-module return-slot ABI, and keep backend-only dependencies feature scoped.\n\nCo-authored-by: Codex <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant