From e575b3287e6bb9cb882ff710174a7ca095373b8b Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:57:41 +0200 Subject: [PATCH] fix: try-catch-finally fix #457846982 --- .../jscript/engine/frame/CodeFrame.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/me/topchetoeu/jscript/engine/frame/CodeFrame.java b/src/me/topchetoeu/jscript/engine/frame/CodeFrame.java index 23671cf..c85a589 100644 --- a/src/me/topchetoeu/jscript/engine/frame/CodeFrame.java +++ b/src/me/topchetoeu/jscript/engine/frame/CodeFrame.java @@ -38,8 +38,10 @@ public class CodeFrame { return ptr >= start && ptr < end; } + public void setCause(EngineException target) { + if (error != null) target.setCause(error); + } public TryCtx _catch(EngineException e) { - if (error != null) e.setCause(error); return new TryCtx(TryState.CATCH, e, result, restoreStackPtr, start, end, -1, finallyStart); } public TryCtx _finally(PendingResult res) { @@ -221,6 +223,7 @@ public class CodeFrame { TryCtx newCtx = null; if (error != null) { + tryCtx.setCause(error); if (tryCtx.hasCatch()) newCtx = tryCtx._catch(error); else if (tryCtx.hasFinally()) newCtx = tryCtx._finally(PendingResult.ofThrow(error, instr)); } @@ -269,15 +272,17 @@ public class CodeFrame { tryStack.pop(); codePtr = tryCtx.end; if (tryCtx.result.instruction != null) instr = tryCtx.result.instruction; - if (tryCtx.result.isJump) { - codePtr = tryCtx.result.ptr; - jumpFlag = true; + if (!jumpFlag && returnValue == Runners.NO_RETURN && error == null) { + if (tryCtx.result.isJump) { + codePtr = tryCtx.result.ptr; + jumpFlag = true; + } + if (tryCtx.result.isReturn) returnValue = tryCtx.result.value; + if (error == null && tryCtx.result.isThrow) { + error = tryCtx.result.error; + } } - if (tryCtx.result.isReturn) returnValue = tryCtx.result.value; - if (tryCtx.result.isThrow) { - error = tryCtx.result.error; - } - if (error != null) error.setCause(tryCtx.error); + if (error != null) tryCtx.setCause(error); continue; } }