From 4fdf190202a783483c61c1fe3bedb432a0c97683 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: Sat, 6 Jun 2026 21:11:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20array=20=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E6=BA=A2=E5=87=BA=E6=97=B6=E5=88=86=E9=85=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_types/src/object.rs | 22 +++++++++++++++------- crates/oxide_vm/src/vm.rs | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/oxide_types/src/object.rs b/crates/oxide_types/src/object.rs index 15821d7..e03dc06 100644 --- a/crates/oxide_types/src/object.rs +++ b/crates/oxide_types/src/object.rs @@ -36,19 +36,26 @@ impl JsObject { } } - pub fn new_array(shape_id: ShapeId, proto: JsValue, n_elements: usize) -> Self { - assert!( - n_elements <= 4, - "arrays with >4 inline elements not yet supported" - ); - Self { + pub fn new_array( + shape_id: ShapeId, + proto: JsValue, + n_elements: usize, + bump: &bumpalo::Bump, + ) -> Self { + let mut obj = Self { header: (shape_id & 0x00FF_FFFF) | (1 << 30) | (1 << 29), inline: [JsValue::undefined(); 4], overflow: std::ptr::null_mut(), proto, generation: 1, _pad: 0, + }; + let count = (n_elements as u8).min(31); + obj.set_prop_count(count); + if n_elements > 4 { + obj.alloc_overflow(bump, n_elements); } + obj } pub fn shape_id(&self) -> ShapeId { @@ -255,7 +262,8 @@ mod tests { #[test] fn new_array_flags() { - let obj = JsObject::new_array(5, JsValue::null(), 3); + let bump = bumpalo::Bump::new(); + let obj = JsObject::new_array(5, JsValue::null(), 3, &bump); assert!(obj.is_array()); assert_eq!(obj.shape_id(), 5); } diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index 6772270..3fd8b80 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -544,10 +544,12 @@ impl Vm { OpCode::NEW_ARRAY => { let proto_ptr = &*self.object_prototype as *const JsObject as *mut JsObject; let n = opcode::imm16(instr) as usize; + let bump = self.epoch.bump(); let obj = self.epoch.alloc(JsObject::new_array( EMPTY_SHAPE_ID, JsValue::from_js_object(proto_ptr), n, + bump, )); self.regs[rd] = JsValue::object(obj as *mut u8); }