fix(runtime::to_value): numbers are always NixFloat
This commit is contained in:
@@ -146,16 +146,8 @@ fn to_value<'a, 'b>(val: v8::Local<'a, v8::Value>, ctx: &RuntimeContext<'a, 'b>)
|
||||
}
|
||||
_ if val.is_number() => {
|
||||
let val = val.to_number(scope).unwrap().value();
|
||||
// Heuristic: convert whole numbers to Int (for backward compatibility and JS interop)
|
||||
if val.is_finite()
|
||||
&& val.fract() == 0.0
|
||||
&& val >= i64::MIN as f64
|
||||
&& val <= i64::MAX as f64
|
||||
{
|
||||
Value::Const(Const::Int(val as i64))
|
||||
} else {
|
||||
Value::Const(Const::Float(val))
|
||||
}
|
||||
// number is always NixFloat
|
||||
Value::Const(Const::Float(val))
|
||||
}
|
||||
_ if val.is_true() => Value::Const(Const::Bool(true)),
|
||||
_ if val.is_false() => Value::Const(Const::Bool(false)),
|
||||
@@ -280,13 +272,13 @@ fn primop_app_name<'a, 'b>(
|
||||
fn to_value_working() {
|
||||
assert_eq!(
|
||||
run("({
|
||||
test: [1, 9223372036854775807n, true, false, 'hello world!']
|
||||
test: [1., 9223372036854775807n, true, false, 'hello world!']
|
||||
})")
|
||||
.unwrap(),
|
||||
Value::AttrSet(AttrSet::new(std::collections::BTreeMap::from([(
|
||||
Symbol::from("test"),
|
||||
Value::List(List::new(vec![
|
||||
Value::Const(Const::Int(1)),
|
||||
Value::Const(Const::Float(1.)),
|
||||
Value::Const(Const::Int(9223372036854775807)),
|
||||
Value::Const(Const::Bool(true)),
|
||||
Value::Const(Const::Bool(false)),
|
||||
|
||||
Reference in New Issue
Block a user