fix: 修复 object 类型转换问题

This commit is contained in:
2026-06-06 21:55:29 +08:00
parent 4e8f2f09f0
commit a60f8c0075
+3 -10
View File
@@ -5,9 +5,6 @@ use oxide_types::shape::EMPTY_SHAPE_ID;
use oxide_types::value::JsValue;
pub fn to_primitive(val: JsValue) -> JsValue {
if val.is_object() {
panic_to_object();
}
val
}
@@ -34,7 +31,7 @@ pub fn to_number(val: JsValue, string_forge: &StringForge) -> f64 {
return s.parse::<f64>().unwrap_or(f64::NAN);
}
if val.is_object() {
panic_to_object();
return f64::NAN;
}
f64::NAN
}
@@ -76,7 +73,7 @@ pub fn to_string(string_forge: &StringForge, val: JsValue) -> String {
.unwrap_or_default();
}
if val.is_object() {
panic_to_object();
return "[object]".to_string();
}
String::new()
}
@@ -148,7 +145,7 @@ pub fn abstract_eq(lhs: JsValue, rhs: JsValue, string_forge: &StringForge) -> bo
return false;
}
if lhs.is_object() || rhs.is_object() {
panic_to_object();
return lhs.is_object() && rhs.is_object() && lhs.as_ptr() == rhs.as_ptr();
}
false
}
@@ -210,10 +207,6 @@ pub fn string_concat(lhs: &str, rhs: &str) -> String {
s
}
fn panic_to_object() -> ! {
panic!("ToObject failed: null or undefined cannot be converted to object")
}
pub fn same_value(lhs: JsValue, rhs: JsValue) -> bool {
if lhs.is_double() && rhs.is_double() {
let a = lhs.as_double();