mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 18:51:13 +08:00
fix: clear_transient 补清 overflow 态(id 空间完整复位)+ kernel 增加 active_vms 计数,sweep/重建/kernel-drop 三处 debug_assert 守卫'清空时点无存活 VM'
This commit is contained in:
@@ -571,6 +571,8 @@ pub struct Vm {
|
||||
|
||||
impl Drop for Vm {
|
||||
fn drop(&mut self) {
|
||||
// 边界守卫计数:与构造器登记恰好配对(Rust 所有权保证恰好一次)。
|
||||
self.kernel_core.note_vm_ended();
|
||||
// 直接 drop(test262 每测试新建即弃)不经 reset/full_reset 路径:
|
||||
// 统一收尾释放全部 session 堆数据与内建原型属性区,防逐测试累积泄漏。
|
||||
self.teardown_intrinsic_protos();
|
||||
|
||||
@@ -145,6 +145,8 @@ impl Vm {
|
||||
vm.init_async_generator_intrinsics();
|
||||
// Promise 全局绑定发生在快照采集之后,重录快照避免首次 full_reset 误判脏。
|
||||
vm.session.record_snapshot();
|
||||
// 边界守卫计数:VM 完整构造后登记,与 `Drop for Vm` 的注销恰好配对。
|
||||
vm.kernel_core.note_vm_started();
|
||||
vm_info!("Vm created");
|
||||
vm
|
||||
}
|
||||
@@ -260,6 +262,8 @@ impl Vm {
|
||||
vm.init_async_generator_intrinsics();
|
||||
// Promise 全局绑定发生在快照采集之后,重录快照避免首次 full_reset 误判脏。
|
||||
vm.session.record_snapshot();
|
||||
// 边界守卫计数:VM 完整构造后登记,与 `Drop for Vm` 的注销恰好配对。
|
||||
vm.kernel_core.note_vm_started();
|
||||
vm_info!("Vm created (pool)");
|
||||
vm
|
||||
}
|
||||
@@ -820,6 +824,38 @@ mod tests {
|
||||
vm.run(&module).expect("vm run failed")
|
||||
}
|
||||
|
||||
/// 计数往返:两条构造路径(独立核/共享核)的登记与 Drop 注销恰好配对,
|
||||
/// 全部 drop 后计数归零,kernel 可干净 drop(Drop 断言无残留)。
|
||||
#[test]
|
||||
fn active_vms_count_roundtrip() {
|
||||
let vm = Vm::new();
|
||||
assert_eq!(vm.kernel_core.active_vms(), 1);
|
||||
drop(vm);
|
||||
|
||||
let core = KernelCore::new(KernelConfig::minimal());
|
||||
assert_eq!(core.active_vms(), 0);
|
||||
let v1 = Vm::with_kernel_core(Arc::clone(&core));
|
||||
let v2 = Vm::with_kernel_core(Arc::clone(&core));
|
||||
let v3 = Vm::with_kernel_core(Arc::clone(&core));
|
||||
assert_eq!(core.active_vms(), 3);
|
||||
drop(v3);
|
||||
assert_eq!(core.active_vms(), 2);
|
||||
drop(v1);
|
||||
drop(v2);
|
||||
assert_eq!(core.active_vms(), 0);
|
||||
drop(core);
|
||||
}
|
||||
|
||||
/// 守卫判别:持活 VM 调 sweep 触发 debug_assert。VM 声明在 kernel 之后,
|
||||
/// panic unwind 时先注销计数再 drop kernel,drop 断言不受干扰。
|
||||
#[test]
|
||||
#[cfg_attr(debug_assertions, should_panic(expected = "no live VMs"))]
|
||||
fn sweep_runner_forges_rejects_live_vm() {
|
||||
let core = KernelCore::new(KernelConfig::minimal());
|
||||
let _vm = Vm::with_kernel_core(Arc::clone(&core));
|
||||
core.sweep_runner_forges();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn full_reset_with_session_objects_forces_global_rebuild() {
|
||||
let mut vm = Vm::new();
|
||||
|
||||
Reference in New Issue
Block a user