feat: add bindings for v8::WasmModuleCompilation#1908
Merged
bartlomieju merged 6 commits intomainfrom Feb 19, 2026
Merged
Conversation
Expose the new experimental WasmModuleCompilation API from V8 14.6, which provides asynchronous WebAssembly module compilation without requiring a Promise-based streaming interface. This is intended for use cases like source phase imports. Bindings include: new, on_bytes_received, finish, abort, set_has_compiled_module_bytes, set_more_functions_can_be_serialized_callback, and set_url. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devsnek
reviewed
Feb 16, 2026
- Pass caching_callback directly to Finish instead of wrapping in a lambda - Capture isolate pointer in the Rust closure instead of threading it through the C++ resolution callback - Use a rule-of-five RustCallable class to track Box lifetime through std::function, preventing leaks if the callback is never invoked Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…pilation Replace RustCallable class with shared_ptr<void> to properly handle std::function copy semantics in V8's Finish method. The previous approach caused heap-use-after-free because V8 copies the std::function internally, and the RustCallable copy/destroy semantics couldn't coordinate ownership of the raw pointer across copies. Now the Rust closure data is reference-counted through shared_ptr copies, and the Rust side uses Option<Box<dyn FnOnce>> so the trampoline can .take() the closure without freeing the outer allocation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
devsnek
approved these changes
Feb 19, 2026
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
Add Rust bindings for the new experimental
v8::WasmModuleCompilationclass fromv8/include/v8-wasm.h, providing an interface for asynchronous WebAssembly module compilation (e.g. for source phase imports).Bindings provided
WasmModuleCompilation::new()/Default— create a new compilationon_bytes_received(&mut self, data: &[u8])— feed wasm bytes (callable from any thread)finish(self, scope, caching_callback, resolution_callback)— finalize compilation on the main thread; the resolution callback receivesResult<Local<WasmModuleObject>, Local<Value>>along with&Isolatefor creatingGlobalhandlesabort(self)— cancel compilationset_has_compiled_module_bytes(&mut self)— signal cached module bytes are availableset_more_functions_can_be_serialized_callback(...)— register a serialization callbackset_url(&mut self, url: &str)— set source URL before finishingDropcleans up the C++ allocation;Sendis implemented (V8 allows cross-thread usage)Implementation details
shared_ptr<void>with a custom deleter on the C++ side, which correctly handlesstd::functioncopy semantics when V8 internally copies the callback into itsResolverOption<Box<dyn FnOnce>>so the trampoline can.take()the closure (FnOnce semantics) without freeing the outer allocation, which is ref-counted byshared_ptrshared_ptr<void>patternTest plan
wasm_module_compilation— compiles a minimal wasm module, finishes, asserts the result viaGlobalhandlewasm_module_compilation_abort— compiles and aborts without finishing🤖 Generated with Claude Code