summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Interpreter.cpp
diff options
context:
space:
mode:
author0xtechnobabble <0xtechnobabble@protonmail.com>2020-03-15 23:57:54 +0200
committerAndreas Kling <kling@serenityos.org>2020-03-16 13:42:13 +0100
commit7aad10d9849f9133f987a6130b330220896ccc58 (patch)
treeaf8d4626a2cfb6799eb171ca5fd8872ec572d09b /Libraries/LibJS/Interpreter.cpp
parent2a32330257b96922d9ed274baf6fc96abca957f0 (diff)
downloadserenity-7aad10d9849f9133f987a6130b330220896ccc58.zip
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. :/
Diffstat (limited to 'Libraries/LibJS/Interpreter.cpp')
-rw-r--r--Libraries/LibJS/Interpreter.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/Libraries/LibJS/Interpreter.cpp b/Libraries/LibJS/Interpreter.cpp
index 1f5c6d1e1c..5ca89f28f2 100644
--- a/Libraries/LibJS/Interpreter.cpp
+++ b/Libraries/LibJS/Interpreter.cpp
@@ -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 });