diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:09:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-04 21:09:06 +0200 |
commit | 9c8363bb5fb1853aedc085e57aafea4b19831223 (patch) | |
tree | 10c3218f49ef02bca569b8d94a18d32c76276ee9 /Libraries | |
parent | 42f47da75dbac8726091da39b69155c0982530f6 (diff) | |
download | serenity-9c8363bb5fb1853aedc085e57aafea4b19831223.zip |
LibJS: Allow "for" statement without curly braces around body
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Parser.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/for-no-curlies.js | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index d9d1cbd7a4..6541f51fc0 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -810,7 +810,7 @@ NonnullRefPtr<ForStatement> Parser::parse_for_statement() consume(TokenType::ParenClose); - auto body = parse_block_statement(); + auto body = parse_statement(); return create_ast_node<ForStatement>(move(init), move(test), move(update), move(body)); } diff --git a/Libraries/LibJS/Tests/for-no-curlies.js b/Libraries/LibJS/Tests/for-no-curlies.js new file mode 100644 index 0000000000..817aea2fbb --- /dev/null +++ b/Libraries/LibJS/Tests/for-no-curlies.js @@ -0,0 +1,14 @@ +function assert(x) { if (!x) throw 1; } + +try { + var number = 0; + + for (var i = 0; i < 3; ++i) + for (var j = 0; j < 3; ++j) + number++; + + assert(number === 9); + console.log("PASS"); +} catch (e) { + console.log("FAIL: " + e); +} |