Repository navigation
jsg: Match C++ JSG's TypeError messages in Rust JSG - #8754
Conversation
There was a problem hiding this comment.
Superseded by the review of
f3a28743.
This review, of 6933b029
✅ Approved — No issues found. The Illegal invocation message matches C++ JSG's kIllegalInvocation exactly, and the JsString rename only changes the text of the type error.
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
new_illegal_invocation() matches C++ JSG's kIllegalInvocation (src/workerd/jsg/resource.h:42-44). Every throw site that used the bare message has been updated, and the tests check the full message. The JsString::class_name() change affects only the type-error text, and the js_string test covers it.
📝 Documentation: ✅ LGTM
The doc comments match the code. No documentation needs updating.
Reviewed commit: 6933b029
A Rust JSG callback that V8 calls without a signature check (an accessor, an inspect property, a wildcard interceptor, a Fast API method) and that receives a wrong `this` threw "Illegal invocation". C++ JSG, and V8's signature check as patched in patches/v8, throw "Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details." So a method and an accessor of the same Rust resource threw different messages. Add jsg::Error::new_illegal_invocation(), with C++ JSG's message, and throw it from each of those callbacks. resource_this's wrong_this_throws_a_type_error now checks the whole message, for methods and accessors alike. Compatibility: no compatibility flag. Only the message of a TypeError changes, to the one C++ JSG and V8 already throw for the same mistake.
A missing jsg::JsString argument threw "parameter 1 is not of type 'string'". C++ JSG names a jsg::JsString parameter 'String', after v8::String, and a kj::String one 'string', so the Rust error differed from the C++ one for the same parameter. Name jsg::JsString 'String'; a String parameter stays 'string', as for kj::String. Compatibility: no change to the API surface exposed to Workers, none of whose Rust APIs takes a jsg::JsString yet.
6933b02 to
f3a2874
Compare
There was a problem hiding this comment.
✅ Approved — No issues found. The Illegal invocation message now matches C++ JSG's in every Rust callback that threw the bare text, and the JsString rename only changes the text of the type error.
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
Only the text of two TypeErrors changes. No check, control flow or input handling changes. The new message is a fixed string, and the throw sites still return early as they did before.
📋 Code Quality: ✅ LGTM
Every Rust throw site that used the bare "Illegal invocation" now calls Error::new_illegal_invocation(): the accessor and method paths, the constructor path, the wildcard interceptor and Fast API. Tests that check contains("Illegal invocation") still pass with the longer message. JsString::class_name() now returns "String". It is used only for the type-error text, and js_string.rs covers it.
📝 Documentation: ✅ LGTM
The doc comments match the code, and no documentation needs updating.
Reviewed commit: f3a28743
Two fixes that make Rust JSG's TypeError messages match C++ JSG's, split out of #8529.
jsg::Error::new_illegal_invocation()has C++ JSG's message, and each of those callbacks throws it.jsg::JsStringparameter 'String' and akj::Stringone 'string'. Rust JSG named both 'string'.Compatibility
No compatibility flag. The first commit changes only the message of a TypeError, to the one C++ JSG and V8 already throw for the same mistake. The second changes nothing Workers can see, since no Rust API exposed to them takes a
jsg::JsStringyet.Testing
resource_thischecks the whole Illegal invocation message for methods and accessors, andjs_stringchecks the 'String' name. The Rust JSG tests and compile tests pass.