Repository navigation
Correct Rust JSG's escapable scope docs and test its invariants - #8783
Conversation
The docs for Lock::with_escapable_handle_scope() compare it to a C++ js.runInHandleScope() callback, but jsg::Lock has no such function; the C++ counterpart is js.withinHandleScope(). This fixes the name in scope.rs, the jsg README and src/rust/AGENTS.md. EscapableScope::escape() consumes its scope because a v8::EscapableHandleScope has a single escape slot. V8 checks a second escape only in debug builds; in a release build the second escape overwrites the slot and so retargets the first escaped handle. The SAFETY comment and the type's docs now say so, since this is what makes the type's lack of Clone a soundness requirement rather than a convenience. The escape-once compile test now also checks that the scope can't be cloned, so deriving Clone on it fails a test. escape() also accepts a handle of a scope nested in the escapable one, because EscapableScope is covariant in its inner lifetime. That's sound: V8 copies the value into a slot it reserved in the enclosing scope when the escapable scope opened. The docs of escape() now state it, and a new test escapes a handle created in a nested scope and reads it after both scopes close.
There was a problem hiding this comment.
Superseded by the review of
0babb64f.
This review, of 63aba2d5
💬 Approved with comments — The doc fix and the new tests are correct. One question remains about whether V8 checks a second escape only in debug builds, which the new text states as fact.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The rename and the new tests are correct; one question about the new statement on V8's release-build behaviour.
Recommendation: 💬 Optional Nits
- [QUESTION] Please check against the pinned V8 version that a second
EscapableHandleScope::Escape()is checked only in debug builds and overwrites the first escaped handle in release builds. Older V8 guarded this with anApiCheckthat stays on in release builds. The same claim appears in the SAFETY comment, the compile-test header and the README. (src/rust/jsg/scope.rs:157)
View full review
The rename to js.withinHandleScope() matches src/workerd/jsg/jsg.h. The nested-scope escape test covers the new doc statement that a handle from a nested scope can be escaped. The cloned compile-fail case checks that EscapableScope has no Clone.
The same claim now appears in four places: the EscapableScope doc, the SAFETY comment in escape, the compile-test header and the README. It says V8 only debug-checks a second Escape() and that a release build silently overwrites the first escaped handle. Older V8 guarded the escape slot with Utils::ApiCheck(..., "Escape value set twice"), and that check stays on in release builds. The V8 sources aren't in this snapshot, so I couldn't check which behaviour the pinned version has.
✅ All other checks passed
📝 Documentation: ✅ LGTM
The doc changes in scope.rs, the jsg README and src/rust/AGENTS.md now name the right C++ function.
Reviewed commit: 63aba2d5
There was a problem hiding this comment.
💬 Approved with comments — The doc fix and the new tests are correct. One question remains about whether V8 checks a second escape only in debug builds, which the new text states as fact.
Findings: 1 question
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📋 Code Quality: ❓ 1 question
The rename and the new tests are correct; one question about the new statement on V8's release-build behaviour.
Recommendation: 💬 Optional Nits
- [QUESTION] Please check against the pinned V8 version that a second
EscapableHandleScope::Escape()is checked only in debug builds and overwrites the first escaped handle in release builds. Older V8 guarded this with anApiCheckthat stays on in release builds. The same claim appears in the SAFETY comment, the compile-test header and the README. (src/rust/jsg/scope.rs:157)
View full review
The rename to js.withinHandleScope() matches src/workerd/jsg/jsg.h. The nested-scope escape test covers the new doc statement that a handle from a nested scope can be escaped. The cloned compile-fail case checks that EscapableScope has no Clone.
The same claim now appears in four places: the EscapableScope doc, the SAFETY comment in escape, the compile-test header and the README. It says V8 only debug-checks a second Escape() and that a release build silently overwrites the first escaped handle. Older V8 guarded the escape slot with Utils::ApiCheck(..., "Escape value set twice"), and that check stays on in release builds. The V8 sources aren't in this snapshot, so I couldn't check which behaviour the pinned version has.
✅ All other checks passed
📝 Documentation: ✅ LGTM
The doc changes in scope.rs, the jsg README and src/rust/AGENTS.md now name the right C++ function.
Reviewed commit: 0babb64f — same changes as 63aba2d5, so this is that commit's review (no new review was run; line numbers are as of 63aba2d5)
Missed in #8725