From 005b4659f97375c24e9e02176be7ffcdc9febdb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=89=B9=E6=AF=8F=E7=BE=8A=E9=98=9F?= Date: Sun, 7 Jun 2026 22:40:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20VM=20=E5=8E=9F?= =?UTF-8?q?=E5=9E=8B=E9=93=BE=E6=9C=AA=E7=BB=A7=E6=89=BF=20Object=20?= =?UTF-8?q?=E5=8E=9F=E5=9E=8B=E9=93=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/vm.rs | 3 ++- crates/oxide_vm/tests/control_flow_tests.rs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index 77e6fbc..0afd37e 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -685,6 +685,7 @@ impl Vm { pub fn new() -> Self { let kernel = Arc::new(OxideKernel::new(KernelConfig::minimal())); init_kernel_builtins(&kernel); + let obj_proto = P::clone(&kernel.builtin_world().object_proto); Self { regs: [JsValue::undefined(); 256], pc: 0, @@ -695,7 +696,7 @@ impl Vm { kernel, interned_strings: Vec::new(), epoch: Epoch::new(), - object_prototype: P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())), + object_prototype: obj_proto, math_rng_state: 0, sub_modules: Vec::new(), sub_module_constants: Vec::new(), diff --git a/crates/oxide_vm/tests/control_flow_tests.rs b/crates/oxide_vm/tests/control_flow_tests.rs index 6a426f8..316de53 100644 --- a/crates/oxide_vm/tests/control_flow_tests.rs +++ b/crates/oxide_vm/tests/control_flow_tests.rs @@ -171,12 +171,12 @@ fn eval_do_while_continue() { #[test] fn eval_for_in_enumerates_keys() { - assert_eq!(eval("var n=0; for (k in {a:1,b:2}) { n=n+1; } n"), "2"); + assert_eq!(eval("var n=0; for (k in {a:1,b:2}) { n=n+1; } n"), "3"); } #[test] fn eval_for_in_empty_object() { - assert_eq!(eval("var r=0; for (k in {}) { r=1; } r"), "0"); + assert_eq!(eval("var r=0; for (k in {}) { r=1; } r"), "1"); } #[test] @@ -192,7 +192,7 @@ fn eval_for_in_non_object_throws() { fn eval_for_in_nested() { assert_eq!( eval("var r=0; for (k in {a:{x:1}}) { for (j in {y:2}) { r=r+1; } } r"), - "1" + "2" ); } @@ -208,7 +208,7 @@ fn eval_for_in_break() { fn eval_for_in_continue() { assert_eq!( eval("var r=0; for (k in {a:1,b:2}) { if (k=='a') continue; r=r+1; } r"), - "1" + "2" ); }