1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:05:08 +00:00

LibJS: Fix assignment of const variable on declaration

We were previously assuming that we were reassigning a variable even
when we were not, oops, my bad. :/
This commit is contained in:
0xtechnobabble 2020-03-15 23:57:54 +02:00 committed by Andreas Kling
parent 2a32330257
commit 7aad10d984
3 changed files with 4 additions and 4 deletions

View file

@ -108,14 +108,14 @@ void Interpreter::declare_variable(String name, DeclarationType declaration_type
}
}
void Interpreter::set_variable(String name, Value value)
void Interpreter::set_variable(String name, Value value, bool first_assignment)
{
for (ssize_t i = m_scope_stack.size() - 1; i >= 0; --i) {
auto& scope = m_scope_stack.at(i);
auto possible_match = scope.variables.get(name);
if (possible_match.has_value()) {
if (possible_match.value().declaration_type == DeclarationType::Const)
if (!first_assignment && possible_match.value().declaration_type == DeclarationType::Const)
ASSERT_NOT_REACHED();
scope.variables.set(move(name), { move(value), possible_match.value().declaration_type });