diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 81aa6bd59a560d..18880633cda8cf 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -277,6 +277,7 @@ void Interpreter::run_bytecode() if (result.is_error()) [[unlikely]] { reg(Register::exception()) = *result.throw_completion().value(); + m_scheduled_jump = {}; auto const* handler = m_current_block->handler(); auto const* finalizer = m_current_block->finalizer(); if (!handler && !finalizer) diff --git a/Userland/Libraries/LibJS/Tests/try-finally-break.js b/Userland/Libraries/LibJS/Tests/try-finally-break.js index bcceb4044ce02a..5699acda12feea 100644 --- a/Userland/Libraries/LibJS/Tests/try-finally-break.js +++ b/Userland/Libraries/LibJS/Tests/try-finally-break.js @@ -339,3 +339,25 @@ test("labelled break in finally overrides labelled break in try", () => { expect(executionOrder).toEqual([1, 2]); }); + +test("Throw while breaking", () => { + const executionOrder = []; + try { + for (const i = 1337; ; expect().fail("Jumped to for loop update block")) { + try { + executionOrder.push(1); + break; + } finally { + executionOrder.push(2); + throw 1; + } + } + } finally { + executionOrder.push(3); + } + expect(() => { + i; + }).toThrowWithMessage(ReferenceError, "'i' is not defined"); + + expect(executionOrder).toEqual([1, 2, 3]); +});