mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-04 17:33:04 +00:00
LibJS: Fix crash in bytecode generator on https://twinings.co.uk/
If the current block has already been terminated, we should just skip creating a per-iteration environment.
This commit is contained in:
parent
c5afe70f77
commit
9a7e6158af
Notes:
github-actions[bot]
2024-07-24 09:14:46 +00:00
Author: https://github.com/awesomekling
Commit: 9a7e6158af
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/804
2 changed files with 22 additions and 6 deletions
|
@ -1042,9 +1042,12 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForStatement::generate_
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (m_init) {
|
||||||
// CreatePerIterationEnvironment where lastIterationEnv is the variable
|
// CreatePerIterationEnvironment where lastIterationEnv is the variable
|
||||||
// scope created above for bound identifiers
|
// scope created above for bound identifiers
|
||||||
generate_per_iteration_bindings();
|
generate_per_iteration_bindings();
|
||||||
|
}
|
||||||
|
|
||||||
body_block_ptr = &generator.make_block();
|
body_block_ptr = &generator.make_block();
|
||||||
|
|
||||||
if (m_update)
|
if (m_update)
|
||||||
|
@ -1082,10 +1085,11 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForStatement::generate_
|
||||||
generator.end_breakable_scope();
|
generator.end_breakable_scope();
|
||||||
generator.end_continuable_scope();
|
generator.end_continuable_scope();
|
||||||
|
|
||||||
|
if (!generator.is_current_block_terminated()) {
|
||||||
// CreatePerIterationEnvironment where lastIterationEnv is the environment
|
// CreatePerIterationEnvironment where lastIterationEnv is the environment
|
||||||
// created by the previous CreatePerIterationEnvironment setup
|
// created by the previous CreatePerIterationEnvironment setup
|
||||||
generate_per_iteration_bindings();
|
generate_per_iteration_bindings();
|
||||||
if (!generator.is_current_block_terminated()) {
|
|
||||||
if (m_update) {
|
if (m_update) {
|
||||||
generator.emit<Bytecode::Op::Jump>(Bytecode::Label { *update_block_ptr });
|
generator.emit<Bytecode::Op::Jump>(Bytecode::Label { *update_block_ptr });
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
test("check that codegen doesn't crash", () => {
|
||||||
|
function func(x) {
|
||||||
|
expect(x()).toBe(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function go() {
|
||||||
|
for (let i = 0; ; ) {
|
||||||
|
func(() => i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue