Browse Source

Fix integer parsing (#1614)

* Use BigInt for parsing long integers
pull/1618/head
Nikodem Rabuliński 3 years ago committed by GitHub
parent
commit
5029a23185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      boa/src/syntax/lexer/number.rs

9
boa/src/syntax/lexer/number.rs

@ -398,13 +398,8 @@ impl<R> Tokenizer<R> for NumberLiteral {
if let Ok(num) = i32::from_str_radix(num_str, base) { if let Ok(num) = i32::from_str_radix(num_str, base) {
Numeric::Integer(num) Numeric::Integer(num)
} else { } else {
let b = f64::from(base); let num = JsBigInt::from_string_radix(num_str, base).expect("Failed to parse integer after checks");
let mut result = 0.0_f64; Numeric::Rational(num.to_f64())
for c in num_str.chars() {
let digit = f64::from(c.to_digit(base).expect("could not parse digit after already checking validity"));
result = result * b + digit;
}
Numeric::Rational(result)
} }
} }
}; };

Loading…
Cancel
Save