Repository navigation
Support typed Rust resources for ctx.cache - #8544
Conversation
There was a problem hiding this comment.
Superseded by the review of
f180c04f.
This review, of 787ba3fc
💬 Approved with comments — The change looks correct and the hook fallback order is the same in both call sites. The only notes are two INFO items: test coverage of the Rust-backed path, and a doc comment that now sits above the wrong declaration.
Findings: 2 info (2 are inline comments on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: 💬 2 info
Two non-blocking notes: no test of the Rust-backed ctx.cache path, and a misplaced RustRef doc comment.
Recommendation: 💬 Optional Nits
- [INFO] No test exercises the Rust-backed CacheContextRef path: wrap and unwrap of RustCacheContext, Rust hook tried before the C++ hook, and isInstance delegation. (
src/workerd/api/cache-context-ref.h:34) - [INFO] The RustRef doc comment now sits above RustRefRtti instead of RustRef, and the Tag contract does not mention JsgRttiDelegate. (
src/rust/jsg-cpp/jsg-cpp.h:208)
View full review
- Test coverage: the new tests cover three things:
ctx.cacheisundefinedwith no embedder, RTTI delegation, andset_prototype. No test covers theRustCacheContextbranch ofCacheContextRef::jsgWrap/jsgTryUnwrap, the rule that the Rust hook is tried before the C++ hook, orCacheContextTag::isInstance. The isolate insrc/rust/jsg-testalready registersRustResourceWrapperand could host such a test. - Doc comment placement:
RustRefRttiwas inserted between the longRustRef<Tag>doc comment andclass RustRef, so the comment now reads as documentation for the helper. TheTagcontract also does not mention the optionalJsgRttiDelegate.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No performance issues found.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 787ba3fc
guybedford
left a comment
There was a problem hiding this comment.
The typed ctx.cache plumbing looks right to me. One real issue in set_prototype's failure handling, plus a few small things inline.
There was a problem hiding this comment.
Superseded by the review of
a0d6225d.
This review, of f180c04f
✅ Approved — No open findings: the earlier notes are fixed or explained, the set_prototype refusal handling now produces a TypeError, and ctx.cache resolves through a single helper.
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 issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The set_prototype shim now tells a refused change from a pending exception. The fallback order lives in currentCacheContext(). The RustRefRtti and Tag contract docs are corrected. RTTI delegation matches the BuildRtti specialization, and the only isolate that uses the global-scope types now registers the needed extension.
⚡ Performance: ✅ LGTM
The ctx.cache lookup adds one virtual call, which returns none when there is no embedder. The set_prototype shim is a single V8 call.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: f180c04f
There was a problem hiding this comment.
Superseded by the review of
0fb980e8.
This review, of a0d6225d
✅ Approved — No findings: since the last approved review, the only changes are behaviour-preserving clippy and clang-tidy fixes in jsg-cpp.h and v8.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 issues found. Standalone workerd still resolves ctx.cache to undefined.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The RustRefRtti alias is valid C++23 without typename, and the void_t specialization still forwards JsgRttiDelegate only when the tag declares one. set_prototype taking Option<Self> converts to Local<Value> through the existing cast. Its match arms follow the shim's contract: a successful change returns Ok, a refused change becomes a TypeError, and a pending exception or termination is propagated.
⚡ Performance: ✅ LGTM
Resolving ctx.cache costs one extra virtual call, which returns none when no embedder supplies a Rust resource. set_prototype is a single V8 call.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: a0d6225d
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8544 +/- ##
==========================================
- Coverage 67.76% 67.75% -0.02%
==========================================
Files 848 849 +1
Lines 216079 216156 +77
Branches 32540 32553 +13
==========================================
+ Hits 146426 146448 +22
- Misses 50441 50487 +46
- Partials 19212 19221 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Waiting on #8617 |
ae7ddac to
0fb980e
Compare
There was a problem hiding this comment.
Superseded by the review of
e86fb61c.
This review, of 0fb980e8
✅ Approved — No findings. Since the last approved review, the only changes are a test-module registration and a header include that the new CacheContextRef return type needs.
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 issues. The default Worker::Api hooks return none and false, so standalone workerd still resolves ctx.cache to undefined. Both ctx.cache paths check IoContext::hasCurrent() before they call the embedder hooks.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
mod set_prototype; registers the new set_prototype.rs tests. The new #include "cache-context-ref.h" in global-scope.h is required because ExecutionContext::getCache now returns jsg::Optional<CacheContextRef>, and it matches the definition in global-scope.c++.
⚡ Performance: ✅ LGTM
Resolving ctx.cache adds one virtual call, which returns none when no embedder supplies a Rust resource. set_prototype makes a single V8 call.
📝 Documentation: ✅ LGTM
No documentation issues found.
Reviewed commit: 0fb980e8
We are migrating the `ctx.cache` API (`CacheContext`) from C++ to Rust JSG. The implementation lives in an internal project that embeds workerd and supplies it through `Worker::Api::getCtxCacheProperty()`, but that hook can only return a C++ `jsg::Ref<CacheContext>`. This change lets the embedder return a typed Rust JSG resource instead, so the Rust implementation can replace the C++ one without changing what Workers see: `ctx.cache` keeps its `CacheContext` TypeScript declaration, and standalone workerd still returns `undefined`. - `RustRef<Tag>` delegates its RTTI to `Tag::JsgRttiDelegate` when the tag declares one, so a Rust resource returned from a C++ JSG API keeps the TypeScript shape of an existing C++ type. - `Worker::Api` gains `getCtxCacheRustProperty()` and `isCtxCacheRustInstance()`. `ctx.cache` on both `ExecutionContext` and the `cloudflare:workers` entrypoints module resolves through `currentCacheContext()`, which tries the Rust hook first and then the C++ hook. The C++ hook stays until the embedder finishes migrating. - Rust JSG gains `Local<Object>::set_prototype()`, so a flat Rust resource can link its prototype to a parent in each realm without C++ JSG inheritance. A refused change (a cycle, a non-extensible object, or a Proxy trap that refused or threw) is a `TypeError`.
0fb980e to
e86fb61
Compare
There was a problem hiding this comment.
✅ Approved — No findings. Since the last approved review, the only changes are a test-module registration and the includes and wrapper registration that the new CacheContextRef return type needs.
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 issues found.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
RustResourceWrapper is registered in JSG_WORKERD_ISOLATE_TYPES, and the jsg-cpp:ffi dependency is added to the api test, io and server targets. The default Worker::Api hooks return none and false, so standalone workerd still resolves ctx.cache to undefined, which global-scope-test.js checks. The set_prototype shim checks exceptionPending both before and after the V8 call.
⚡ Performance: ✅ LGTM
Resolving ctx.cache adds one virtual call to the Rust hook, which returns none in standalone workerd. set_prototype makes a single V8 call.
📝 Documentation: ✅ LGTM
No documentation issues found in the changed files.
Reviewed commit: e86fb61c
We are migrating the
ctx.cacheAPI (CacheContext) from C++ to Rust JSG. The implementation lives in an internal project that embeds workerd and supplies it throughWorker::Api::getCtxCacheProperty(), but that hook can only return a C++jsg::Ref<CacheContext>. This change lets the embedder return a typed Rust JSG resource instead, so the Rust implementation can replace the C++ one without changing what Workers see:ctx.cachekeeps itsCacheContextTypeScript declaration, and standalone workerd still returnsundefined.RustRef<Tag>delegates its RTTI toTag::JsgRttiDelegatewhen the tag declares one, so a Rust resource returned from a C++ JSG API keeps the TypeScript shape of an existing C++ type.Worker::ApigainsgetCtxCacheRustProperty()andisCtxCacheRustInstance().ctx.cacheon bothExecutionContextand thecloudflare:workersentrypoints module resolves throughcurrentCacheContext(), which tries the Rust hook first and then the C++ hook. The C++ hook stays until the embedder finishes migrating.Local<Object>::set_prototype(), so a flat Rust resource can link its prototype to a parent in each realm without C++ JSG inheritance. A refused change (a cycle, a non-extensible object, or a Proxy trap that refused or threw) is aTypeError.