mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-04 10:18:51 +00:00
LibJS: Use Identifier to represent CatchClause parameter names
By doing that we consistently use Identifier node for identifiers and also enable mechanism that registers identifiers in a corresponding ScopePusher for catch parameters, which is necessary for work in the upcoming changes.
This commit is contained in:
parent
42f72bbdce
commit
0f14c70252
Notes:
github-actions[bot]
2025-04-22 19:58:36 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 0f14c70252
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4421
Reviewed-by: https://github.com/gmta
4 changed files with 43 additions and 30 deletions
|
@ -2660,14 +2660,12 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> TryStatement::generate_
|
|||
bool did_create_variable_scope_for_catch_clause = false;
|
||||
|
||||
TRY(m_handler->parameter().visit(
|
||||
[&](FlyString const& parameter) -> Bytecode::CodeGenerationErrorOr<void> {
|
||||
if (!parameter.is_empty()) {
|
||||
generator.begin_variable_scope();
|
||||
did_create_variable_scope_for_catch_clause = true;
|
||||
auto parameter_identifier = generator.intern_identifier(parameter);
|
||||
generator.emit<Bytecode::Op::CreateVariable>(parameter_identifier, Bytecode::Op::EnvironmentMode::Lexical, false);
|
||||
generator.emit<Bytecode::Op::InitializeLexicalBinding>(parameter_identifier, caught_value);
|
||||
}
|
||||
[&](NonnullRefPtr<Identifier const> const& parameter) -> Bytecode::CodeGenerationErrorOr<void> {
|
||||
generator.begin_variable_scope();
|
||||
did_create_variable_scope_for_catch_clause = true;
|
||||
auto parameter_identifier = generator.intern_identifier(parameter->string());
|
||||
generator.emit<Bytecode::Op::CreateVariable>(parameter_identifier, Bytecode::Op::EnvironmentMode::Lexical, false);
|
||||
generator.emit<Bytecode::Op::InitializeLexicalBinding>(parameter_identifier, caught_value);
|
||||
return {};
|
||||
},
|
||||
[&](NonnullRefPtr<BindingPattern const> const& binding_pattern) -> Bytecode::CodeGenerationErrorOr<void> {
|
||||
|
@ -2675,6 +2673,9 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> TryStatement::generate_
|
|||
did_create_variable_scope_for_catch_clause = true;
|
||||
TRY(binding_pattern->generate_bytecode(generator, Bytecode::Op::BindingInitializationMode::Initialize, caught_value, true));
|
||||
return {};
|
||||
},
|
||||
[](Empty) -> Bytecode::CodeGenerationErrorOr<void> {
|
||||
return {};
|
||||
}));
|
||||
|
||||
auto handler_result = TRY(m_handler->body().generate_bytecode(generator));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue