Skip to content
New issue

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

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

Already on GitHub? # to your account

[parser UpdateExpression] panics when the prefix/postfix increment/decrement target is a number #779

Closed
alexanderkjall opened this issue Oct 3, 2020 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@alexanderkjall
Copy link

Describe the bug

Expected an Error, not a panic.

To Reproduce

Can be reproduced with this program:

fn main() {
    let mut context = boa::Context::new();
    let _ = context.eval("--245");
}

Expected behavior

An Error, not a panic

Build environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Version: 0.10.0
  • Target triple: [e.g. x86_64-unknown-linux-gnu]
  • Rustc version: 1.48.0-nightly (d006f5734 2020-08-28)

Additional context
Full stacktrace:

thread 'main' panicked at 'TypeError: invalid assignment to 245', /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/context.rs:438:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d006f5734f49625c34d6fc33bf6b9967243abca8/library/std/src/panicking.rs:483
   1: std::panicking::begin_panic_fmt
             at /rustc/d006f5734f49625c34d6fc33bf6b9967243abca8/library/std/src/panicking.rs:437
   2: boa::context::Context::set_value
             at /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/context.rs:438
   3: boa::exec::operator::<impl boa::exec::Executable for boa::syntax::ast::node::operator::UnaryOp>::run
             at /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/operator/mod.rs:206
   4: <boa::syntax::ast::node::Node as boa::exec::Executable>::run
             at /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/mod.rs:108
   5: boa::exec::statement_list::<impl boa::exec::Executable for boa::syntax::ast::node::statement_list::StatementList>::run
             at /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/statement_list.rs:17
   6: boa::context::Context::eval
             at /home/capitol/.cargo/registry/src/github.heygears.com-1ecc6299db9ec823/Boa-0.10.0/src/context.rs:494
   7: boa_reproduce::main
             at ./src/main.rs:3
   8: core::ops::function::FnOnce::call_once
             at /home/capitol/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227
@alexanderkjall alexanderkjall added the bug Something isn't working label Oct 3, 2020
@croraf
Copy link
Contributor

croraf commented Oct 7, 2020

Thanks for submitting. Simple assignment like 3 = 4 do throw correctly. Boa fails in the case of using "number" in Update expressions: https://tc39.es/ecma262/#sec-update-expressions

This should be detected during static analysis.

@croraf
Copy link
Contributor

croraf commented Oct 10, 2020

Can the title be changed to something like [parser UpdateExpression] panics when the prefix/postfix increment/decrement target is a number.

The relevant code bits start in the boa/src/syntax/parser/expression/update.rs.

Regarding prefix increment:
I'm checking the code, and I came to the boa/src/syntax/parser/expression/update.rs line 61 and 70. First of all the target is set to be LeftHandSideExpression instead of the UnaryExpression.

@alexanderkjall alexanderkjall changed the title panic on assignment to number [parser UpdateExpression] panics when the prefix/postfix increment/decrement target is a number Oct 12, 2020
@croraf
Copy link
Contributor

croraf commented Oct 13, 2020

I'm checking the code, and I came to the boa/src/syntax/parser/expression/update.rs line 61 and 70. First of all the target is set to be LeftHandSideExpression instead of the UnaryExpression.
This is solved.

But another problem is:

let lhs = MemberExpression::new(self.allow_yield, self.allow_await).parse(cursor)?;
if let Some(tok) = cursor.peek(0)? {
if tok.kind() == &TokenKind::Punctuator(Punctuator::OpenParen) {
return CallExpression::new(self.allow_yield, self.allow_await, lhs).parse(cursor);
}
}
Ok(lhs)

which doesnt account properly the LHS expressions as per the spec https://tc39.es/ecma262/#prod-LeftHandSideExpression

@Razican Razican added this to the v0.11.0 milestone Jan 9, 2021
@Razican
Copy link
Member

Razican commented Jan 9, 2021

This no longer panics, it returns a TypeError, so I'm closing this as the original issue has been fixed.

@Razican Razican closed this as completed Jan 9, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants