mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 23:09:08 +00:00
LibJS/Bytecode: Setup declarative environment for lexical for statements
This commit is contained in:
parent
97af7654dd
commit
750b69540e
Notes:
sideshowbarker
2024-07-17 17:26:52 +09:00
Author: https://github.com/Lubrsi
Commit: 750b69540e
Pull-request: https://github.com/SerenityOS/serenity/pull/13039
Reviewed-by: https://github.com/davidot
1 changed files with 25 additions and 1 deletions
|
@ -723,8 +723,29 @@ Bytecode::CodeGenerationErrorOr<void> ForStatement::generate_bytecode(Bytecode::
|
|||
|
||||
auto& end_block = generator.make_block();
|
||||
|
||||
if (m_init)
|
||||
bool has_lexical_environment = false;
|
||||
|
||||
if (m_init) {
|
||||
if (m_init->is_variable_declaration()) {
|
||||
auto& variable_declaration = verify_cast<VariableDeclaration>(*m_init);
|
||||
|
||||
if (variable_declaration.is_lexical_declaration()) {
|
||||
has_lexical_environment = true;
|
||||
|
||||
// FIXME: Is Block correct?
|
||||
generator.begin_variable_scope(Bytecode::Generator::BindingMode::Lexical, Bytecode::Generator::SurroundingScopeKind::Block);
|
||||
|
||||
bool is_const = variable_declaration.is_constant_declaration();
|
||||
variable_declaration.for_each_bound_name([&](auto const& name) {
|
||||
auto index = generator.intern_identifier(name);
|
||||
generator.register_binding(index);
|
||||
generator.emit<Bytecode::Op::CreateVariable>(index, Bytecode::Op::EnvironmentMode::Lexical, is_const);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TRY(m_init->generate_bytecode(generator));
|
||||
}
|
||||
|
||||
body_block_ptr = &generator.make_block();
|
||||
|
||||
|
@ -761,6 +782,9 @@ Bytecode::CodeGenerationErrorOr<void> ForStatement::generate_bytecode(Bytecode::
|
|||
generator.end_breakable_scope();
|
||||
generator.end_continuable_scope();
|
||||
|
||||
if (has_lexical_environment)
|
||||
generator.end_variable_scope();
|
||||
|
||||
if (!generator.is_current_block_terminated()) {
|
||||
if (m_update) {
|
||||
generator.emit<Bytecode::Op::Jump>().set_targets(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue