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

Make boa::parse emit error on invalid input, not panic #807

Merged
merged 7 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion boa/src/syntax/ast/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ pub enum CompOp {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in
In,

/// The `instanceop` operator returns `true` if the specified object is an instance of the
/// The `instanceof` operator returns `true` if the specified object is an instance of the
/// right hand side object.
///
/// Syntax: `obj instanceof Object`
Expand Down
13 changes: 12 additions & 1 deletion boa/src/syntax/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ impl<R> Tokenizer<R> for NumberLiteral {
}
}

//Checks if the next
let digit_char = cursor.peek();

if let Some(digit) = digit_char? {
gorogoroumaru marked this conversation as resolved.
Show resolved Hide resolved
if !digit.is_digit(kind.base()) {
return Err(Error::syntax(
"character was not in expected digit",
cursor.pos(),
));
gorogoroumaru marked this conversation as resolved.
Show resolved Hide resolved
}
}
// Consume digits until a non-digit character is encountered or all the characters are consumed.
cursor.take_while_pred(&mut buf, &|c: char| c.is_digit(kind.base()))?;

Expand Down Expand Up @@ -295,7 +306,7 @@ impl<R> Tokenizer<R> for NumberLiteral {
let val = f64::from_str(&buf).expect("Failed to parse float after checks");
let int_val = val as i32;

// The truncated float should be identically to the non-truncated float for the conversion to be loss-less,
// The truncated float should be identically to the non-truncated float for the conversion to be loss-less,
// any other different and the number must be stored as a rational.
#[allow(clippy::float_cmp)]
if (int_val as f64) == val {
Expand Down