summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Interpreter.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-06-09 23:21:42 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-09 23:25:16 +0200
commit4bc98fd39fb5538f838c1767e613f93b32b07c3c (patch)
tree3ce544b311b73ddb135dc37a15cf9ba80e989e3a /Userland/Libraries/LibJS/Interpreter.cpp
parentd5fa0ea60fee93557c599cf6bb68b4db44e0122f (diff)
downloadserenity-4bc98fd39fb5538f838c1767e613f93b32b07c3c.zip
LibJS: Only "var" declarations go in the global object at program level
"let" and "const" go in the lexical environment. This fixes one part of #4001 (Lexically declared variables are mixed up with global object properties)
Diffstat (limited to 'Userland/Libraries/LibJS/Interpreter.cpp')
-rw-r--r--Userland/Libraries/LibJS/Interpreter.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Interpreter.cpp b/Userland/Libraries/LibJS/Interpreter.cpp
index ebad86ede1..90f4584948 100644
--- a/Userland/Libraries/LibJS/Interpreter.cpp
+++ b/Userland/Libraries/LibJS/Interpreter.cpp
@@ -94,9 +94,11 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
HashMap<FlyString, Variable> scope_variables_with_declaration_kind;
scope_variables_with_declaration_kind.ensure_capacity(16);
+ bool is_program_node = is<Program>(scope_node);
+
for (auto& declaration : scope_node.variables()) {
for (auto& declarator : declaration.declarations()) {
- if (is<Program>(scope_node)) {
+ if (is_program_node && declaration.declaration_kind() == DeclarationKind::Var) {
declarator.target().visit(
[&](const NonnullRefPtr<Identifier>& id) {
global_object.put(id->string(), js_undefined());