Pluggable JS↔WASM boundary contract.

Every bridge in the matrix implements this interface. The matrix is wasmgc-classic and any future bridge (e.g. shared-memory for the threading EPIC); wasmgc-builtins was in it until causl/causl-core-rs#355 retired it (see detectBridge). The BackendEngine consumes only the interface; bridges are interchangeable at runtime.

Two operations dominate boundary cost — object construction and string copying — so they are the only two crossings the interface exposes as primitives. Numbers and booleans pass through cheaply (8 bytes / 4 bytes respectively) and need no bridge primitive.

interface Bridge {
    abiVersion: number;
    features: BridgeFeatures;
    id: BridgeId;
    fromWasmObject(h: WasmObjectHandle): object;
    fromWasmString(h: WasmStringHandle): string;
    release(h: WasmHandle): void;
    toWasmObject(o: object): WasmObjectHandle;
    toWasmString(s: string): WasmStringHandle;
}

Properties

abiVersion: number

ABI version, bumped on any ABI-breaking bridge change. The Rust-side .bridge_abi_version linker section is read by the loader and matched against this number; a mismatch fails-closed before the WASM module is instantiated.

features: BridgeFeatures

Capability flags this bridge advertises. Consumers branch on the flag, not the Bridge.id.

Stable identifier for telemetry and benchmarking. The one shipped id is wasmgc-classic; future bridges add new ids without deprecating existing ones.

Methods

  • Resolve an opaque object handle back to its JS object.

    Parameters

    Returns object

  • Resolve an opaque string handle back to a JS string.

    The returned string is a plain JS string even when the bridge keeps the underlying buffer in WASM linear memory; the bridge never leaks JsValue (or any wasm-bindgen wrapper) into bridge consumers.

    Parameters

    Returns string

  • Release a handle previously issued by this bridge. Idempotent; releasing an unknown or already-released handle is a no-op.

    Parameters

    Returns void

  • Register a JS object with the WASM module and return an opaque handle.

    Parameters

    • o: object

    Returns WasmObjectHandle

  • Register a JS string with the WASM module and return an opaque handle. The bridge owns the allocation; callers must Bridge.release it when done.

    Result strings are allocated through the bridge's allocator so a future wasm:string-view bridge can substitute its own without changing the consumer surface.

    Parameters

    • s: string

    Returns WasmStringHandle