Skip to content

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

Closed

Description

@alexanderkjall

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.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.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.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.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.com-1ecc6299db9ec823/Boa-0.10.0/src/exec/statement_list.rs:17
   6: boa::context::Context::eval
             at /home/capitol/.cargo/registry/src/github.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

Activity

  1. added
    A-Bug
    on Oct 3, 2020
  2. croraf commented on Oct 7, 2020

    @croraf
    Contributor

    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.

  3. croraf commented on Oct 10, 2020

    @croraf
    Contributor

    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.

  4. changed the title [-]panic on assignment to number[/-] [+][parser UpdateExpression] panics when the prefix/postfix increment/decrement target is a number[/+] on Oct 12, 2020
  5. croraf commented on Oct 13, 2020

    @croraf
    Contributor

    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

  6. added this to the v0.11.0 milestone on Jan 9, 2021
  7. Razican commented on Jan 9, 2021

    @Razican
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions