From f7d64e9fa8998b69efe0d0d729c8de98d94efacc Mon Sep 17 00:00:00 2001 From: speles Date: Fri, 26 Feb 2021 00:37:27 +0200 Subject: [PATCH] LibJS: Set declared for-in and for-of variables as first time. These declarations might be const, and now when we're handling it properly, we have to set values to them correctly. --- Userland/Libraries/LibJS/AST.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 6d11821451..57b5773aab 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -476,7 +476,8 @@ Value ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_obj interpreter.enter_node(*this); ScopeGuard exit_node { [&] { interpreter.exit_node(*this); } }; - if (!is(*m_lhs) && !is(*m_lhs)) { + bool has_declaration = is(*m_lhs); + if (!has_declaration && !is(*m_lhs)) { // FIXME: Implement "for (foo.bar in baz)", "for (foo[0] in bar)" VERIFY_NOT_REACHED(); } @@ -494,7 +495,7 @@ Value ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_obj while (object) { auto property_names = object->get_own_properties(*object, Object::PropertyKind::Key, true); for (auto& property_name : property_names.as_object().indexed_properties()) { - interpreter.vm().set_variable(variable_name, property_name.value_and_attributes(object).value, global_object); + interpreter.vm().set_variable(variable_name, property_name.value_and_attributes(object).value, global_object, has_declaration); if (interpreter.exception()) return {}; last_value = interpreter.execute_statement(global_object, *m_body); @@ -523,7 +524,8 @@ Value ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_obj interpreter.enter_node(*this); ScopeGuard exit_node { [&] { interpreter.exit_node(*this); } }; - if (!is(*m_lhs) && !is(*m_lhs)) { + bool has_declaration = is(*m_lhs); + if (!has_declaration && !is(*m_lhs)) { // FIXME: Implement "for (foo.bar of baz)", "for (foo[0] of bar)" VERIFY_NOT_REACHED(); } @@ -539,7 +541,7 @@ Value ForOfStatement::execute(Interpreter& interpreter, GlobalObject& global_obj return {}; get_iterator_values(global_object, rhs_result, [&](Value value) { - interpreter.vm().set_variable(variable_name, value, global_object); + interpreter.vm().set_variable(variable_name, value, global_object, has_declaration); last_value = interpreter.execute_statement(global_object, *m_body); if (interpreter.exception()) return IterationDecision::Break;