From c699102e56cf01a08deb9538b0c0d85665f16cdd Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 25 Dec 2024 02:51:02 +0200 Subject: [PATCH] try-catch AGAIN --- .../me/topchetoeu/jscript/runtime/Frame.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/topchetoeu/jscript/runtime/Frame.java b/src/main/java/me/topchetoeu/jscript/runtime/Frame.java index f5f8b2f..66e0c94 100644 --- a/src/main/java/me/topchetoeu/jscript/runtime/Frame.java +++ b/src/main/java/me/topchetoeu/jscript/runtime/Frame.java @@ -287,15 +287,18 @@ public final class Frame { } if (returnValue != null) { - dbg.onInstruction(env, this, instr, returnValue, null, false); - return returnValue; + dbg.onInstruction(env, this, instr, returnValue, null, false); + return returnValue; } if (error != null) { var caught = false; - for (var frame : dbg.getStackFrames()) { + loop: for (var frame : Frame.get(env)) { for (var tryCtx : frame.tryStack) { - if (tryCtx.state == TryState.TRY) caught = true; + if (tryCtx.state == TryState.TRY) { + caught = true; + break loop; + } } } @@ -350,8 +353,8 @@ public final class Frame { DebugContext.get(env).onFramePush(env, this); } public void onPop() { - get(env).pop(); DebugContext.get(env).onFramePop(env, this); + get(env).pop(); } /** @@ -398,6 +401,9 @@ public final class Frame { } public static Frame get(Environment env, int i) { var stack = get(env); - return stack.get(stack.size() - i - 1); + i = stack.size() - i - 1; + if (i < 0 || i >= stack.size()) return null; + + return stack.get(i); } }