Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Dec 4, 2024
1 parent e2fa89a commit 1b53194
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
8 changes: 0 additions & 8 deletions nova_vm/src/ecmascript/abstract_operations/type_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@ pub(crate) fn to_integer_or_infinity(
// Fast path: A safe integer is already an integer.
if let Value::Integer(int) = argument {
let int = IntegerOrInfinity(int.into_i64());
// Note: It should be impossible for the integer to be outside of safe
// integer limits.
debug_assert!(int.is_safe_integer());
return Ok(int);
}
// 1. Let number be ? ToNumber(argument).
Expand All @@ -481,7 +478,6 @@ pub(crate) fn to_integer_or_infinity(
// Fast path: The value might've been eg. parsed into an integer.
if let Number::Integer(int) = number {
let int = IntegerOrInfinity(int.into_i64());
debug_assert!(int.is_safe_integer());
return Ok(int);
}

Expand Down Expand Up @@ -532,9 +528,6 @@ pub(crate) fn try_to_integer_or_infinity(
// Fast path: A safe integer is already an integer.
if let Value::Integer(int) = argument {
let int = IntegerOrInfinity(int.into_i64());
// Note: It should be impossible for the integer to be outside of safe
// integer limits.
debug_assert!(int.is_safe_integer());
return Some(Ok(int));
}
// 1. Let number be ? ToNumber(argument).
Expand All @@ -552,7 +545,6 @@ pub(crate) fn try_to_integer_or_infinity(
// Fast path: The value might've been eg. parsed into an integer.
if let Number::Integer(int) = number {
let int = IntegerOrInfinity(int.into_i64());
debug_assert!(int.is_safe_integer());
return Some(Ok(int));
}

Expand Down
18 changes: 13 additions & 5 deletions nova_vm/src/ecmascript/builtins/numbers_and_dates/math_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{
},
engine::context::{GcScope, NoGcScope},
heap::WellKnownSymbolIndexes,
SmallInteger,
};

pub(crate) struct MathObject;
Expand Down Expand Up @@ -1315,11 +1314,20 @@ impl MathObject {
let base = base.into_i64();
let exponent = exponent.into_i64();
if let Ok(exponent) = u32::try_from(exponent) {
let result = (base as i128).pow(exponent);
if let Ok(result) = SmallInteger::try_from(result) {
return Ok(Value::Integer(result));
} else {
if let Some(result) = base.checked_pow(exponent) {
if let Ok(result) = Number::try_from(result) {
return Ok(result.into_value());
} else {
return Ok(Value::from_f64(agent, gc.into_nogc(), result as f64));
}
} else if let Some(result) = (base as i128).checked_pow(exponent) {
return Ok(Value::from_f64(agent, gc.into_nogc(), result as f64));
} else {
return Ok(Value::from_f64(
agent,
gc.into_nogc(),
(base as f64).powf(exponent as f64),
));
}
} else if let Ok(exponent) = i32::try_from(exponent) {
let result = (base as f64).powi(exponent);
Expand Down
8 changes: 8 additions & 0 deletions nova_vm/src/ecmascript/types/language/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ impl TryFrom<i64> for Number<'static> {
}
}

impl TryFrom<u64> for Number<'static> {
type Error = ();

fn try_from(value: u64) -> Result<Self, ()> {
Ok(Number::Integer(SmallInteger::try_from(value)?))
}
}

impl TryFrom<usize> for Number<'static> {
type Error = ();

Expand Down
3 changes: 0 additions & 3 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -23481,9 +23481,6 @@
"language/statements/with/unscopables-inc-dec.js": "CRASH",
"language/statements/with/unscopables-not-referenced-for-undef.js": "CRASH",
"language/statements/with/unscopables-prop-get-err.js": "CRASH",
"language/types/number/S8.5_A13_T2.js": "CRASH",
"language/types/number/S8.5_A14_T1.js": "CRASH",
"language/types/number/S8.5_A14_T2.js": "CRASH",
"language/types/reference/get-value-prop-base-primitive-realm.js": "FAIL",
"language/types/reference/put-value-prop-base-primitive-realm.js": "FAIL",
"language/types/reference/put-value-prop-base-primitive.js": "CRASH",
Expand Down
4 changes: 2 additions & 2 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"results": {
"crash": 14782,
"fail": 8755,
"pass": 21706,
"fail": 8752,
"pass": 21709,
"skip": 45,
"timeout": 3,
"unresolved": 0
Expand Down

0 comments on commit 1b53194

Please sign in to comment.