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.

Implement BroadcastChannel for same-origin cross-context messaging #189

open opened by pierrelf.com

Goal#

Implement the BroadcastChannel interface so documents and workers within the same origin can communicate via a named channel, reusing the Phase 19 structured clone and worker message-channel infrastructure.

Depends on: Phase 19 (Web Workers — already complete).

Scope#

  • BroadcastChannel interface
    • new BroadcastChannel(name: string) — creates or joins the named channel
    • postMessage(message) — structured-clones the message and dispatches MessageEvent on every other BroadcastChannel with the same name in the same origin
    • close() — removes this channel instance from the registry
    • Properties: name
    • Event handlers: onmessage, onmessageerror plus addEventListener equivalents
  • Origin scoping
    • Two BroadcastChannel instances communicate only when they are in browsing contexts (documents or workers) with the same origin
    • Closed channels do not receive or emit
  • Cross-thread delivery
    • When the document and a Worker open the same channel, messages cross thread boundaries via the existing worker message-channel infrastructure
    • Use the Phase 19 structured clone implementation (crates/js/src/structured_clone.rs) for serialization
    • Non-cloneable values fire messageerror on receivers (do not abort the sender)
  • Registry
    • Per-event-loop registry keyed by (origin, name)
    • Workers and documents register/unregister on construction/close (and on context destruction)
  • Lifecycle
    • GC root channels with non-empty onmessage/onmessageerror handlers or pending listeners
    • Closing a context closes all its channels

Acceptance Criteria#

  • Two documents in the same origin can exchange messages via the same channel name
  • A document and a Worker exchange messages over a BroadcastChannel
  • The sender does not receive its own postMessage (per spec)
  • name is the value passed to the constructor (or coerced to string)
  • After close(), no further messages are received and postMessage throws InvalidStateError
  • Non-cloneable values fire messageerror on listening channels, not on the sender
  • Origin isolation: a different-origin channel with the same name does not see the messages
  • Unit tests covering: same-context dispatch, cross-worker dispatch, sender exclusion, close semantics, origin isolation, structured-clone error path
  • Conventions
    • cargo fmt --all --check
    • cargo clippy --workspace -- -D warnings
    • cargo test --workspace
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/3mly7sv5rjh24