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.

Structured Clone Algorithm for cross-thread data serialization #178

open opened by pierrelf.com

Phase 19: Web Workers#

Implement the WHATWG Structured Clone algorithm so JS values can be safely transferred across worker thread boundaries via postMessage.

What to implement#

Add a structured_clone module in crates/js/src/:

  • Serialization (serialize(value: &JsValue) -> Result<SerializedData, CloneError>): walk the JS value graph and produce a self-contained, heap-allocation-free byte representation. Support:
    • Primitives: undefined, null, boolean, number, string, BigInt
    • Plain objects and arrays (recursively)
    • ArrayBuffer (copy bytes)
    • TypedArrays (Uint8Array, Int32Array, Float64Array, etc.) and DataView
    • Map, Set
    • Date (serialize as milliseconds since epoch)
    • Transferable placeholder for future ArrayBuffer transfer (mark as transferred, zero original)
  • Deserialization (deserialize(data: SerializedData, context: &mut JsContext) -> JsValue): reconstruct the value in the target context's heap.
  • Error handling: non-cloneable values (functions, DOM nodes, Symbols) return CloneError::NotSerializable which maps to a DataCloneError JS exception.

Acceptance criteria#

  • Round-trip test: serialize then deserialize a deeply nested object with arrays, numbers, strings, and an ArrayBuffer; assert structural equality.
  • Functions and DOM nodes produce CloneError::NotSerializable.
  • cargo test -p we-js passes.
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/3mlxpo36wat2c