1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:08:12 +00:00

LibJS: Add support for binding patterns in catch clauses

`try { ... } catch({a=foo}) {}` is valid, and now we parse and evaluate
it correctly :^)
This commit is contained in:
Ali Mohammad Pur 2021-07-11 15:15:38 +04:30 committed by Linus Groh
parent 1a9518ebe3
commit 77a5144264
4 changed files with 73 additions and 15 deletions

View file

@ -1215,10 +1215,18 @@ void TryStatement::generate_bytecode(Bytecode::Generator& generator) const
generator.switch_to_basic_block(handler_block);
if (!m_finalizer)
generator.emit<Bytecode::Op::LeaveUnwindContext>();
if (!m_handler->parameter().is_empty()) {
// FIXME: We need a separate DeclarativeEnvironment here
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(m_handler->parameter()));
}
m_handler->parameter().visit(
[&](FlyString const& parameter) {
if (parameter.is_empty()) {
// FIXME: We need a separate DeclarativeEnvironment here
generator.emit<Bytecode::Op::SetVariable>(generator.intern_string(parameter));
}
},
[&](NonnullRefPtr<BindingPattern> const&) {
// FIXME: Implement this path when the above DeclrativeEnvironment issue is dealt with.
TODO();
});
m_handler->body().generate_bytecode(generator);
handler_target = Bytecode::Label { handler_block };
if (!generator.is_current_block_terminated()) {