mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibJS: Stop generating switch case statements on block termination
After we terminate a block (e.g. break, continue), we cannot generate anymore bytecode for the block. This caused us to crash with this example code: ``` a = 0; switch (a) { case 0: break; console.log("hello world"); } ``` Anything after a block terminating instruction is considered unreachable code, so we can safely skip any statements after it.
This commit is contained in:
parent
6f29ccaa5a
commit
1fc6bbcdc3
Notes:
sideshowbarker
2024-07-17 17:24:36 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/1fc6bbcdc3 Pull-request: https://github.com/SerenityOS/serenity/pull/13053
@ -1627,6 +1627,8 @@ Bytecode::CodeGenerationErrorOr<void> SwitchStatement::generate_bytecode(Bytecod
|
||||
generator.emit<Bytecode::Op::LoadImmediate>(js_undefined());
|
||||
for (auto& statement : switch_case.children()) {
|
||||
TRY(statement.generate_bytecode(generator));
|
||||
if (generator.is_current_block_terminated())
|
||||
break;
|
||||
}
|
||||
if (!generator.is_current_block_terminated()) {
|
||||
auto next_block = current_block;
|
||||
|
Loading…
Reference in New Issue
Block a user