mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-03 17:58:49 +00:00
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)
This commit is contained in:
parent
d5fa0ea60f
commit
4bc98fd39f
Notes:
sideshowbarker
2024-07-18 12:30:37 +09:00
Author: https://github.com/awesomekling
Commit: 4bc98fd39f
2 changed files with 24 additions and 1 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue