From 0697cde2198fa047e854a5c12cb99b5b245386ec Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sat, 19 Sep 2026 09:57:43 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20pending=5Flength=5Fexception=20=E7=99=BB?= =?UTF-8?q?=E8=AE=B0=20GC=20=E6=A0=B9=E9=81=8D=E5=8E=86=E4=B8=8E=E6=90=AC?= =?UTF-8?q?=E7=A7=BB=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/session_gc/tests.rs | 11 +++++++++++ crates/oxide_vm/src/vm/gc_hooks.rs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/crates/oxide_vm/src/session_gc/tests.rs b/crates/oxide_vm/src/session_gc/tests.rs index a081b604..f44b0342 100644 --- a/crates/oxide_vm/src/session_gc/tests.rs +++ b/crates/oxide_vm/src/session_gc/tests.rs @@ -40,6 +40,17 @@ fn uncaught_value_is_gc_root() { assert!(has_ptr(&roots, session)); } +#[test] +fn pending_length_exception_is_gc_root() { + let mut vm = Vm::new(); + let obj = plain_object(&mut vm); + let session = vm.promote_object(obj); + vm.pending_length_exception = Some(JsValue::from_js_object(session)); + let mut roots = Vec::new(); + vm.for_each_root(|v| roots.push(v)); + assert!(has_ptr(&roots, session)); +} + #[test] fn suspended_signal_fields_are_roots() { let mut vm = Vm::new(); diff --git a/crates/oxide_vm/src/vm/gc_hooks.rs b/crates/oxide_vm/src/vm/gc_hooks.rs index 156576a8..a2acaf21 100644 --- a/crates/oxide_vm/src/vm/gc_hooks.rs +++ b/crates/oxide_vm/src/vm/gc_hooks.rs @@ -53,6 +53,7 @@ impl Vm { f(self.exception_value.unwrap_or(JsValue::undefined())); f(self.pending_exception.unwrap_or(JsValue::undefined())); f(self.last_uncaught_value.unwrap_or(JsValue::undefined())); + f(self.pending_length_exception.unwrap_or(JsValue::undefined())); // 悬挂的 return 完成持有返回值,是 GC 根。 if let Some(Completion::Return { value, .. }) = self.pending_completion { f(value); @@ -118,6 +119,7 @@ impl Vm { self.exception_value = self.exception_value.map(&mut rewrite); self.pending_exception = self.pending_exception.map(&mut rewrite); self.last_uncaught_value = self.last_uncaught_value.map(&mut rewrite); + self.pending_length_exception = self.pending_length_exception.map(&mut rewrite); for cached in self.template_objects.values_mut() { *cached = rewrite(*cached); }