From 955af1565bd440b4954a7cbd3db4278b669302e7 Mon Sep 17 00:00:00 2001 From: Attila Szegedi Date: Thu, 4 Jul 2024 13:34:43 +0200 Subject: [PATCH] More idiomatic loop, without continues and unconditional break at bottom. --- .../org/mozilla/javascript/Interpreter.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java index eb3df9fe74..48a1844b8a 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java +++ b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java @@ -1774,23 +1774,21 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl calleeScope = ScriptableObject.getTopLevelScope(frame.scope); } - // Iteratively peel known function types that can be reduced: - // arrows, lambdas, bound functions, call/apply, and - // no-such-method-handler in order to make a best-effort to keep - // them in this interpreter loop so continuations keep working. - // The loop initializer and condition are formulated so that - // they short-circuit the loop if the function is already an - // interpreted function, which should be the majority of cases. + // Iteratively reduce known function types: arrows, lambdas, + // bound functions, call/apply, and no-such-method-handler in + // order to make a best-effort to keep them in this interpreter + // loop so continuations keep working. The loop initializer and + // condition are formulated so that they short-circuit the loop + // if the function is already an interpreted function, which + // should be the majority of cases. for (boolean notInt = !(fun instanceof InterpretedFunction); notInt; ) { if (fun instanceof ArrowFunction) { ArrowFunction afun = (ArrowFunction) fun; fun = afun.getTargetFunction(); funThisObj = afun.getCallThis(cx); - continue; } else if (fun instanceof LambdaFunction) { fun = ((LambdaFunction) fun).getTarget(); - continue; } else if (fun instanceof BoundFunction) { BoundFunction bfun = (BoundFunction) fun; fun = bfun.getTargetFunction(); @@ -1818,7 +1816,6 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl boundArgs, 0, stack, stackTop + 2, blen); indexReg += blen; } - continue; } else if (fun instanceof IdFunctionObject) { IdFunctionObject ifun = (IdFunctionObject) fun; // Bug 405654 -- make the best effort to keep @@ -1878,7 +1875,10 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl indexReg--; } } - continue; + } else { + // Some other IdFunctionObject we don't know how to + // reduce. + break; } } else if (fun instanceof NoSuchMethodShim) { NoSuchMethodShim nsmfun = (NoSuchMethodShim) fun; @@ -1895,15 +1895,13 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl stack[stackTop + 3] = cx.newArray(calleeScope, elements); indexReg = 2; - continue; } else if (fun == null) { throw ScriptRuntime.notFunctionError(null, null); + } else { + // Current function is something that we can't reduce + // further. + break; } - - // We reached here without any of the continue statements - // triggering. Current function is something that we can't - // peel back further. - break; } if (fun instanceof InterpretedFunction) {