Lib: add Broadcast Channel and Shared Worker bindings#2400
Open
hhugo wants to merge 5 commits into
Open
Conversation
Add two new modules to js_of_ocaml: - BroadcastChannel: the BroadcastChannel constructor, name, polymorphic postMessage, close, onmessage/onmessageerror and a support probe. - SharedWorker: the page-side sharedWorker (port, onerror) with plain, named and options constructors (workerOptions: name/type/credentials), and the worker-side sharedWorkerGlobalScope (name, close, onconnect) with a set_onconnect helper that hands the connecting MessagePort to the callback. Register the modules in js_of_ocaml.ml, add runtime tests (BroadcastChannel gated off QuickJS; SharedWorker limited to the environment-independent parts since the global is browser-only), and update CHANGES.md and API-STATUS.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A shared worker receives connect events as soon as the loader script has been evaluated, while the wasm module is still being instantiated asynchronously: nothing listens to these events yet and the connecting page never gets its port. Capture connect events during start-up and dispatch them again once the program is initialized. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A page (lib/tests-browser/test_shared_worker.html) to open in several tabs: every tab talks to a single shared worker that numbers connections and echoes messages with a shared counter, the worker announces new connections on a broadcast channel, and each tab can broadcast to the others. Works in both js and wasm modes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes the api-check test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Served without a charset in the Content-Type header, browsers fall back to windows-1252 and the em dash in the mode-switch line renders as mojibake. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add two new modules to
js_of_ocaml, filling the two remaining Tier 2 communication gaps from API-STATUS.md:BroadcastChannel: theBroadcastChannelconstructor,name, polymorphicpostMessage,close,onmessage/onmessageerror(typed with the sharedDom_html.messageEvent), and anis_supportedprobe.SharedWorker:sharedWorker(itsport : MessageChannel.messagePort,onerrorreusingWorker.errorEvent) with plain, named and options constructors (workerOptions:name/type/credentials);sharedWorkerGlobalScope(name,close,onconnect),global (), and aset_onconnecthelper that extracts the connectingMessagePortfrom theconnectevent, mirroringWorker.set_onmessage(including theInvalid_argumentguard outside a shared worker scope).Runtime tests exercise
BroadcastChannelunder Node (construction,name,instanceof,postMessage/close), gated off QuickJS;SharedWorkeris browser-only so its tests cover the environment-independent parts (options record, support probe, theset_onconnectguard).CHANGES.mdandAPI-STATUS.mdare updated.🤖 Generated with Claude Code