Skip to content

feat(std): add WinterTC polyfills for WASI 0.3 components - #2613

Open
MendyBerger wants to merge 4 commits into
bytecodealliance:mainfrom
MendyBerger:wintertc
Open

MendyBerger wants to merge 4 commits into
bytecodealliance:mainfrom
MendyBerger:wintertc

Conversation

@MendyBerger

Copy link
Copy Markdown
Contributor

Adds polyfills for the WinterTC Minimum Common API (ECMA-429) to jco-std, for JavaScript engines in WASI 0.3 components that don't have these APIs built in, such as QuickJS in jco componentize --backend quickjs.

What's included

  • APIs (@bytecodealliance/jco-std/wintertc): spec-shaped ES module exports. They don't install globals yet. Covers events and abort, streams, fetch (Headers, Request, Response, fetch, FormData, Blob/File), encoding, URL/URLSearchParams/URLPattern, compression, Web Crypto, timers, console, performance, MessageChannel, atob/btoa, queueMicrotask and reportError.
  • Calls WASI 0.3 directly (wasi:clocks, wasi:random, wasi:cli, wasi:http), typed by the declarations jco guest-types generates, so any toolchain that follows those types can use them. The places where componentize-qjs differs from the generated types are handled in src/wintertc/internal/wit.ts:
    • futures aren't thenable
    • stream<u8> is passed as Uint8Array chunks
    • import calls can be cancelled
  • Composed components: URL parsing with IDNA, URLPattern, deflate, legacy text encodings and cryptography are separate components behind jco:wintertc/* interfaces, which you compose with your component. These are large pure algorithms that already have mature, spec-conformant implementations: Servo's url, Deno's urlpattern, Firefox's encoding_rs, and audited constant-time RustCrypto code. Reusing those beats reimplementing them in JavaScript, which would be slower on QuickJS, and for Web Crypto it keeps key material out of the JS heap. They're built from Rust crates in packages/jco-std/crates for wasm32-wasip3, and import only WASI 0.3. prepack builds them into wasm/, and their WIT ships in wit/wintertc-0.1.0/.
  • Not provided: structuredClone and WebAssembly, which have to come from the engine. MessagePort.postMessage() throws DataCloneError without the engine's structuredClone.
  • Non-standard exports:
    • flushOutput(): WASI 0.3 stdout is an async stream and wasmtime run exits when run returns.
    • errorTarget(): there's no global object to fire error events at.
    • disposeCryptoKey(): frees key material early, before garbage collection.

User docs: docs/src/wasi/wintertc.md. Contributor notes: packages/jco-std/src/wintertc/README.md.

Testing

All tests run inside real componentize-qjs components under wasmtime, composed with the Rust components:

  • 958 tests: unit tests (vitest-style, one component per file), end-to-end fixtures including fetch from a wasi:http handler, and WPT.
  • WPT runs at a pinned commit, one component per area, with expectation files listing the known failures. About 32.8k of 56.7k subtests pass. Failures are labelled engine: (for example, no structuredClone) or runner:.
  • New CI job test-jco-std-wintertc. It sets WINTERTC_REQUIRE_TOOLS=1, so a missing tool fails the job instead of skipping tests.

Review notes

  • Size: most of the diff is the WPT expectation files, crates/Cargo.lock, and five small Rust crates. The generated type declarations are gitignored and regenerated by build:ts and check:wintertc.
  • Licences: composing the components adds Unicode-3.0 code (ICU4X, which jco already ships through url/idna) and BSD-3-Clause code (encoding_rs, the dalek crates). Details are on the docs page.
  • Release: release.yml installs the Rust toolchain pinned in crates/rust-toolchain.toml when packing jco-std, so prepack can build the components. This path hasn't run yet.

🤖 Generated with Claude Code

Polyfill the WinterTC Minimum Common API for engines that lack it, as spec-shaped ES module
exports that call WASI 0.3 directly, typed by jco guest-types. URL, URLPattern, compression,
legacy decoding and Web Crypto run in composed wasm32-wasip3 components whose WIT ships in
wit/wintertc-0.1.0. Pin jco-std to TypeScript 6 for typescript-eslint.

This branch has not been deployed

No deployments
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