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

Panic parsing some floats #1063

Closed
Razican opened this issue Jan 12, 2021 · 1 comment · Fixed by #1110
Closed

Panic parsing some floats #1063

Razican opened this issue Jan 12, 2021 · 1 comment · Fixed by #1110
Labels
bug Something isn't working lexer Issues surrounding the lexer
Milestone

Comments

@Razican
Copy link
Member

Razican commented Jan 12, 2021

When running this test, we get the following panic:

thread 'main' panicked at 'Failed to parse float after checks: ParseFloatError { kind: Invalid }', boa/src/syntax/lexer/number.rs:384:50

This is the stack trace:

   0: rust_begin_unwind
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/std/src/panicking.rs:495:5
   1: core::panicking::panic_fmt
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/panicking.rs:92:14
   2: core::option::expect_none_failed
             at /rustc/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/option.rs:1268:5
   3: <boa::syntax::lexer::number::NumberLiteral as boa::syntax::lexer::Tokenizer<R>>::lex
   4: boa::syntax::lexer::Lexer<R>::next
   5: boa::syntax::parser::cursor::buffered_lexer::BufferedLexer<R>::fill
   6: boa::syntax::parser::cursor::buffered_lexer::BufferedLexer<R>::peek
   7: <boa::syntax::parser::expression::assignment::exponentiation::ExponentiationExpression as boa::syntax::parser::TokenParser<R>>::parse
   8: <boa::syntax::parser::expression::MultiplicativeExpression as boa::syntax::parser::TokenParser<R>>::parse
   9: <boa::syntax::parser::expression::AdditiveExpression as boa::syntax::parser::TokenParser<R>>::parse
  10: <boa::syntax::parser::expression::ShiftExpression as boa::syntax::parser::TokenParser<R>>::parse
  11: <boa::syntax::parser::expression::RelationalExpression as boa::syntax::parser::TokenParser<R>>::parse
  12: <boa::syntax::parser::expression::EqualityExpression as boa::syntax::parser::TokenParser<R>>::parse
  13: <boa::syntax::parser::expression::BitwiseANDExpression as boa::syntax::parser::TokenParser<R>>::parse
  14: <boa::syntax::parser::expression::BitwiseXORExpression as boa::syntax::parser::TokenParser<R>>::parse
  15: <boa::syntax::parser::expression::BitwiseORExpression as boa::syntax::parser::TokenParser<R>>::parse
  16: <boa::syntax::parser::expression::ShortCircuitExpression as boa::syntax::parser::TokenParser<R>>::parse
  17: <boa::syntax::parser::expression::assignment::conditional::ConditionalExpression as boa::syntax::parser::TokenParser<R>>::parse
  18: <boa::syntax::parser::expression::assignment::AssignmentExpression as boa::syntax::parser::TokenParser<R>>::parse
  19: <boa::syntax::parser::expression::Expression as boa::syntax::parser::TokenParser<R>>::parse
  20: <boa::syntax::parser::statement::Statement as boa::syntax::parser::TokenParser<R>>::parse
  21: <boa::syntax::parser::statement::StatementList as boa::syntax::parser::TokenParser<R>>::parse
  22: boa::context::Context::eval
  23: boa_tester::exec::<impl boa_tester::Test>::run_once
  24: boa_tester::exec::<impl boa_tester::Test>::run
  25: boa_tester::main

This happens here. In theory, at this point in the code, we have already checked that what we are receiving is a valid float literal, but it seems that some representation of it is passing the checks but still fails to parse.

The minimal code that seems to cause this issue is this one:

4.9406564584124654417656879286822e-324;

This should in theory be parsed as 5e-324, but instead, it panics. This might be because Rust doesn't parse floats the same way as JavaScript does, and we are using f64::from_str.

@Razican Razican added bug Something isn't working lexer Issues surrounding the lexer labels Jan 12, 2021
@Razican Razican added this to the v0.12.0 milestone Jan 12, 2021
@Razican Razican mentioned this issue Jan 12, 2021
@tofpie
Copy link
Contributor

tofpie commented Jan 18, 2021

This is related to issue rust-lang/rust#31407.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lexer Issues surrounding the lexer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants