Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cargo check errors #1338

Merged
merged 5 commits into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boa/src/builtins/bigint/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl BigInt {

/// Converts the BigInt to a f64 type.
///
/// Returns `std::f64::INFINITY` if the BigInt is too big.
/// Returns `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]
Expand Down
15 changes: 7 additions & 8 deletions boa/src/builtins/math/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::{
builtins::BuiltIn, object::ObjectInitializer, property::Attribute, BoaProfiler, Context,
Result, Value,
};
use std::f64;

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

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

Expand Down Expand Up @@ -314,7 +313,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
Expand All @@ -323,7 +322,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))
}
}

Expand Down Expand Up @@ -1169,7 +1168,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")
Expand Down Expand Up @@ -1247,7 +1246,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<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 < std::u32::MAX {
if index >= old_len && index < u32::MAX {
let desc = PropertyDescriptor::Data(DataDescriptor::new(
index + 1,
old_len_data_desc.attributes(),
Expand Down
11 changes: 9 additions & 2 deletions boa/src/syntax/parser/expression/assignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(_))
) =>
{
Expand Down
3 changes: 1 addition & 2 deletions boa/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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 +90,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.
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(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)),
Expand Down
33 changes: 21 additions & 12 deletions boa_tester/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down