mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
fix: 修复表达式中整数强转浮点问题
This commit is contained in:
@@ -48,6 +48,9 @@ pub fn to_string(vm: &Vm, val: JsValue) -> String {
|
|||||||
"-Infinity".to_string()
|
"-Infinity".to_string()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if d.is_finite() && d.fract() == 0.0 {
|
||||||
|
return (d as i64).to_string();
|
||||||
|
}
|
||||||
let mut buf = ryu::Buffer::new();
|
let mut buf = ryu::Buffer::new();
|
||||||
return buf.format(d).to_string();
|
return buf.format(d).to_string();
|
||||||
}
|
}
|
||||||
@@ -170,7 +173,12 @@ fn strict_double_eq(a: f64, b: f64) -> bool {
|
|||||||
a == b
|
a == b
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn relational_compare(lhs: JsValue, rhs: JsValue) -> Option<bool> {
|
pub fn relational_compare(vm: &Vm, lhs: JsValue, rhs: JsValue) -> Option<bool> {
|
||||||
|
if lhs.is_string() && rhs.is_string() {
|
||||||
|
let ls = vm.lookup_str(lhs).unwrap_or("");
|
||||||
|
let rs = vm.lookup_str(rhs).unwrap_or("");
|
||||||
|
return Some(ls < rs);
|
||||||
|
}
|
||||||
let l = to_number(lhs);
|
let l = to_number(lhs);
|
||||||
let r = to_number(rhs);
|
let r = to_number(rhs);
|
||||||
if l.is_nan() || r.is_nan() {
|
if l.is_nan() || r.is_nan() {
|
||||||
|
|||||||
@@ -205,22 +205,22 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpCode::LT => {
|
OpCode::LT => {
|
||||||
let rel = coercion::relational_compare(self.regs[a], self.regs[b]);
|
let rel = coercion::relational_compare(self, self.regs[a], self.regs[b]);
|
||||||
self.regs[rd] = JsValue::bool(rel.unwrap_or(false));
|
self.regs[rd] = JsValue::bool(rel.unwrap_or(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::GT => {
|
OpCode::GT => {
|
||||||
let rel = coercion::relational_compare(self.regs[b], self.regs[a]);
|
let rel = coercion::relational_compare(self, self.regs[b], self.regs[a]);
|
||||||
self.regs[rd] = JsValue::bool(rel.unwrap_or(false));
|
self.regs[rd] = JsValue::bool(rel.unwrap_or(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::LTE => {
|
OpCode::LTE => {
|
||||||
let rel = coercion::relational_compare(self.regs[b], self.regs[a]);
|
let rel = coercion::relational_compare(self, self.regs[b], self.regs[a]);
|
||||||
self.regs[rd] = JsValue::bool(!rel.unwrap_or(true));
|
self.regs[rd] = JsValue::bool(!rel.unwrap_or(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
OpCode::GTE => {
|
OpCode::GTE => {
|
||||||
let rel = coercion::relational_compare(self.regs[a], self.regs[b]);
|
let rel = coercion::relational_compare(self, self.regs[a], self.regs[b]);
|
||||||
self.regs[rd] = JsValue::bool(!rel.unwrap_or(true));
|
self.regs[rd] = JsValue::bool(!rel.unwrap_or(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user