feat: 支持编译对象构造并统一属性字段名获取
This commit is contained in:
+20
-22
@@ -313,8 +313,7 @@ impl Vm {
|
||||
return Err("GET_PROP on non-object".into());
|
||||
}
|
||||
let obj = unsafe { &*obj_ptr };
|
||||
let prop_val = self.constants[opcode::imm16(instr) as usize];
|
||||
let prop_name_si = prop_val.as_string_index();
|
||||
let prop_name_si = self.regs[b].as_string_index();
|
||||
if let Some(offset) = shape::lookup_offset(obj.shape_id(), prop_name_si) {
|
||||
self.regs[a] = obj.get_prop(offset);
|
||||
} else {
|
||||
@@ -322,6 +321,25 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
OpCode::SET_PROP => {
|
||||
let obj_ptr = self.regs[rd].as_object_ptr() as *mut JsObject;
|
||||
if obj_ptr.is_null() {
|
||||
return Err("SET_PROP on non-object".into());
|
||||
}
|
||||
let obj = unsafe { &mut *obj_ptr };
|
||||
let prop_name_si = self.regs[b].as_string_index();
|
||||
if let Some(offset) = shape::lookup_offset(obj.shape_id(), prop_name_si) {
|
||||
obj.set_prop(offset, self.regs[a]);
|
||||
} else {
|
||||
let new_offset = obj.prop_count();
|
||||
let new_shape_id = shape::make_shape(obj.shape_id(), prop_name_si);
|
||||
obj.set_shape_id(new_shape_id);
|
||||
obj.set_prop_count(new_offset + 1);
|
||||
obj.set_prop(new_offset, self.regs[a]);
|
||||
obj.bump_generation();
|
||||
}
|
||||
}
|
||||
|
||||
OpCode::GET_PROP_DYNAMIC => {
|
||||
let obj_ptr = self.regs[rd].as_object_ptr() as *mut JsObject;
|
||||
if obj_ptr.is_null() {
|
||||
@@ -340,26 +358,6 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
|
||||
OpCode::SET_PROP => {
|
||||
let obj_ptr = self.regs[rd].as_object_ptr() as *mut JsObject;
|
||||
if obj_ptr.is_null() {
|
||||
return Err("SET_PROP on non-object".into());
|
||||
}
|
||||
let obj = unsafe { &mut *obj_ptr };
|
||||
let prop_val = self.constants[opcode::imm16(instr) as usize];
|
||||
let prop_name_si = prop_val.as_string_index();
|
||||
if let Some(offset) = shape::lookup_offset(obj.shape_id(), prop_name_si) {
|
||||
obj.set_prop(offset, self.regs[a]);
|
||||
} else {
|
||||
let new_offset = obj.prop_count();
|
||||
let new_shape_id = shape::make_shape(obj.shape_id(), prop_name_si);
|
||||
obj.set_shape_id(new_shape_id);
|
||||
obj.set_prop_count(new_offset + 1);
|
||||
obj.set_prop(new_offset, self.regs[a]);
|
||||
obj.bump_generation();
|
||||
}
|
||||
}
|
||||
|
||||
OpCode::SET_PROP_DYNAMIC => {
|
||||
let obj_ptr = self.regs[rd].as_object_ptr() as *mut JsObject;
|
||||
if obj_ptr.is_null() {
|
||||
|
||||
Reference in New Issue
Block a user