1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

LibJS: Fix runaway let scope when parsing for-in/of statements

This requires variables that should be exported to the script host
or to other scripts to be declared as var (such as in test-common.js),
since lexically-scoped variables won't be visible.
This commit is contained in:
Hendi 2021-07-05 21:31:51 +02:00 committed by Linus Groh
parent 793e1bf28a
commit c194afd17c
2 changed files with 10 additions and 9 deletions

View file

@ -2033,6 +2033,11 @@ NonnullRefPtr<Statement> Parser::parse_for_statement()
consume(TokenType::ParenOpen);
bool in_scope = false;
ScopeGuard guard([&]() {
if (in_scope)
m_state.let_scopes.take_last();
});
RefPtr<ASTNode> init;
if (!match(TokenType::Semicolon)) {
if (match_expression()) {
@ -2075,10 +2080,6 @@ NonnullRefPtr<Statement> Parser::parse_for_statement()
TemporaryChange continue_change(m_state.in_continue_context, true);
auto body = parse_statement();
if (in_scope) {
m_state.let_scopes.take_last();
}
return create_ast_node<ForStatement>({ m_state.current_token.filename(), rule_start.position(), position() }, move(init), move(test), move(update), move(body));
}