Wasm: dispatch lifecycle events when async instantiation completes#2232
Open
JasonGross wants to merge 3 commits into
Open
Wasm: dispatch lifecycle events when async instantiation completes#2232JasonGross wants to merge 3 commits into
JasonGross wants to merge 3 commits into
Conversation
Closed
3 tasks
Contributor
Author
|
I assume all of the CI failures are spurious? |
Compiling and instantiating the generated WebAssembly is asynchronous, but the launcher only returns a Promise that callers typically don't await. Surrounding JavaScript that runs on DOMContentLoaded therefore has no way to tell when the OCaml exports are actually ready. Dispatch 'wasmoocaml:loaded' (and 'wasmoocaml:error' on failure) CustomEvents on globalThis so external code can wait for the runtime to be ready. Ported from ocaml-wasm/wasm_of_ocaml#143. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The free-variable check in compiler/bin-wasm_of_ocaml/gen/gen.ml flagged the new CustomEvent reference in runtime.js. CustomEvent is a standard DOM/Node global comparable to XMLHttpRequest and DOMException already in this list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b0ea27b to
e5fc28c
Compare
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.
Summary
DOMContentLoadedtherefore has no way to tell when the OCaml exports are actually ready.wasmoocaml:loaded(andwasmoocaml:erroron failure)CustomEvents onglobalThiswhen the asynchronous Wasm instantiation completes, so external code can wait for the runtime to be ready.CustomEventtocompiler/lib/reserved.mlso the free-variable check incompiler/bin-wasm_of_ocaml/gen/gen.mlaccepts the new reference (CustomEventjoins existing standard DOM globals likeXMLHttpRequest/DOMException).Test plan
make lint-jspasses (only an unrelated biome.json schema-version notice)dune build runtime/wasmsucceedsdune build compiler/lib compiler/lib-wasm compiler/bin-wasm_of_ocaml compiler/bin-js_of_ocaml runtimesucceeds (verifies the free-variable check acceptsCustomEvent)make tests— could not run locally; this switch lacksppx_expectand other test-only dependencies. CI should cover it.wasmoocaml:loadedevent fires onglobalThisafter the Wasm runtime finishes initializingwasmoocaml:errorevent fires before the error propagates🤖 Generated with Claude Code