diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-03-14 02:38:13 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-14 21:15:27 +0330 |
commit | 97af7654dd3d5d6917d2693ba2162d0035750f21 (patch) | |
tree | fc4a931e923735fae318cd9c787042ef26c8a643 /Userland/Libraries/LibJS | |
parent | 04774f923fa0f80fc4e8f6a718f83f8f776890fc (diff) | |
download | serenity-97af7654dd3d5d6917d2693ba2162d0035750f21.zip |
LibJS/Bytecode: Setup declarative environment for catch with variable
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 3bd8ee32d7..4453d9d011 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1479,11 +1479,14 @@ Bytecode::CodeGenerationErrorOr<void> TryStatement::generate_bytecode(Bytecode:: if (m_handler) { auto& handler_block = generator.make_block(); generator.switch_to_basic_block(handler_block); + generator.begin_variable_scope(Bytecode::Generator::BindingMode::Lexical, Bytecode::Generator::SurroundingScopeKind::Block); TRY(m_handler->parameter().visit( [&](FlyString const& parameter) -> Bytecode::CodeGenerationErrorOr<void> { if (!parameter.is_empty()) { - // FIXME: We need a separate DeclarativeEnvironment here - generator.emit<Bytecode::Op::SetVariable>(generator.intern_identifier(parameter)); + auto parameter_identifier = generator.intern_identifier(parameter); + generator.register_binding(parameter_identifier); + generator.emit<Bytecode::Op::CreateVariable>(parameter_identifier, Bytecode::Op::EnvironmentMode::Lexical, false); + generator.emit<Bytecode::Op::SetVariable>(parameter_identifier, Bytecode::Op::SetVariable::InitializationMode::Initialize); } return {}; }, @@ -1497,6 +1500,8 @@ Bytecode::CodeGenerationErrorOr<void> TryStatement::generate_bytecode(Bytecode:: TRY(m_handler->body().generate_bytecode(generator)); handler_target = Bytecode::Label { handler_block }; + generator.end_variable_scope(); + if (!generator.is_current_block_terminated()) { if (m_finalizer) { generator.emit<Bytecode::Op::LeaveUnwindContext>(); |