Repository navigation
Rust JSG: support WebAssembly.Module handles - #8616
Conversation
Both harnesses created their V8System lazily, on the first thread that needed it. On Linux x86-64, V8 guards JIT memory such as the WebAssembly code pointer table with a memory protection key, and only the thread that creates the platform, and threads it later creates, get access to that key. The Rust test harness runs tests on threads spawned from the main thread, so the main thread, which disposes V8 from static destructors at exit, had no access. Once a test had compiled WebAssembly, V8::Dispose() faulted with SEGV_PKUERR in WasmCodePointerTable::SweepSegments. Construct V8System at namespace scope instead, as the C++ JSG tests and benchmarks do, so V8 starts and stops on the main thread.
Rust JSG had no handle type for WebAssembly.Module. Add the WasmModuleObject marker type, accepted as an exact-type parameter, in unions and in Global/TracedGlobal like the other handle types, and Local<WasmModuleObject>::compiled_module(), which returns an owned v8::CompiledWasmModule. It exposes the module's wire bytes and can be handed to C++ to make a module object in another isolate without recompiling. It is Send + Sync and must be dropped before V8 is disposed. The Rust port of the Worker Loader binding needs this for the WebAssembly.Module values in WorkerCode.modules.
There was a problem hiding this comment.
Superseded by the review of
23196725.
This review, of f5d6967e
✅ Approved — No issues found. The new handle type and its compiled-module accessor are wired in consistently and well tested, and the harness change starts V8 on the main thread as the C++ JSG tests do.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
No defects found:
- Harnesses:
V8Systemis now constructed at namespace scope in both harnesses, and the lazy accessors are removed cleanly. - Handle type:
WasmModuleObjectis integrated throughout the handle machinery. CompiledWasmModule: ownership crosses the FFI boundary as akj::Own, and the empty wire-bytes case is handled.- Tests: coverage is thorough.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The README update matches the new handle type.
Reviewed commit: f5d6967e
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8616 +/- ##
==========================================
- Coverage 67.03% 67.01% -0.02%
==========================================
Files 799 799
Lines 206639 206765 +126
Branches 32062 32072 +10
==========================================
+ Hits 138519 138569 +50
- Misses 49323 49394 +71
- Partials 18797 18802 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…sm-module-object # Conflicts: # src/rust/jsg/wrappable.rs
There was a problem hiding this comment.
Superseded by the review of
5cc510ef.
This review, of 23196725
✅ Approved — No issues found. The merge-resolved wrappable.rs registrations and the test harness's namespace-scope V8System are consistent with the rest of the change.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
- A value that is not a
WebAssembly.Moduleis rejected by the type check beforecompiled_module()is reached. - The empty wire-bytes case is handled.
- The harness change affects only the test and benchmark binaries.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates needed.
📋 Code Quality: ✅ LGTM
No defects found in the code changed since the last review.
src/rust/jsg-test/ffi.c++:V8Systemnow lives at namespace scope, and everyTestIsolateconstruction site uses it. The new shims only call into V8 orLock.src/rust/jsg/wrappable.rs:CompiledWasmModuleandWasmModuleObjectare registered the same way as the neighbouring handle types.
⚡ Performance: ✅ LGTM
No performance concerns.
- Getting the compiled module makes one small allocation per call.
- Reading the wire bytes returns a view into the existing bytes without copying them.
📝 Documentation: ✅ LGTM
The README update matches the new handle type.
Reviewed commit: 23196725
On Linux x86-64, V8 grants access to the memory protection key that guards its JIT memory only to the thread that starts it and the threads that thread creates, and dropping the last reference to a module's compiled code frees entries in the protected code pointer table. Say so instead of claiming any thread will do, and keep the test harness comment to the requirement it states.
There was a problem hiding this comment.
Superseded by the review of
b8787062.
This review, of 5cc510ef
✅ Approved — No issues found. The changes since the last review (the V8System setup in the harnesses, the new test shims and the narrowed comment on where a CompiledWasmModule may be dropped) are correct and consistent with the rest of the change.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
compiled_module()can only be reached after theWebAssembly.Moduletype check, so a value of another type never gets there.- Reading the wire bytes returns a view into bytes the module owns.
- The harness changes affect only the test and benchmark binaries.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates are needed.
📋 Code Quality: ✅ LGTM
I found no defects in src/rust/jsg-test/ffi.c++, src/rust/jsg/ffi.h or src/rust/jsg/v8.rs.
- Harness startup:
V8Systemis built at namespace scope in both harnesses, and every isolate constructor passes it in. KjOwn<CompiledWasmModule>drop: the bridge inv8.rsgenerates the drop function.- Empty wire bytes: they return an empty slice instead of a slice built from a possibly null pointer.
- Tests: they cover conversion, rejection of other values, unions, struct fields, wire bytes, and a compiled module that outlives its isolate.
⚡ Performance: ✅ LGTM
No performance concerns.
compiled_module()makes one small allocation per call.wire_bytes()returns a view into the existing bytes without copying them.
📝 Documentation: ✅ LGTM
The README and the doc comments match the new handle type and the thread requirement for dropping a CompiledWasmModule.
Reviewed commit: 5cc510ef
There was a problem hiding this comment.
✅ Approved — No issues found. The test update since the last review is consistent with the error format in wrappable.rs.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
- Type check:
compiled_module()can only be reached after theWebAssembly.Moduletype check. - Wire bytes:
wire_bytes()returns a view into bytes the module owns, and an empty slice when there are no bytes. - Harness changes: These affect only the test and benchmark binaries.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md updates are needed.
📋 Code Quality: ✅ LGTM
I found no defects in src/rust/jsg-test/tests/wasm_module_object.rs.
- Helpers: The helper signatures match how the tests call them.
- Error message: The expected error message matches the
"Expected {} but got {type_name}"format inwrappable.rs. - Drop thread: The test where a compiled module outlives its isolate drops the last
CompiledWasmModuleon a thread allowed by the drop-thread contract documented inv8.rs.
⚡ Performance: ✅ LGTM
No performance concerns.
compiled_module()makes one small allocation per call.wire_bytes()returns a view into the module's bytes without copying them.- The harness now starts V8 once, so it adds no per-test cost.
📝 Documentation: ✅ LGTM
The README and the doc comments match the new handle type and the thread requirement for dropping a CompiledWasmModule.
Reviewed commit: b8787062
Rust JSG had no handle type for
WebAssembly.Module;v8.rslistedWasmModuleObjectas deliberately unimplemented because nothingneeded it. The Rust port of the Worker Loader binding does:
WorkerCode.modulesacceptsWebAssembly.Modulevalues, and C++hands their compiled code to the new isolate without recompiling. This
adds the
WasmModuleObjecthandle type andLocal<WasmModuleObject>::compiled_module(), which returns an owned,Send + SyncCompiledWasmModule.The first commit fixes the jsg-test and jsg-bench harnesses, which
started V8 lazily on a test thread. That left the main thread without
access to V8's memory protection key, so
V8::Dispose()crashed atexit once a test had compiled WebAssembly (Linux x86-64 only).
V8Systemis now constructed at namespace scope, as in the C++ JSGtests.