fix: 统一错误模型
This commit is contained in:
+11
-11
@@ -206,11 +206,13 @@ impl Vm {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !method.is_object() {
|
if !method.is_object() {
|
||||||
return Err(format!("TypeError: {method_name} is not callable"));
|
self.raise_error_kind("TypeError", &format!("{method_name} is not callable"))?;
|
||||||
|
return Ok(JsValue::undefined());
|
||||||
}
|
}
|
||||||
let method_ptr = method.as_js_object_ptr();
|
let method_ptr = method.as_js_object_ptr();
|
||||||
if method_ptr.is_null() || !unsafe { &*method_ptr }.is_function() {
|
if method_ptr.is_null() || !unsafe { &*method_ptr }.is_function() {
|
||||||
return Err(format!("TypeError: {method_name} is not callable"));
|
self.raise_error_kind("TypeError", &format!("{method_name} is not callable"))?;
|
||||||
|
return Ok(JsValue::undefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = self.call_function_sync(method, value, &[])?;
|
let result = self.call_function_sync(method, value, &[])?;
|
||||||
@@ -248,13 +250,7 @@ impl Vm {
|
|||||||
Ok(n.trunc().rem_euclid(4_294_967_296.0) as u32)
|
Ok(n.trunc().rem_euclid(4_294_967_296.0) as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pack_sync_native_call_args(
|
fn pack_sync_native_call_args(&mut self, receiver: JsValue, callee: JsValue, args: &[JsValue]) -> Vec<u8> {
|
||||||
&mut self, receiver: JsValue, callee: JsValue, args: &[JsValue],
|
|
||||||
) -> Result<Vec<u8>, String> {
|
|
||||||
if args.len() > Self::SYNC_NATIVE_ARG_LIMIT {
|
|
||||||
return Err("RangeError: Maximum call stack size exceeded".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
self.regs[253] = receiver;
|
self.regs[253] = receiver;
|
||||||
self.regs[254] = callee;
|
self.regs[254] = callee;
|
||||||
|
|
||||||
@@ -265,7 +261,7 @@ impl Vm {
|
|||||||
self.regs[reg as usize] = *arg;
|
self.regs[reg as usize] = *arg;
|
||||||
arg_regs.push(reg);
|
arg_regs.push(reg);
|
||||||
}
|
}
|
||||||
Ok(arg_regs)
|
arg_regs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_session_ptr(&self, obj_ptr: *mut JsObject) -> bool {
|
pub(crate) fn is_session_ptr(&self, obj_ptr: *mut JsObject) -> bool {
|
||||||
@@ -590,8 +586,12 @@ impl Vm {
|
|||||||
self.raise_error_kind("RangeError", "Maximum call stack size exceeded")?;
|
self.raise_error_kind("RangeError", "Maximum call stack size exceeded")?;
|
||||||
return Ok(JsValue::undefined());
|
return Ok(JsValue::undefined());
|
||||||
}
|
}
|
||||||
|
if args.len() > Self::SYNC_NATIVE_ARG_LIMIT {
|
||||||
|
self.raise_error_kind("RangeError", "Maximum call stack size exceeded")?;
|
||||||
|
return Ok(JsValue::undefined());
|
||||||
|
}
|
||||||
let saved_regs = self.regs;
|
let saved_regs = self.regs;
|
||||||
let arg_regs = self.pack_sync_native_call_args(receiver, callee, args)?;
|
let arg_regs = self.pack_sync_native_call_args(receiver, callee, args);
|
||||||
// SAFETY: native_fn was set via set_native_fn with a valid NativeFn pointer;
|
// SAFETY: native_fn was set via set_native_fn with a valid NativeFn pointer;
|
||||||
// native_fn_ptr_to_fn is the single coercion point for NativeFnPtr → NativeFn.
|
// native_fn_ptr_to_fn is the single coercion point for NativeFnPtr → NativeFn.
|
||||||
let func: NativeFn = unsafe { native_fn_ptr_to_fn(native_fn) };
|
let func: NativeFn = unsafe { native_fn_ptr_to_fn(native_fn) };
|
||||||
|
|||||||
Reference in New Issue
Block a user