Skip to content

Commit

Permalink
Revert "fix: adopting changes of RFC 2700"
Browse files Browse the repository at this point in the history
This reverts commit 1f426ad.
  • Loading branch information
NathanRoyer committed May 23, 2021
1 parent 3007411 commit a48a326
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion boa/src/builtins/bigint/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl BigInt {
/// Returns `std::f64::INFINITY` if the BigInt is too big.
#[inline]
pub fn to_f64(&self) -> f64 {
self.0.to_f64().unwrap_or(f64::INFINITY)
self.0.to_f64().unwrap_or(std::f64::INFINITY)
}

#[inline]
Expand Down
15 changes: 8 additions & 7 deletions boa/src/builtins/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context,
Result, Value,
};
use std::f64;

#[cfg(test)]
mod tests;
Expand All @@ -36,14 +37,14 @@ impl BuiltIn for Math {

let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT;
let object = ObjectInitializer::new(context)
.property("E", std::f64::consts::E, attribute)
.property("LN2", std::f64::consts::LN_2, attribute)
.property("LN10", std::f64::consts::LN_10, attribute)
.property("LOG2E", std::f64::consts::LOG2_E, attribute)
.property("LOG10E", std::f64::consts::LOG10_E, attribute)
.property("E", f64::consts::E, attribute)
.property("LN2", f64::consts::LN_2, attribute)
.property("LN10", f64::consts::LN_10, attribute)
.property("LOG2E", f64::consts::LOG2_E, attribute)
.property("LOG10E", f64::consts::LOG10_E, attribute)
.property("SQRT1_2", 0.5_f64.sqrt(), attribute)
.property("SQRT2", std::f64::consts::SQRT_2, attribute)
.property("PI", std::f64::consts::PI, attribute)
.property("SQRT2", f64::consts::SQRT_2, attribute)
.property("PI", f64::consts::PI, attribute)
.function(Self::abs, "abs", 1)
.function(Self::acos, "acos", 1)
.function(Self::acosh, "acosh", 1)
Expand Down
13 changes: 7 additions & 6 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use regress::Regex;
use std::{
char::{decode_utf16, from_u32},
cmp::{max, min},
f64::NAN,
string::String as StdString,
};

Expand Down Expand Up @@ -334,7 +335,7 @@ impl String {

// Fast path returning NaN when pos is obviously out of range
if pos < 0 || pos >= primitive_val.len() as i32 {
return Ok(Value::from(f64::NAN));
return Ok(Value::from(NAN));
}

// Calling .len() on a string would give the wrong result, as they are bytes not the number of unicode code points
Expand All @@ -343,7 +344,7 @@ impl String {
if let Some(utf16_val) = primitive_val.encode_utf16().nth(pos as usize) {
Ok(Value::from(f64::from(utf16_val)))
} else {
Ok(Value::from(f64::NAN))
Ok(Value::from(NAN))
}
}

Expand Down Expand Up @@ -1162,11 +1163,11 @@ impl String {
};
let length = primitive_val.chars().count() as i32;
// If less than 2 args specified, end is +infinity, the maximum number value.
// Using i32::MAX should be safe because the final length used is at most
// Using i32::max_value() should be safe because the final length used is at most
// the number of code units from start to the end of the string,
// which should always be smaller or equals to both +infinity and i32::MAX
// which should always be smaller or equals to both +infinity and i32::max_value
let end = if args.len() < 2 {
i32::MAX
i32::max_value()
} else {
args.get(1)
.expect("Could not get argument")
Expand Down Expand Up @@ -1244,7 +1245,7 @@ impl String {
.get(1)
.map(|arg| arg.to_integer(context).map(|limit| limit as usize))
.transpose()?
.unwrap_or(u32::MAX as usize);
.unwrap_or(std::u32::MAX as usize);

let values: Vec<Value> = match separator {
None if limit == 0 => vec![],
Expand Down
2 changes: 1 addition & 1 deletion boa/src/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl GcObject {
return Ok(false);
}
if self.ordinary_define_own_property(key, desc) {
if index >= old_len && index < u32::MAX {
if index >= old_len && index < std::u32::MAX {
let desc = PropertyDescriptor::Data(DataDescriptor::new(
index + 1,
old_len_data_desc.attributes(),
Expand Down
3 changes: 2 additions & 1 deletion boa/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use serde_json::{Number as JSONNumber, Value as JSONValue};
use std::{
collections::HashSet,
convert::TryFrom,
f64::NAN,
fmt::{self, Display},
str::FromStr,
};
Expand Down Expand Up @@ -91,7 +92,7 @@ impl Value {
/// Creates a new number with `NaN` value.
#[inline]
pub fn nan() -> Self {
Self::number(f64::NAN)
Self::number(NAN)
}

/// Creates a new string value.
Expand Down
6 changes: 3 additions & 3 deletions boa/src/value/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,14 @@ impl Value {
#[inline]
pub fn neg(&self, context: &mut Context) -> Result<Value> {
Ok(match *self {
Self::Symbol(_) | Self::Undefined => Self::rational(f64::NAN),
Self::Symbol(_) | Self::Undefined => Self::rational(NAN),
Self::Object(_) => Self::rational(match self.to_numeric_number(context) {
Ok(num) => -num,
Err(_) => f64::NAN,
Err(_) => NAN,
}),
Self::String(ref str) => Self::rational(match f64::from_str(str) {
Ok(num) => -num,
Err(_) => f64::NAN,
Err(_) => NAN,
}),
Self::Rational(num) => Self::rational(-num),
Self::Integer(num) => Self::rational(-f64::from(num)),
Expand Down

0 comments on commit a48a326

Please sign in to comment.