Repository navigation
Name a missing MemoryCache key 'string' in the Rust MemoryCache - #8584
Conversation
There was a problem hiding this comment.
Superseded by the review of
58dd2c5a.
This review, of 24f1bb9f
✅ Approved — No issues found. The missing-key error now names 'string', and invalid keys are still thrown or rejected as before, depending on capture_async_api_throws.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
Key's FromJS gives 'string' as the type name, so a missing key and a non-string key both produce the C++-matching TypeError. The key bytes are the same as before (lone surrogates kept), OBJECT_CONVERSION_MAY_RUN_SCRIPT = false is right because only strings convert, and the removed key_bytes helper leaves no dead code behind. The test now covers calls with no argument for both read() and delete().
📝 Documentation: ✅ LGTM
The test's header comment, which says read() rejects under capture_async_api_throws and throws otherwise, is still accurate. For methods that return a promise, the method macro wraps argument conversion in jsg::capture_throws_as_rejection (src/rust/jsg-macros/lib.rs:570-580), so key conversion errors still reject under that flag. The doc comment on Key correctly describes how it relates to jsg::NonCoercible<kj::String> and how it holds the key as UTF-8.
Reviewed commit: 24f1bb9f
guybedford
left a comment
There was a problem hiding this comment.
LGTM. I checked locally that memory-cache-rust-test fails without the fix and passes with it, and that C++ and Rust agree for undefined, null, new String('k'), Symbol() and object keys on both read() and delete(). Three non-blocking nits inline.
The Rust MemoryCache took the key of read() and delete() as a raw `v8::Local<v8::Value>`, so that it could keep lone surrogates as `kj::String` does, and checked that it was a string itself. When the key was missing, though, the `#[jsg_method]` arity check rejected the call first, and it names the parameter after its Rust type: `env.CACHE.read()` failed with "parameter 1 is not of type 'Value'." where the C++ MemoryCache says 'string'. In this patch the key is a `Key` type whose `FromJS` accepts only a string, holds it as the same UTF-8 bytes, and is named 'string', as C++'s `jsg::NonCoercible<kj::String>` is. memory-cache-throws-test now calls read() and delete() without a key; it fails on the Rust MemoryCache without the fix.
24f1bb9 to
58dd2c5
Compare
There was a problem hiding this comment.
✅ Approved — No issues found: a missing MemoryCache key now gives a TypeError naming 'string', as the C++ MemoryCache does, key bytes are unchanged and the test covers calls with no argument.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
Key implements FromJS completely and reports 'string' as its type name. It keeps the original UTF-8 key bytes. Moving it into the try_catch closure is valid because that closure is FnOnce. The updated test covers calling read() and delete() with no argument.
📝 Documentation: ✅ LGTM
The doc comment on Key and the test header comment are accurate.
Reviewed commit: 58dd2c5a
The Rust MemoryCache took the key of
read()anddelete()as a rawv8::Local<v8::Value>, so that it could keep lone surrogates askj::Stringdoes, and checked that it was a string itself. When the key was missing, though, the#[jsg_method]arity check rejected the call first, and it names the parameter after its Rust type:env.CACHE.read()failed with "parameter 1 is not of type 'Value'." where the C++ MemoryCache says 'string'.In this patch the key is a
Keytype whoseFromJSaccepts only a string, holds it as the same UTF-8 bytes, and is named 'string', as C++'sjsg::NonCoercible<kj::String>is. memory-cache-throws-test now callsread()anddelete()without a key; it fails on the Rust MemoryCache without the fix.