diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-05-30 10:34:52 +0430 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-30 10:34:44 +0100 |
commit | 724b89f90c859d45ebd66998465549bc99cd313f (patch) | |
tree | 937f792f2245093366a93774dcac2f3f6b603630 /Userland/Libraries/LibJS | |
parent | e10006b3fa3fc5b727c804f68da31a20b0fdbcc9 (diff) | |
download | serenity-724b89f90c859d45ebd66998465549bc99cd313f.zip |
LibJS: Make missing variable decls in for..in/of a syntax error
...instead of a hard crash :P
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Parser.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 12d4f10af1..33b7ae6c4c 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1961,7 +1961,9 @@ NonnullRefPtr<Statement> Parser::parse_for_in_of_statement(NonnullRefPtr<ASTNode auto declarations = static_cast<VariableDeclaration&>(*lhs).declarations(); if (declarations.size() > 1) syntax_error("multiple declarations not allowed in for..in/of"); - if (declarations.first().init() != nullptr) + if (declarations.size() < 1) + syntax_error("need exactly one variable declaration in for..in/of"); + else if (declarations.first().init() != nullptr) syntax_error("variable initializer not allowed in for..in/of"); } auto in_or_of = consume(); |