瀏覽代碼

LibJS: Skip bindings creation for locals during block declaration init

No need to create bindings for local variables as their values are not
stored in an environment.
Aliaksandr Kalenik 2 年之前
父節點
當前提交
4a9a1d1656
共有 1 個文件被更改,包括 7 次插入1 次删除
  1. 7 1
      Userland/Libraries/LibJS/AST.cpp

+ 7 - 1
Userland/Libraries/LibJS/AST.cpp

@@ -4757,7 +4757,13 @@ void ScopeNode::block_declaration_instantiation(VM& vm, Environment* environment
         auto is_constant_declaration = declaration.is_constant_declaration();
         auto is_constant_declaration = declaration.is_constant_declaration();
         // NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below,
         // NOTE: Due to the use of MUST with `create_immutable_binding` and `create_mutable_binding` below,
         //       an exception should not result from `for_each_bound_name`.
         //       an exception should not result from `for_each_bound_name`.
-        MUST(declaration.for_each_bound_name([&](auto const& name) {
+        MUST(declaration.for_each_bound_identifier([&](auto const& identifier) {
+            if (vm.bytecode_interpreter_if_exists() && identifier.is_local()) {
+                // NOTE: No need to create bindings for local variables as their values are not stored in an environment.
+                return;
+            }
+
+            auto const& name = identifier.string();
             if (is_constant_declaration) {
             if (is_constant_declaration) {
                 MUST(environment->create_immutable_binding(vm, name, true));
                 MUST(environment->create_immutable_binding(vm, name, true));
             } else {
             } else {