Add Lock::with_handle_scope() and with_escapable_handle_scope() to Rust JSG #8725
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 172 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.308
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8725"
general
weight: 0.35
bartlomieju
Rust JSG has no way to open a nested
v8::HandleScope: every handle aLockcreates lives until the callback's scope closes, so a loop thatcreates handles on every iteration, such as a benchmark calling a
function many times, grows the scope without bound. C++ opens a scope
per iteration for this, and uses
js.withinHandleScope()with av8::EscapableHandleScopeto build a value from many temporary handlesand keep only the result. This adds both to Rust JSG.
lock.with_handle_scope(|lock, _| ...)runs the closure in a newHandleScopewith a lock for that scope. Handles of the enclosingscope stay usable inside, but none of the new scope's can escape the
closure; the compiler enforces both.
lock.with_escapable_handle_scope(|lock, scope| ...)opens av8::EscapableHandleScope, andscope.escape(local)moves one handleinto the enclosing scope. Unlike C++, which escapes the callback's
return value by type, escaping is an explicit call, so the handle can
come back in a
jsg::ResultorOption.escape()consumesscope,since V8 only debug-checks a second escape and a release build would
overwrite the first handle.
A panic in either closure is resumed once the scope has closed, so it
never unwinds through C++. The jsg-test suite covers freeing handles,
escaping, nesting, pending exceptions and panics, and compile tests pin
the lifetime rules.