refactor: match 可改 ? 的等价改写
This commit is contained in:
@@ -185,21 +185,17 @@ impl ShapeForge {
|
||||
let mut prop_steps: u32 = 0;
|
||||
let mut cursor = Some(shape_id);
|
||||
while let Some(id) = cursor {
|
||||
match shapes.get((id - 1) as usize).and_then(|s| s.clone()) {
|
||||
Some(s) => {
|
||||
if s.property_name != EMPTY_SENTINEL {
|
||||
if s.property_name == prop_name {
|
||||
let pos = total_depth.checked_sub(prop_steps + 1)?;
|
||||
drop(shapes);
|
||||
self.positions.insert(cache_key, pos);
|
||||
return Some(pos);
|
||||
}
|
||||
prop_steps += 1;
|
||||
}
|
||||
cursor = s.parent;
|
||||
let s = shapes.get((id - 1) as usize).and_then(|s| s.clone())?;
|
||||
if s.property_name != EMPTY_SENTINEL {
|
||||
if s.property_name == prop_name {
|
||||
let pos = total_depth.checked_sub(prop_steps + 1)?;
|
||||
drop(shapes);
|
||||
self.positions.insert(cache_key, pos);
|
||||
return Some(pos);
|
||||
}
|
||||
None => return None,
|
||||
prop_steps += 1;
|
||||
}
|
||||
cursor = s.parent;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@@ -105,16 +105,12 @@ impl ShapeStore {
|
||||
let mut step: u32 = 0;
|
||||
cursor = Some(shape_id);
|
||||
while let Some(id) = cursor {
|
||||
match self.get_shape(id) {
|
||||
Some(s) => {
|
||||
if s.property_name == prop_name && s.property_name != EMPTY_SENTINEL {
|
||||
return Some(total_depth - step - 1);
|
||||
}
|
||||
cursor = s.parent;
|
||||
step += 1;
|
||||
}
|
||||
None => return None,
|
||||
let s = self.get_shape(id)?;
|
||||
if s.property_name == prop_name && s.property_name != EMPTY_SENTINEL {
|
||||
return Some(total_depth - step - 1);
|
||||
}
|
||||
cursor = s.parent;
|
||||
step += 1;
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@@ -492,18 +492,14 @@ impl Vm {
|
||||
NativeResult::TailCall { callee, this, args } => {
|
||||
// 如 bound 函数:解析尾调用,用其返回值作为构造实例
|
||||
// (或回退到 derived_this)。
|
||||
match self.call_function_sync(callee, this, &args) {
|
||||
Ok(val) => {
|
||||
let instance = if val.is_object() { val } else { derived_this };
|
||||
if instance.is_object() {
|
||||
self.set_constructed_proto(instance, new_target_obj)?;
|
||||
}
|
||||
self.regs[254] = instance;
|
||||
self.regs[rd] = self.regs[254];
|
||||
self.mark_super_called();
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
let val = self.call_function_sync(callee, this, &args)?;
|
||||
let instance = if val.is_object() { val } else { derived_this };
|
||||
if instance.is_object() {
|
||||
self.set_constructed_proto(instance, new_target_obj)?;
|
||||
}
|
||||
self.regs[254] = instance;
|
||||
self.regs[rd] = self.regs[254];
|
||||
self.mark_super_called();
|
||||
}
|
||||
}
|
||||
} else if super_obj.sub_module_index() > 0 {
|
||||
|
||||
Reference in New Issue
Block a user