mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
refactor: 统一错误对象构造与异常类型传播
This commit is contained in:
@@ -36,34 +36,41 @@ fn create_error_object(vm: &mut Vm, error_proto_ptr: *mut JsObject, name: &str,
|
|||||||
JsValue::from_js_object(obj)
|
JsValue::from_js_object(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_kind_error(vm: &mut Vm, kind: &str, msg: &str) -> JsValue {
|
||||||
|
let proto_ptr = match kind {
|
||||||
|
"TypeError" => P::as_ptr(&vm.session().builtin_world().type_error_proto) as *mut JsObject,
|
||||||
|
"RangeError" => P::as_ptr(&vm.session().builtin_world().range_error_proto) as *mut JsObject,
|
||||||
|
"ReferenceError" => P::as_ptr(&vm.session().builtin_world().reference_error_proto) as *mut JsObject,
|
||||||
|
"SyntaxError" => P::as_ptr(&vm.session().builtin_world().syntax_error_proto) as *mut JsObject,
|
||||||
|
"URIError" => P::as_ptr(&vm.session().builtin_world().uri_error_proto) as *mut JsObject,
|
||||||
|
"EvalError" => P::as_ptr(&vm.session().builtin_world().eval_error_proto) as *mut JsObject,
|
||||||
|
_ => P::as_ptr(&vm.session().builtin_world().error_proto) as *mut JsObject,
|
||||||
|
};
|
||||||
|
create_error_object(vm, proto_ptr, kind, msg)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_type_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_type_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().type_error_proto) as *mut JsObject;
|
create_kind_error(vm, "TypeError", msg)
|
||||||
create_error_object(vm, proto_ptr, "TypeError", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().error_proto) as *mut JsObject;
|
create_kind_error(vm, "Error", msg)
|
||||||
create_error_object(vm, proto_ptr, "Error", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_reference_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_reference_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().reference_error_proto) as *mut JsObject;
|
create_kind_error(vm, "ReferenceError", msg)
|
||||||
create_error_object(vm, proto_ptr, "ReferenceError", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_range_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_range_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().range_error_proto) as *mut JsObject;
|
create_kind_error(vm, "RangeError", msg)
|
||||||
create_error_object(vm, proto_ptr, "RangeError", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_syntax_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_syntax_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().syntax_error_proto) as *mut JsObject;
|
create_kind_error(vm, "SyntaxError", msg)
|
||||||
create_error_object(vm, proto_ptr, "SyntaxError", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_uri_error(vm: &mut Vm, msg: &str) -> JsValue {
|
pub fn create_uri_error(vm: &mut Vm, msg: &str) -> JsValue {
|
||||||
let proto_ptr = P::as_ptr(&vm.session().builtin_world().uri_error_proto) as *mut JsObject;
|
create_kind_error(vm, "URIError", msg)
|
||||||
create_error_object(vm, proto_ptr, "URIError", msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_msg(vm: &mut Vm, args: &[u8]) -> String {
|
fn get_msg(vm: &mut Vm, args: &[u8]) -> String {
|
||||||
@@ -137,7 +144,7 @@ pub fn error_to_string(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
} else {
|
} else {
|
||||||
("Error".to_string(), String::new())
|
("Error".to_string(), String::new())
|
||||||
};
|
};
|
||||||
let result = if msg.is_empty() { name } else { format!("{}: {}", name, msg) };
|
let result = crate::vm::format_error_message(&name, &msg);
|
||||||
let si = vm.kernel_core().string_forge().intern(&result).0;
|
let si = vm.kernel_core().string_forge().intern(&result).0;
|
||||||
NativeResult::Ok(JsValue::string(si, 0))
|
NativeResult::Ok(JsValue::string(si, 0))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ pub fn object_assign(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
let target_val = vm.reg(args[1]);
|
let target_val = vm.reg(args[1]);
|
||||||
let target_val = match coercion::to_object(target_val, vm) {
|
let target_val = match coercion::to_object(target_val, vm) {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(msg) => return NativeResult::Err(crate::builtins::error::create_type_error(vm, msg)),
|
Err(msg) => return NativeResult::Err(crate::builtins::error::create_type_error(vm, &msg)),
|
||||||
};
|
};
|
||||||
let target_ptr = target_val.as_js_object_ptr();
|
let target_ptr = target_val.as_js_object_ptr();
|
||||||
if target_ptr.is_null() {
|
if target_ptr.is_null() {
|
||||||
|
|||||||
@@ -6,28 +6,22 @@ use crate::coercion;
|
|||||||
use crate::native::NativeResult;
|
use crate::native::NativeResult;
|
||||||
use crate::vm::Vm;
|
use crate::vm::Vm;
|
||||||
|
|
||||||
fn get_regexp_ptr(vm: &Vm, args: &[u8]) -> Result<*mut JsObject, JsValue> {
|
fn get_regexp_ptr(vm: &mut Vm, args: &[u8]) -> Result<*mut JsObject, JsValue> {
|
||||||
let this_val = vm.reg(args[0]);
|
let this_val = vm.reg(args[0]);
|
||||||
if !this_val.is_object() {
|
if !this_val.is_object() {
|
||||||
return Err(JsValue::string(
|
return Err(crate::builtins::error::create_type_error(
|
||||||
vm.kernel_core()
|
vm,
|
||||||
.string_forge()
|
"RegExp.prototype method called on non-object",
|
||||||
.intern("TypeError: RegExp.prototype method called on non-object")
|
|
||||||
.0,
|
|
||||||
0,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let ptr = this_val.as_js_object_ptr();
|
let ptr = this_val.as_js_object_ptr();
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
return Err(JsValue::string(vm.kernel_core().string_forge().intern("TypeError: null object").0, 0));
|
return Err(crate::builtins::error::create_type_error(vm, "null object"));
|
||||||
}
|
}
|
||||||
if !unsafe { &*ptr }.is_regexp_obj() {
|
if !unsafe { &*ptr }.is_regexp_obj() {
|
||||||
return Err(JsValue::string(
|
return Err(crate::builtins::error::create_type_error(
|
||||||
vm.kernel_core()
|
vm,
|
||||||
.string_forge()
|
"RegExp.prototype method called on non-RegExp object",
|
||||||
.intern("TypeError: RegExp.prototype method called on non-RegExp object")
|
|
||||||
.0,
|
|
||||||
0,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(ptr)
|
Ok(ptr)
|
||||||
@@ -107,8 +101,10 @@ pub fn regexp_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
obj.set_native_fn(Some(unsafe { NativeFnPtr::from_raw(re_ptr as *const ()) }));
|
obj.set_native_fn(Some(unsafe { NativeFnPtr::from_raw(re_ptr as *const ()) }));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let msg = format!("SyntaxError: Invalid regular expression: {}", e);
|
return NativeResult::Err(crate::builtins::error::create_syntax_error(
|
||||||
return NativeResult::Err(JsValue::string(vm.kernel_core().string_forge().intern(&msg).0, 0));
|
vm,
|
||||||
|
&format!("Invalid regular expression: {e}"),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,10 +148,7 @@ pub fn regexp_test(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
|
|
||||||
let fn_ptr = match re.native_fn() {
|
let fn_ptr = match re.native_fn() {
|
||||||
None => {
|
None => {
|
||||||
return NativeResult::Err(JsValue::string(
|
return NativeResult::Err(crate::builtins::error::create_type_error(vm, "invalid RegExp"));
|
||||||
vm.kernel_core().string_forge().intern("TypeError: invalid RegExp").0,
|
|
||||||
0,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
};
|
};
|
||||||
@@ -187,10 +180,7 @@ pub fn regexp_exec(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
let re = unsafe { &*re_ptr };
|
let re = unsafe { &*re_ptr };
|
||||||
match re.native_fn() {
|
match re.native_fn() {
|
||||||
None => {
|
None => {
|
||||||
return NativeResult::Err(JsValue::string(
|
return NativeResult::Err(crate::builtins::error::create_type_error(vm, "invalid RegExp"));
|
||||||
vm.kernel_core().string_forge().intern("TypeError: invalid RegExp").0,
|
|
||||||
0,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
use oxide_types::value::JsValue;
|
|
||||||
|
|
||||||
use crate::native::NativeResult;
|
use crate::native::NativeResult;
|
||||||
use crate::vm::Vm;
|
use crate::vm::Vm;
|
||||||
|
|
||||||
fn stub_error(vm: &mut Vm, name: &str) -> NativeResult {
|
fn stub_error(vm: &mut Vm, name: &str) -> NativeResult {
|
||||||
let msg = format!("TypeError: {} is not implemented", name);
|
NativeResult::Err(crate::builtins::error::create_type_error(vm, &format!("{name} is not implemented")))
|
||||||
let si = vm.kernel_core().string_forge().intern(&msg).0;
|
|
||||||
NativeResult::Err(JsValue::string(si, 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Architecturally deferred — see 13.5-CONTEXT.md for rationale
|
// Architecturally deferred — see 13.5-CONTEXT.md for rationale
|
||||||
|
|||||||
@@ -17,12 +17,9 @@ pub fn symbol_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
if !proto_ptr.is_null() {
|
if !proto_ptr.is_null() {
|
||||||
let sp = vm.session().builtin_world().symbol_proto.as_ptr() as *mut JsObject;
|
let sp = vm.session().builtin_world().symbol_proto.as_ptr() as *mut JsObject;
|
||||||
if std::ptr::eq(proto_ptr, sp) {
|
if std::ptr::eq(proto_ptr, sp) {
|
||||||
return NativeResult::Err(JsValue::string(
|
return NativeResult::Err(crate::builtins::error::create_type_error(
|
||||||
vm.kernel_core()
|
vm,
|
||||||
.string_forge()
|
"Symbol is not a constructor",
|
||||||
.intern("TypeError: Symbol is not a constructor")
|
|
||||||
.0,
|
|
||||||
0,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,12 +42,9 @@ pub fn symbol_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
pub fn symbol_to_string(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
pub fn symbol_to_string(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||||
let this_val = vm.reg(args[0]);
|
let this_val = vm.reg(args[0]);
|
||||||
if !this_val.is_symbol() {
|
if !this_val.is_symbol() {
|
||||||
return NativeResult::Err(JsValue::string(
|
return NativeResult::Err(crate::builtins::error::create_type_error(
|
||||||
vm.kernel_core()
|
vm,
|
||||||
.string_forge()
|
"Symbol.prototype.toString requires a Symbol",
|
||||||
.intern("TypeError: Symbol.prototype.toString requires a Symbol")
|
|
||||||
.0,
|
|
||||||
0,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -286,12 +286,12 @@ pub fn strict_equality(lhs: JsValue, rhs: JsValue) -> bool {
|
|||||||
same_value(lhs, rhs)
|
same_value(lhs, rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_object(val: JsValue, vm: &mut Vm) -> Result<JsValue, &'static str> {
|
pub fn to_object(val: JsValue, vm: &mut Vm) -> Result<JsValue, String> {
|
||||||
if val.is_object() {
|
if val.is_object() {
|
||||||
return Ok(val);
|
return Ok(val);
|
||||||
}
|
}
|
||||||
if val.is_null() || val.is_undefined() {
|
if val.is_null() || val.is_undefined() {
|
||||||
return Err("TypeError: Cannot convert null or undefined to object");
|
return Err(vm.error_message_text("TypeError", "Cannot convert null or undefined to object"));
|
||||||
}
|
}
|
||||||
let (proto_ptr, type_tag) = if val.is_string() {
|
let (proto_ptr, type_tag) = if val.is_string() {
|
||||||
(
|
(
|
||||||
|
|||||||
+20
-13
@@ -54,6 +54,14 @@ fn js_error_kind_name(kind: JsErrorKind) -> &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn format_error_message(kind: &str, msg: &str) -> String {
|
||||||
|
if msg.is_empty() || msg == kind || msg.starts_with(&format!("{kind}:")) {
|
||||||
|
msg.to_string()
|
||||||
|
} else {
|
||||||
|
format!("{kind}: {msg}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! throw_err {
|
macro_rules! throw_err {
|
||||||
($self:ident, $kind:ident, $msg:expr) => {{
|
($self:ident, $kind:ident, $msg:expr) => {{
|
||||||
@@ -213,7 +221,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err("TypeError: Cannot convert object to primitive value".into())
|
Err(self.error_message_text("TypeError", "Cannot convert object to primitive value"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn coerce_number_bounded(&mut self, value: JsValue) -> Result<f64, String> {
|
pub(crate) fn coerce_number_bounded(&mut self, value: JsValue) -> Result<f64, String> {
|
||||||
@@ -342,12 +350,7 @@ impl Vm {
|
|||||||
|
|
||||||
pub(crate) fn raise_js_error(&mut self, err: JsError) -> Result<(), String> {
|
pub(crate) fn raise_js_error(&mut self, err: JsError) -> Result<(), String> {
|
||||||
let kind = js_error_kind_name(err.kind);
|
let kind = js_error_kind_name(err.kind);
|
||||||
let error = match kind {
|
let error = crate::builtins::error::create_kind_error(self, kind, &err.message);
|
||||||
"TypeError" => crate::builtins::error::create_type_error(self, &err.message),
|
|
||||||
"ReferenceError" => crate::builtins::error::create_reference_error(self, &err.message),
|
|
||||||
"SyntaxError" => crate::builtins::error::create_syntax_error(self, &err.message),
|
|
||||||
_ => crate::builtins::error::create_error(self, &err.message),
|
|
||||||
};
|
|
||||||
self.exception_value = Some(error);
|
self.exception_value = Some(error);
|
||||||
self.pending_error_kind = Some(kind);
|
self.pending_error_kind = Some(kind);
|
||||||
self.unwind()
|
self.unwind()
|
||||||
@@ -357,6 +360,10 @@ impl Vm {
|
|||||||
self.raise_error_kind("TypeError", msg)
|
self.raise_error_kind("TypeError", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn error_message_text(&self, kind: &str, msg: &str) -> String {
|
||||||
|
format_error_message(kind, msg)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn step_rng(&mut self) {
|
pub fn step_rng(&mut self) {
|
||||||
if self.math_rng_state == 0 {
|
if self.math_rng_state == 0 {
|
||||||
self.math_rng_state = std::time::SystemTime::now()
|
self.math_rng_state = std::time::SystemTime::now()
|
||||||
@@ -521,11 +528,11 @@ impl Vm {
|
|||||||
&mut self, callee: JsValue, receiver: JsValue, args: &[JsValue],
|
&mut self, callee: JsValue, receiver: JsValue, args: &[JsValue],
|
||||||
) -> Result<JsValue, String> {
|
) -> Result<JsValue, String> {
|
||||||
if !callee.is_object() {
|
if !callee.is_object() {
|
||||||
return Err("TypeError: accessor is not callable".into());
|
return Err(self.error_message_text("TypeError", "accessor is not callable"));
|
||||||
}
|
}
|
||||||
let callee_obj = unsafe { &*callee.as_js_object_ptr() };
|
let callee_obj = unsafe { &*callee.as_js_object_ptr() };
|
||||||
if !callee_obj.is_function() {
|
if !callee_obj.is_function() {
|
||||||
return Err("TypeError: accessor is not callable".into());
|
return Err(self.error_message_text("TypeError", "accessor is not callable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(native_fn) = callee_obj.native_fn() {
|
if let Some(native_fn) = callee_obj.native_fn() {
|
||||||
@@ -562,11 +569,11 @@ impl Vm {
|
|||||||
constructed_this: Option<JsValue>, new_target: JsValue, continuation: FrameContinuation,
|
constructed_this: Option<JsValue>, new_target: JsValue, continuation: FrameContinuation,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if !callee.is_object() {
|
if !callee.is_object() {
|
||||||
return Err("TypeError: CALL target is not callable".into());
|
return Err(self.error_message_text("TypeError", "CALL target is not callable"));
|
||||||
}
|
}
|
||||||
let obj = unsafe { &*callee.as_js_object_ptr() };
|
let obj = unsafe { &*callee.as_js_object_ptr() };
|
||||||
if !obj.is_function() || obj.sub_module_index() == 0 {
|
if !obj.is_function() || obj.sub_module_index() == 0 {
|
||||||
return Err("TypeError: CALL target is not callable".into());
|
return Err(self.error_message_text("TypeError", "CALL target is not callable"));
|
||||||
}
|
}
|
||||||
let sub_idx = obj.sub_module_index() as usize - 1;
|
let sub_idx = obj.sub_module_index() as usize - 1;
|
||||||
if sub_idx >= self.sub_modules.len() {
|
if sub_idx >= self.sub_modules.len() {
|
||||||
@@ -866,7 +873,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
NativeResult::Err(err_val) => {
|
NativeResult::Err(err_val) => {
|
||||||
self.exception_value = Some(err_val);
|
self.exception_value = Some(err_val);
|
||||||
self.pending_error_kind = Some("Error");
|
self.pending_error_kind = Some(self.thrown_error_kind(err_val));
|
||||||
match self.unwind() {
|
match self.unwind() {
|
||||||
Ok(()) => continue,
|
Ok(()) => continue,
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
@@ -894,7 +901,7 @@ impl Vm {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
if self.frames.len() >= self.kernel_core.config.max_call_depth {
|
if self.frames.len() >= self.kernel_core.config.max_call_depth {
|
||||||
return Err("RangeError: Maximum call stack size exceeded".into());
|
return Err(self.error_message_text("RangeError", "Maximum call stack size exceeded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let sub_bytecode = self.sub_modules[sub_idx].bytecode.clone();
|
let sub_bytecode = self.sub_modules[sub_idx].bytecode.clone();
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
NativeResult::Err(err_val) => {
|
NativeResult::Err(err_val) => {
|
||||||
self.exception_value = Some(err_val);
|
self.exception_value = Some(err_val);
|
||||||
self.pending_error_kind = Some("Error");
|
self.pending_error_kind = Some(self.thrown_error_kind(err_val));
|
||||||
self.unwind().map(|_| true)
|
self.unwind().map(|_| true)
|
||||||
}
|
}
|
||||||
NativeResult::TailCall { .. } => {
|
NativeResult::TailCall { .. } => {
|
||||||
@@ -89,7 +89,7 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.frames.len() >= self.kernel_core.config.max_call_depth {
|
if self.frames.len() >= self.kernel_core.config.max_call_depth {
|
||||||
return Err("RangeError: Maximum call stack size exceeded".into());
|
return Err(self.error_message_text("RangeError", "Maximum call stack size exceeded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_obj_val = JsValue::object(new_obj as *mut u8);
|
let new_obj_val = JsValue::object(new_obj as *mut u8);
|
||||||
@@ -154,7 +154,7 @@ impl Vm {
|
|||||||
let error =
|
let error =
|
||||||
crate::builtins::error::create_error(self, "NEW_EXPRESSION: bytecode constructors not yet supported");
|
crate::builtins::error::create_error(self, "NEW_EXPRESSION: bytecode constructors not yet supported");
|
||||||
self.exception_value = Some(error);
|
self.exception_value = Some(error);
|
||||||
self.pending_error_kind = Some("Error");
|
self.pending_error_kind = Some(self.thrown_error_kind(error));
|
||||||
self.unwind().map(|_| true)
|
self.unwind().map(|_| true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,11 +66,11 @@ impl Vm {
|
|||||||
&mut self, getter: JsValue, receiver: JsValue, target_reg: u8,
|
&mut self, getter: JsValue, receiver: JsValue, target_reg: u8,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
if !getter.is_object() {
|
if !getter.is_object() {
|
||||||
return Err("TypeError: getter is not callable".into());
|
return Err(self.error_message_text("TypeError", "getter is not callable"));
|
||||||
}
|
}
|
||||||
let getter_obj = unsafe { &*getter.as_js_object_ptr() };
|
let getter_obj = unsafe { &*getter.as_js_object_ptr() };
|
||||||
if !getter_obj.is_function() {
|
if !getter_obj.is_function() {
|
||||||
return Err("TypeError: getter is not callable".into());
|
return Err(self.error_message_text("TypeError", "getter is not callable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if getter_obj.native_fn().is_some() {
|
if getter_obj.native_fn().is_some() {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ impl Vm {
|
|||||||
&mut self, callee: JsValue, callee_obj: &JsObject, receiver: JsValue, args: &[JsValue],
|
&mut self, callee: JsValue, callee_obj: &JsObject, receiver: JsValue, args: &[JsValue],
|
||||||
) -> Result<JsValue, String> {
|
) -> Result<JsValue, String> {
|
||||||
if callee_obj.sub_module_index() == 0 {
|
if callee_obj.sub_module_index() == 0 {
|
||||||
return Err("TypeError: accessor is not callable".into());
|
return Err(self.error_message_text("TypeError", "accessor is not callable"));
|
||||||
}
|
}
|
||||||
let sub_idx = callee_obj.sub_module_index() as usize - 1;
|
let sub_idx = callee_obj.sub_module_index() as usize - 1;
|
||||||
if sub_idx >= self.sub_modules.len() {
|
if sub_idx >= self.sub_modules.len() {
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ impl Vm {
|
|||||||
.resolve_property(obj, message_si)
|
.resolve_property(obj, message_si)
|
||||||
.and_then(|v| self.lookup_str(v))
|
.and_then(|v| self.lookup_str(v))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
return if message.is_empty() { name } else { format!("{name}: {message}") };
|
return crate::vm::format_error_message(&name, &message);
|
||||||
}
|
}
|
||||||
format!("{val}")
|
format!("{val}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user