diff --git a/modules/rhino/src/main/java/com/script/rhino/RhinoCompiledScript.kt b/modules/rhino/src/main/java/com/script/rhino/RhinoCompiledScript.kt index 12fe9c91b..3afcded08 100644 --- a/modules/rhino/src/main/java/com/script/rhino/RhinoCompiledScript.kt +++ b/modules/rhino/src/main/java/com/script/rhino/RhinoCompiledScript.kt @@ -56,12 +56,6 @@ internal class RhinoCompiledScript( override fun eval(scope: Scriptable, coroutineContext: CoroutineContext?): Any? { val cx = Context.enter() as RhinoContext - try { - cx.checkRecursive() - } catch (e: RhinoRecursionError) { - Context.exit() - throw e - } val previousCoroutineContext = cx.coroutineContext if (coroutineContext != null && coroutineContext[Job] != null) { cx.coroutineContext = coroutineContext @@ -70,6 +64,7 @@ internal class RhinoCompiledScript( cx.recursiveCount++ val result: Any? try { + cx.checkRecursive() val ret = script.exec(cx, scope) result = engine.unwrapReturnValue(ret) } catch (re: RhinoException) { @@ -93,17 +88,12 @@ internal class RhinoCompiledScript( override suspend fun evalSuspend(scope: Scriptable): Any? { val cx = Context.enter() as RhinoContext - try { - cx.checkRecursive() - } catch (e: RhinoRecursionError) { - Context.exit() - throw e - } var ret: Any? withContext(VMBridgeReflect.contextLocal.asContextElement()) { cx.allowScriptRun = true cx.recursiveCount++ try { + cx.checkRecursive() try { ret = cx.executeScriptWithContinuations(script, scope) } catch (e: ContinuationPending) { diff --git a/modules/rhino/src/main/java/com/script/rhino/RhinoScriptEngine.kt b/modules/rhino/src/main/java/com/script/rhino/RhinoScriptEngine.kt index 7ee6b6c48..721e7f2ed 100644 --- a/modules/rhino/src/main/java/com/script/rhino/RhinoScriptEngine.kt +++ b/modules/rhino/src/main/java/com/script/rhino/RhinoScriptEngine.kt @@ -91,12 +91,6 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable { coroutineContext: CoroutineContext? ): Any? { val cx = Context.enter() as RhinoContext - try { - cx.checkRecursive() - } catch (e: RhinoRecursionError) { - Context.exit() - throw e - } val previousCoroutineContext = cx.coroutineContext if (coroutineContext != null && coroutineContext[Job] != null) { cx.coroutineContext = coroutineContext @@ -105,6 +99,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable { cx.recursiveCount++ val ret: Any? try { + cx.checkRecursive() var filename = this["javax.script.filename"] as? String filename = filename ?: "" ret = cx.evaluateReader(scope, reader, filename, 1, null) @@ -132,17 +127,12 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable { @Throws(ContinuationPending::class) override suspend fun evalSuspend(reader: Reader, scope: Scriptable): Any? { val cx = Context.enter() as RhinoContext - try { - cx.checkRecursive() - } catch (e: RhinoRecursionError) { - Context.exit() - throw e - } var ret: Any? withContext(VMBridgeReflect.contextLocal.asContextElement()) { cx.allowScriptRun = true cx.recursiveCount++ try { + cx.checkRecursive() var filename = this@RhinoScriptEngine["javax.script.filename"] as? String filename = filename ?: "" val script = cx.compileReader(reader, filename, 1, null)