1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-29 01:22:11 +00:00

LibJS: More properly implement scoping rules in bytecode codegen

Now we emit CreateVariable and SetVariable with the appropriate
initialization/environment modes, much closer to the spec.
This makes a whole lot of things like let/const variables, function
and variable hoisting and some other things work :^)
This commit is contained in:
Ali Mohammad Pur 2022-02-12 19:48:45 +03:30 committed by Linus Groh
parent c7e6b65fd2
commit 1bbfaf8627
12 changed files with 503 additions and 38 deletions

View file

@ -542,14 +542,16 @@ ThrowCompletionOr<void> ECMAScriptFunctionObject::function_declaration_instantia
if (!scope_body)
return {};
scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
declaration.for_each_bound_name([&](auto const& name) {
if (declaration.is_constant_declaration())
MUST(lex_environment->create_immutable_binding(global_object(), name, true));
else
MUST(lex_environment->create_mutable_binding(global_object(), name, false));
if (!Bytecode::Interpreter::current()) {
scope_body->for_each_lexically_scoped_declaration([&](Declaration const& declaration) {
declaration.for_each_bound_name([&](auto const& name) {
if (declaration.is_constant_declaration())
MUST(lex_environment->create_immutable_binding(global_object(), name, true));
else
MUST(lex_environment->create_mutable_binding(global_object(), name, false));
});
});
});
}
auto* private_environment = callee_context.private_environment;
for (auto& declaration : functions_to_initialize) {