diff --git a/boa/src/builtins/array/array_iterator.rs b/boa/src/builtins/array/array_iterator.rs index 33c9e84b052..3934d5979a6 100644 --- a/boa/src/builtins/array/array_iterator.rs +++ b/boa/src/builtins/array/array_iterator.rs @@ -49,14 +49,14 @@ impl ArrayIterator { context: &Context, array: Value, kind: ArrayIterationKind, - ) -> Result { + ) -> Value { let array_iterator = Value::new_object(context); array_iterator.set_data(ObjectData::ArrayIterator(Self::new(array, kind))); array_iterator .as_object() .expect("array iterator object") .set_prototype_instance(context.iterator_prototypes().array_iterator().into()); - Ok(array_iterator) + array_iterator } /// %ArrayIteratorPrototype%.next( ) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 515499c54de..0ea3f8f913d 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -120,7 +120,7 @@ impl Array { .unwrap_or_else(|| context.standard_objects().array_object().prototype()); // Delegate to the appropriate constructor based on the number of arguments match args.len() { - 0 => Array::construct_array_empty(prototype, context), + 0 => Ok(Array::construct_array_empty(prototype, context)), 1 => Array::construct_array_length(prototype, &args[0], context), _ => Array::construct_array_values(prototype, args, context), } @@ -132,7 +132,7 @@ impl Array { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-array-constructor-array - fn construct_array_empty(proto: GcObject, context: &mut Context) -> Result { + fn construct_array_empty(proto: GcObject, context: &mut Context) -> Value { Array::array_create(0, Some(proto), context) } @@ -147,7 +147,7 @@ impl Array { length: &Value, context: &mut Context, ) -> Result { - let array = Array::array_create(0, Some(prototype), context)?; + let array = Array::array_create(0, Some(prototype), context); if !length.is_number() { array.set_property(0, DataDescriptor::new(length, Attribute::all())); @@ -174,7 +174,7 @@ impl Array { context: &mut Context, ) -> Result { let items_len = items.len().try_into().map_err(interror_to_value)?; - let array = Array::array_create(items_len, Some(prototype), context)?; + let array = Array::array_create(items_len, Some(prototype), context); for (k, item) in items.iter().enumerate() { array.set_property(k, DataDescriptor::new(item.clone(), Attribute::all())); @@ -189,11 +189,7 @@ impl Array { /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-arraycreate - fn array_create( - length: u32, - prototype: Option, - context: &mut Context, - ) -> Result { + fn array_create(length: u32, prototype: Option, context: &mut Context) -> Value { let prototype = match prototype { Some(prototype) => prototype, None => context.standard_objects().array_object().prototype(), @@ -214,11 +210,11 @@ impl Array { ); array.set_property("length", length); - Ok(array) + array } /// Creates a new `Array` instance. - pub(crate) fn new_array(context: &Context) -> Result { + pub(crate) fn new_array(context: &Context) -> Value { let array = Value::new_object(context); array.set_data(ObjectData::Array); array @@ -230,7 +226,7 @@ impl Array { Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, ); array.set_property("length", length); - Ok(array) + array } /// Utility function for creating array objects. @@ -273,7 +269,7 @@ impl Array { context: &mut Context, ) -> Result { if !original_array.is_array() { - return Self::array_create(length, None, context); + return Ok(Self::array_create(length, None, context)); } let c = original_array.get( &"constructor".into(), @@ -296,7 +292,7 @@ impl Array { c }; if c.is_undefined() { - return Self::array_create(length, None, context); + return Ok(Self::array_create(length, None, context)); } if let Some(c) = c.as_object() { if !c.is_constructable() { @@ -727,7 +723,7 @@ impl Array { return context.throw_range_error("Invalid array length"); } - let new = Self::new_array(context)?; + let new = Self::new_array(context); let values = (0..length) .map(|idx| { @@ -1005,7 +1001,7 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.slice /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice pub(crate) fn slice(this: &Value, args: &[Value], context: &mut Context) -> Result { - let new_array = Self::new_array(context)?; + let new_array = Self::new_array(context); let len = this.get_field("length", context)?.to_length(context)?; let from = Self::get_relative_start(context, args.get(0), len)?; @@ -1310,7 +1306,11 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values pub(crate) fn values(this: &Value, _: &[Value], context: &mut Context) -> Result { - ArrayIterator::create_array_iterator(context, this.clone(), ArrayIterationKind::Value) + Ok(ArrayIterator::create_array_iterator( + context, + this.clone(), + ArrayIterationKind::Value, + )) } /// `Array.prototype.keys( )` @@ -1324,7 +1324,11 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values pub(crate) fn keys(this: &Value, _: &[Value], context: &mut Context) -> Result { - ArrayIterator::create_array_iterator(context, this.clone(), ArrayIterationKind::Key) + Ok(ArrayIterator::create_array_iterator( + context, + this.clone(), + ArrayIterationKind::Key, + )) } /// `Array.prototype.entries( )` @@ -1338,7 +1342,11 @@ impl Array { /// [spec]: https://tc39.es/ecma262/#sec-array.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values pub(crate) fn entries(this: &Value, _: &[Value], context: &mut Context) -> Result { - ArrayIterator::create_array_iterator(context, this.clone(), ArrayIterationKind::KeyAndValue) + Ok(ArrayIterator::create_array_iterator( + context, + this.clone(), + ArrayIterationKind::KeyAndValue, + )) } /// Represents the algorithm to calculate `relativeStart` (or `k`) in array functions. diff --git a/boa/src/builtins/array/tests.rs b/boa/src/builtins/array/tests.rs index dac5b842b40..8ae8e1119e3 100644 --- a/boa/src/builtins/array/tests.rs +++ b/boa/src/builtins/array/tests.rs @@ -1366,7 +1366,7 @@ fn get_relative_end() { fn array_length_is_not_enumerable() { let context = Context::new(); - let array = Array::new_array(&context).unwrap(); + let array = Array::new_array(&context); let desc = array.get_property("length").unwrap(); assert!(!desc.enumerable()); } diff --git a/boa/src/builtins/bigint/conversions.rs b/boa/src/builtins/bigint/conversions.rs index 6cdb1f14f20..1841e5439a4 100644 --- a/boa/src/builtins/bigint/conversions.rs +++ b/boa/src/builtins/bigint/conversions.rs @@ -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(std::f64::INFINITY) + self.0.to_f64().unwrap_or(f64::INFINITY) } #[inline] diff --git a/boa/src/builtins/date/mod.rs b/boa/src/builtins/date/mod.rs index 3f49aa6ae3f..40556ac0c6e 100644 --- a/boa/src/builtins/date/mod.rs +++ b/boa/src/builtins/date/mod.rs @@ -371,7 +371,7 @@ impl Date { context: &mut Context, ) -> Result { if new_target.is_undefined() { - Self::make_date_string() + Ok(Self::make_date_string()) } else { let prototype = new_target .as_object() @@ -386,7 +386,7 @@ impl Date { obj.set_prototype_instance(prototype.into()); let this = obj.into(); if args.is_empty() { - Self::make_date_now(&this) + Ok(Self::make_date_now(&this)) } else if args.len() == 1 { Self::make_date_single(&this, args, context) } else { @@ -405,8 +405,8 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date-constructor /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date - pub(crate) fn make_date_string() -> Result { - Ok(Value::from(Local::now().to_rfc3339())) + pub(crate) fn make_date_string() -> Value { + Value::from(Local::now().to_rfc3339()) } /// `Date()` @@ -419,10 +419,10 @@ impl Date { /// /// [spec]: https://tc39.es/ecma262/#sec-date-constructor /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date - pub(crate) fn make_date_now(this: &Value) -> Result { + pub(crate) fn make_date_now(this: &Value) -> Value { let date = Date::default(); this.set_data(ObjectData::Date(date)); - Ok(this.clone()) + this.clone() } /// `Date(value)` diff --git a/boa/src/builtins/function/mod.rs b/boa/src/builtins/function/mod.rs index 0f3e7ab90d2..b9b8ae9dc49 100644 --- a/boa/src/builtins/function/mod.rs +++ b/boa/src/builtins/function/mod.rs @@ -119,7 +119,7 @@ impl Function { local_env: &Environment, ) { // Create array of values - let array = Array::new_array(context).unwrap(); + let array = Array::new_array(context); Array::add_to_array_object(&array, &args_list[index..], context).unwrap(); // Create binding diff --git a/boa/src/builtins/map/map_iterator.rs b/boa/src/builtins/map/map_iterator.rs index fe2c933c650..13766475a7a 100644 --- a/boa/src/builtins/map/map_iterator.rs +++ b/boa/src/builtins/map/map_iterator.rs @@ -49,14 +49,14 @@ impl MapIterator { context: &Context, map: Value, kind: MapIterationKind, - ) -> Result { + ) -> Value { let map_iterator = Value::new_object(context); map_iterator.set_data(ObjectData::MapIterator(Self::new(map, kind))); map_iterator .as_object() .expect("map iterator object") .set_prototype_instance(context.iterator_prototypes().map_iterator().into()); - Ok(map_iterator) + map_iterator } /// %MapIteratorPrototype%.next( ) @@ -104,7 +104,7 @@ impl MapIterator { } MapIterationKind::KeyAndValue => { let result = Array::construct_array( - &Array::new_array(context)?, + &Array::new_array(context), &[key.clone(), value.clone()], context, )?; diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index 3b9c293743a..3e4e56a4557 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -158,7 +158,11 @@ impl Map { /// [spec]: https://www.ecma-international.org/ecma-262/11.0/index.html#sec-map.prototype.entries /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries pub(crate) fn entries(this: &Value, _: &[Value], context: &mut Context) -> Result { - MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::KeyAndValue) + Ok(MapIterator::create_map_iterator( + context, + this.clone(), + MapIterationKind::KeyAndValue, + )) } /// `Map.prototype.keys()` @@ -172,7 +176,11 @@ impl Map { /// [spec]: https://tc39.es/ecma262/#sec-map.prototype.keys /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys pub(crate) fn keys(this: &Value, _: &[Value], context: &mut Context) -> Result { - MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::Key) + Ok(MapIterator::create_map_iterator( + context, + this.clone(), + MapIterationKind::Key, + )) } /// Helper function to set the size property. @@ -395,7 +403,11 @@ impl Map { /// [spec]: https://tc39.es/ecma262/#sec-map.prototype.values /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values pub(crate) fn values(this: &Value, _: &[Value], context: &mut Context) -> Result { - MapIterator::create_map_iterator(context, this.clone(), MapIterationKind::Value) + Ok(MapIterator::create_map_iterator( + context, + this.clone(), + MapIterationKind::Value, + )) } /// Helper function to get a key-value pair from an array. diff --git a/boa/src/builtins/math/mod.rs b/boa/src/builtins/math/mod.rs index ce6e4317970..70f54cef0e1 100644 --- a/boa/src/builtins/math/mod.rs +++ b/boa/src/builtins/math/mod.rs @@ -15,7 +15,6 @@ use crate::{ builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context, Result, Value, }; -use std::f64; #[cfg(test)] mod tests; @@ -32,6 +31,8 @@ impl BuiltIn for Math { } fn init(context: &mut Context) -> (&'static str, Value, Attribute) { + use std::f64; + let _timer = BoaProfiler::global().start_event(Self::NAME, "init"); let attribute = Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::PERMANENT; diff --git a/boa/src/builtins/object/for_in_iterator.rs b/boa/src/builtins/object/for_in_iterator.rs index 61c1d3bfa16..deeb9c22845 100644 --- a/boa/src/builtins/object/for_in_iterator.rs +++ b/boa/src/builtins/object/for_in_iterator.rs @@ -45,14 +45,14 @@ impl ForInIterator { /// - [ECMA reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-createforiniterator - pub(crate) fn create_for_in_iterator(context: &Context, object: Value) -> Result { + pub(crate) fn create_for_in_iterator(context: &Context, object: Value) -> Value { let for_in_iterator = Value::new_object(context); for_in_iterator.set_data(ObjectData::ForInIterator(Self::new(object))); for_in_iterator .as_object() .expect("for in iterator object") .set_prototype_instance(context.iterator_prototypes().for_in_iterator().into()); - Ok(for_in_iterator) + for_in_iterator } /// %ForInIteratorPrototype%.next( ) diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index fd6f4239141..11a2ebbc205 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -164,7 +164,7 @@ impl Object { let key = key.to_property_key(context)?; if let Some(desc) = object.get_own_property(&key) { - return Ok(Self::from_property_descriptor(desc, context)?); + return Ok(Self::from_property_descriptor(desc, context)); } } @@ -197,7 +197,7 @@ impl Object { let desc = object .get_own_property(&key) .expect("Expected property to be on object."); - Self::from_property_descriptor(desc, context)? + Self::from_property_descriptor(desc, context) }; if !descriptor.is_undefined() { @@ -216,7 +216,7 @@ impl Object { /// [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-frompropertydescriptor - fn from_property_descriptor(desc: PropertyDescriptor, context: &mut Context) -> Result { + fn from_property_descriptor(desc: PropertyDescriptor, context: &mut Context) -> Value { let mut descriptor = ObjectInitializer::new(context); if let PropertyDescriptor::Data(data_desc) = &desc { @@ -251,7 +251,7 @@ impl Object { Attribute::all(), ); - Ok(descriptor.build().into()) + descriptor.build().into() } /// Uses the SameValue algorithm to check equality of objects diff --git a/boa/src/builtins/string/mod.rs b/boa/src/builtins/string/mod.rs index b7ee8b07b4e..af9fbcc75a3 100644 --- a/boa/src/builtins/string/mod.rs +++ b/boa/src/builtins/string/mod.rs @@ -27,7 +27,6 @@ use regress::Regex; use std::{ char::{decode_utf16, from_u32}, cmp::{max, min}, - f64::NAN, string::String as StdString, }; @@ -335,7 +334,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(NAN)); + return Ok(Value::from(f64::NAN)); } // Calling .len() on a string would give the wrong result, as they are bytes not the number of unicode code points @@ -344,7 +343,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(NAN)) + Ok(Value::from(f64::NAN)) } } @@ -910,11 +909,11 @@ impl String { max_length: i32, fill_string: Option, at_start: bool, - ) -> Result { + ) -> Value { let primitive_length = primitive.len() as i32; if max_length <= primitive_length { - return Ok(Value::from(primitive)); + return Value::from(primitive); } let filter = fill_string.as_deref().unwrap_or(" "); @@ -929,9 +928,9 @@ impl String { let concat_fill_str: StdString = fill_str.chars().take(fill_len as usize).collect(); if at_start { - Ok(Value::from(format!("{}{}", concat_fill_str, &primitive))) + Value::from(format!("{}{}", concat_fill_str, &primitive)) } else { - Ok(Value::from(format!("{}{}", primitive, &concat_fill_str))) + Value::from(format!("{}{}", primitive, &concat_fill_str)) } } @@ -959,7 +958,7 @@ impl String { let fill_string = args.get(1).map(|arg| arg.to_string(context)).transpose()?; - Self::string_pad(primitive, max_length, fill_string, false) + Ok(Self::string_pad(primitive, max_length, fill_string, false)) } /// `String.prototype.padStart( targetLength [, padString] )` @@ -986,7 +985,7 @@ impl String { let fill_string = args.get(1).map(|arg| arg.to_string(context)).transpose()?; - Self::string_pad(primitive, max_length, fill_string, true) + Ok(Self::string_pad(primitive, max_length, fill_string, true)) } /// String.prototype.trim() @@ -1167,7 +1166,7 @@ impl String { // 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_value let end = if args.len() < 2 { - i32::max_value() + i32::MAX } else { args.get(1) .expect("Could not get argument") @@ -1245,7 +1244,7 @@ impl String { .get(1) .map(|arg| arg.to_integer(context).map(|limit| limit as usize)) .transpose()? - .unwrap_or(std::u32::MAX as usize); + .unwrap_or(u32::MAX as usize); let values: Vec = match separator { None if limit == 0 => vec![], @@ -1263,7 +1262,7 @@ impl String { .collect(), }; - let new = Array::new_array(context)?; + let new = Array::new_array(context); Array::construct_array(&new, &values, context) } diff --git a/boa/src/lib.rs b/boa/src/lib.rs index 0540130fc3a..25c54e44e75 100644 --- a/boa/src/lib.rs +++ b/boa/src/lib.rs @@ -42,6 +42,8 @@ This is an experimental Javascript lexer, parser and compiler written in Rust. C missing_doc_code_examples )] +// builtins module has a lot of built-in functions that need unnecessary_wraps +#[allow(clippy::unnecessary_wraps)] pub mod builtins; pub mod class; pub mod environment; diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index 0e0e56b047c..3892eee5db7 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -363,7 +363,7 @@ impl GcObject { return Ok(false); } if self.ordinary_define_own_property(key, desc) { - if index >= old_len && index < std::u32::MAX { + if index >= old_len && index < u32::MAX { let desc = PropertyDescriptor::Data(DataDescriptor::new( index + 1, old_len_data_desc.attributes(), diff --git a/boa/src/syntax/ast/node/array/mod.rs b/boa/src/syntax/ast/node/array/mod.rs index 7096770918b..8bb7f5ac32e 100644 --- a/boa/src/syntax/ast/node/array/mod.rs +++ b/boa/src/syntax/ast/node/array/mod.rs @@ -38,7 +38,7 @@ pub struct ArrayDecl { impl Executable for ArrayDecl { fn run(&self, context: &mut Context) -> Result { let _timer = BoaProfiler::global().start_event("ArrayDecl", "exec"); - let array = Array::new_array(context)?; + let array = Array::new_array(context); let mut elements = Vec::new(); for elem in self.as_ref() { if let Node::Spread(ref x) = elem { diff --git a/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs b/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs index 9841aedb3c7..faf1124be52 100644 --- a/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs +++ b/boa/src/syntax/ast/node/iteration/for_in_loop/mod.rs @@ -84,7 +84,7 @@ impl Executable for ForInLoop { return Ok(result); } let object = object.to_object(context)?; - let for_in_iterator = ForInIterator::create_for_in_iterator(context, Value::from(object))?; + let for_in_iterator = ForInIterator::create_for_in_iterator(context, Value::from(object)); let next_function = for_in_iterator .get_property("next") .map(|p| p.as_data_descriptor().unwrap().value()) diff --git a/boa/src/syntax/ast/node/template/mod.rs b/boa/src/syntax/ast/node/template/mod.rs index 896c7541181..2e6a747a848 100644 --- a/boa/src/syntax/ast/node/template/mod.rs +++ b/boa/src/syntax/ast/node/template/mod.rs @@ -88,8 +88,8 @@ impl Executable for TaggedTemplate { fn run(&self, context: &mut Context) -> Result { let _timer = BoaProfiler::global().start_event("TaggedTemplate", "exec"); - let template_object = Array::new_array(context)?; - let raw_array = Array::new_array(context)?; + let template_object = Array::new_array(context); + let raw_array = Array::new_array(context); for (i, raw) in self.raws.iter().enumerate() { raw_array.set_field(i, Value::from(raw), context)?; diff --git a/boa/src/syntax/parser/expression/assignment/mod.rs b/boa/src/syntax/parser/expression/assignment/mod.rs index 0a7cf4c4d07..be30d52eebd 100644 --- a/boa/src/syntax/parser/expression/assignment/mod.rs +++ b/boa/src/syntax/parser/expression/assignment/mod.rs @@ -217,6 +217,13 @@ where /// [spec]: https://tc39.es/ecma262/#sec-assignment-operators-static-semantics-early-errors #[inline] pub(crate) fn is_assignable(node: &Node) -> bool { - matches!(node, Node::GetConstField(_) | Node::GetField(_) | Node::Assign(_) - | Node::Call(_) | Node::Identifier(_) | Node::Object(_)) + matches!( + node, + Node::GetConstField(_) + | Node::GetField(_) + | Node::Assign(_) + | Node::Call(_) + | Node::Identifier(_) + | Node::Object(_) + ) } diff --git a/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs b/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs index 0ae11c5dada..9a450c8cef2 100644 --- a/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs +++ b/boa/src/syntax/parser/expression/primary/object_initializer/mod.rs @@ -208,8 +208,10 @@ where idn @ "get" | idn @ "set" if matches!( cursor.peek(0)?.map(|t| t.kind()), - Some(&TokenKind::Identifier(_)) | Some(&TokenKind::Keyword(_)) - | Some(&TokenKind::BooleanLiteral(_)) | Some(&TokenKind::NullLiteral) + Some(&TokenKind::Identifier(_)) + | Some(&TokenKind::Keyword(_)) + | Some(&TokenKind::BooleanLiteral(_)) + | Some(&TokenKind::NullLiteral) | Some(&TokenKind::NumericLiteral(_)) ) => { diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index 44c91047ba9..99163dc3e20 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -20,7 +20,6 @@ use serde_json::{Number as JSONNumber, Value as JSONValue}; use std::{ collections::HashSet, convert::TryFrom, - f64::NAN, fmt::{self, Display}, str::FromStr, }; @@ -92,7 +91,7 @@ impl Value { /// Creates a new number with `NaN` value. #[inline] pub fn nan() -> Self { - Self::number(NAN) + Self::number(f64::NAN) } /// Creates a new string value. diff --git a/boa/src/value/operations.rs b/boa/src/value/operations.rs index 44cc173f8b3..d7e0ac9341a 100644 --- a/boa/src/value/operations.rs +++ b/boa/src/value/operations.rs @@ -423,14 +423,14 @@ impl Value { #[inline] pub fn neg(&self, context: &mut Context) -> Result { Ok(match *self { - Self::Symbol(_) | Self::Undefined => Self::rational(NAN), + Self::Symbol(_) | Self::Undefined => Self::rational(f64::NAN), Self::Object(_) => Self::rational(match self.to_numeric_number(context) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::String(ref str) => Self::rational(match f64::from_str(str) { Ok(num) => -num, - Err(_) => NAN, + Err(_) => f64::NAN, }), Self::Rational(num) => Self::rational(-num), Self::Integer(num) => Self::rational(-f64::from(num)), diff --git a/boa/src/value/tests.rs b/boa/src/value/tests.rs index 81619ffd474..c87e39e9c91 100644 --- a/boa/src/value/tests.rs +++ b/boa/src/value/tests.rs @@ -58,7 +58,7 @@ fn number_is_true() { assert_eq!(Value::from(0.0).to_boolean(), false); assert_eq!(Value::from(-0.0).to_boolean(), false); assert_eq!(Value::from(-1.0).to_boolean(), true); - assert_eq!(Value::from(NAN).to_boolean(), false); + assert_eq!(Value::from(f64::NAN).to_boolean(), false); } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness @@ -569,7 +569,7 @@ fn to_integer_or_infinity() { Ok(IntegerOrInfinity::Integer(0)) ); assert_eq!( - Value::from(NAN).to_integer_or_infinity(&mut context), + Value::from(f64::NAN).to_integer_or_infinity(&mut context), Ok(IntegerOrInfinity::Integer(0)) ); assert_eq!( diff --git a/boa_tester/src/exec.rs b/boa_tester/src/exec.rs index aa011deec60..b362f923563 100644 --- a/boa_tester/src/exec.rs +++ b/boa_tester/src/exec.rs @@ -110,18 +110,27 @@ impl Test { && !IGNORED.contains_test(&self.name) && !IGNORED.contains_any_feature(&self.features) && (matches!(self.expected_outcome, Outcome::Positive) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Parse, - error_type: _, - }) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Early, - error_type: _, - }) - || matches!(self.expected_outcome, Outcome::Negative { - phase: Phase::Runtime, - error_type: _, - })) { + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Parse, + error_type: _, + } + ) + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Early, + error_type: _, + } + ) + || matches!( + self.expected_outcome, + Outcome::Negative { + phase: Phase::Runtime, + error_type: _, + } + )) { let res = panic::catch_unwind(|| match self.expected_outcome { Outcome::Positive => { // TODO: implement async and add `harness/doneprintHandle.js` to the includes. diff --git a/test262 b/test262 index 6cf3433cf8f..9da1d6119c7 160000 --- a/test262 +++ b/test262 @@ -1 +1 @@ -Subproject commit 6cf3433cf8f44c471a7e4f47e5ba36d32ebb7b69 +Subproject commit 9da1d6119c76200abecbd4ef4f80ae8f3e5ae3cf