mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03:00
LibJS: Handle "for" statements with empty initializer and updater
This commit is contained in:
parent
30d24af54a
commit
6c9d2cfa5e
Notes:
sideshowbarker
2024-07-19 08:08:02 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6c9d2cfa5e1
@ -126,7 +126,7 @@ Value ForStatement::execute(Interpreter& interpreter) const
|
||||
{
|
||||
RefPtr<BlockStatement> wrapper;
|
||||
|
||||
if (m_init->is_variable_declaration() && static_cast<const VariableDeclaration*>(m_init.ptr())->declaration_type() != DeclarationType::Var) {
|
||||
if (m_init && m_init->is_variable_declaration() && static_cast<const VariableDeclaration*>(m_init.ptr())->declaration_type() != DeclarationType::Var) {
|
||||
wrapper = create_ast_node<BlockStatement>();
|
||||
interpreter.enter_scope(*wrapper, {}, ScopeType::Block);
|
||||
}
|
||||
|
@ -612,7 +612,7 @@ NonnullRefPtr<ForStatement> Parser::parse_for_statement()
|
||||
|
||||
RefPtr<Expression> update;
|
||||
switch (m_current_token.type()) {
|
||||
case TokenType::Semicolon:
|
||||
case TokenType::ParenClose:
|
||||
break;
|
||||
default:
|
||||
update = parse_expression(0);
|
||||
|
24
Libraries/LibJS/Tests/for-basic.js
Normal file
24
Libraries/LibJS/Tests/for-basic.js
Normal file
@ -0,0 +1,24 @@
|
||||
function assert(x) { if (!x) throw 1; }
|
||||
|
||||
try {
|
||||
var a = [];
|
||||
for (var i = 0; i < 3; ++i) {
|
||||
a.push(i);
|
||||
}
|
||||
assert(a.length === 3);
|
||||
assert(a[0] === 0);
|
||||
assert(a[1] === 1);
|
||||
assert(a[2] === 2);
|
||||
|
||||
for (; a.length < 6;) {
|
||||
a.push('x');
|
||||
}
|
||||
assert(a.length === 6);
|
||||
assert(a[3] === 'x');
|
||||
assert(a[4] === 'x');
|
||||
assert(a[5] === 'x');
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Reference in New Issue
Block a user