mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 09:47:41 +00:00
LibJS/Bytecode: Actually exit switch
statement's lexical scope
95 new passes on test262. :^)
This commit is contained in:
parent
cc1bd2d2d9
commit
1f95a40780
1 changed files with 8 additions and 10 deletions
|
@ -29,17 +29,13 @@ Bytecode::CodeGenerationErrorOr<void> ASTNode::generate_bytecode(Bytecode::Gener
|
||||||
|
|
||||||
Bytecode::CodeGenerationErrorOr<void> ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
|
Bytecode::CodeGenerationErrorOr<void> ScopeNode::generate_bytecode(Bytecode::Generator& generator) const
|
||||||
{
|
{
|
||||||
// Note: SwitchStatement has its own codegen, but still calls into this function to handle the scoping of the switch body.
|
|
||||||
auto is_switch_statement = is<SwitchStatement>(*this);
|
|
||||||
bool did_create_lexical_environment = false;
|
bool did_create_lexical_environment = false;
|
||||||
|
|
||||||
if (is<BlockStatement>(*this) || is_switch_statement) {
|
if (is<BlockStatement>(*this)) {
|
||||||
if (has_lexical_declarations()) {
|
if (has_lexical_declarations()) {
|
||||||
generator.block_declaration_instantiation(*this);
|
generator.block_declaration_instantiation(*this);
|
||||||
did_create_lexical_environment = true;
|
did_create_lexical_environment = true;
|
||||||
}
|
}
|
||||||
if (is_switch_statement)
|
|
||||||
return {};
|
|
||||||
} else if (is<Program>(*this)) {
|
} else if (is<Program>(*this)) {
|
||||||
// GlobalDeclarationInstantiation is handled by the C++ AO.
|
// GlobalDeclarationInstantiation is handled by the C++ AO.
|
||||||
} else {
|
} else {
|
||||||
|
@ -2128,9 +2124,9 @@ Bytecode::CodeGenerationErrorOr<void> SwitchStatement::generate_labelled_evaluat
|
||||||
Bytecode::BasicBlock* default_block { nullptr };
|
Bytecode::BasicBlock* default_block { nullptr };
|
||||||
Bytecode::BasicBlock* next_test_block = &generator.make_block();
|
Bytecode::BasicBlock* next_test_block = &generator.make_block();
|
||||||
|
|
||||||
auto has_lexical_block = has_lexical_declarations();
|
auto has_lexical_declarations = this->has_lexical_declarations();
|
||||||
// Note: This call ends up calling begin_variable_scope() if has_lexical_block is true, so we need to clean up after it at the end.
|
if (has_lexical_declarations)
|
||||||
TRY(ScopeNode::generate_bytecode(generator));
|
generator.block_declaration_instantiation(*this);
|
||||||
|
|
||||||
generator.emit<Bytecode::Op::Jump>().set_targets(Bytecode::Label { *next_test_block }, {});
|
generator.emit<Bytecode::Op::Jump>().set_targets(Bytecode::Label { *next_test_block }, {});
|
||||||
|
|
||||||
|
@ -2179,10 +2175,12 @@ Bytecode::CodeGenerationErrorOr<void> SwitchStatement::generate_labelled_evaluat
|
||||||
current_block++;
|
current_block++;
|
||||||
}
|
}
|
||||||
generator.end_breakable_scope();
|
generator.end_breakable_scope();
|
||||||
if (has_lexical_block)
|
|
||||||
generator.end_variable_scope();
|
|
||||||
|
|
||||||
generator.switch_to_basic_block(end_block);
|
generator.switch_to_basic_block(end_block);
|
||||||
|
|
||||||
|
if (has_lexical_declarations)
|
||||||
|
generator.end_variable_scope();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue