优化
This commit is contained in:
@@ -56,12 +56,6 @@ internal class RhinoCompiledScript(
|
|||||||
|
|
||||||
override fun eval(scope: Scriptable, coroutineContext: CoroutineContext?): Any? {
|
override fun eval(scope: Scriptable, coroutineContext: CoroutineContext?): Any? {
|
||||||
val cx = Context.enter() as RhinoContext
|
val cx = Context.enter() as RhinoContext
|
||||||
try {
|
|
||||||
cx.checkRecursive()
|
|
||||||
} catch (e: RhinoRecursionError) {
|
|
||||||
Context.exit()
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
val previousCoroutineContext = cx.coroutineContext
|
val previousCoroutineContext = cx.coroutineContext
|
||||||
if (coroutineContext != null && coroutineContext[Job] != null) {
|
if (coroutineContext != null && coroutineContext[Job] != null) {
|
||||||
cx.coroutineContext = coroutineContext
|
cx.coroutineContext = coroutineContext
|
||||||
@@ -70,6 +64,7 @@ internal class RhinoCompiledScript(
|
|||||||
cx.recursiveCount++
|
cx.recursiveCount++
|
||||||
val result: Any?
|
val result: Any?
|
||||||
try {
|
try {
|
||||||
|
cx.checkRecursive()
|
||||||
val ret = script.exec(cx, scope)
|
val ret = script.exec(cx, scope)
|
||||||
result = engine.unwrapReturnValue(ret)
|
result = engine.unwrapReturnValue(ret)
|
||||||
} catch (re: RhinoException) {
|
} catch (re: RhinoException) {
|
||||||
@@ -93,17 +88,12 @@ internal class RhinoCompiledScript(
|
|||||||
|
|
||||||
override suspend fun evalSuspend(scope: Scriptable): Any? {
|
override suspend fun evalSuspend(scope: Scriptable): Any? {
|
||||||
val cx = Context.enter() as RhinoContext
|
val cx = Context.enter() as RhinoContext
|
||||||
try {
|
|
||||||
cx.checkRecursive()
|
|
||||||
} catch (e: RhinoRecursionError) {
|
|
||||||
Context.exit()
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
var ret: Any?
|
var ret: Any?
|
||||||
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
||||||
cx.allowScriptRun = true
|
cx.allowScriptRun = true
|
||||||
cx.recursiveCount++
|
cx.recursiveCount++
|
||||||
try {
|
try {
|
||||||
|
cx.checkRecursive()
|
||||||
try {
|
try {
|
||||||
ret = cx.executeScriptWithContinuations(script, scope)
|
ret = cx.executeScriptWithContinuations(script, scope)
|
||||||
} catch (e: ContinuationPending) {
|
} catch (e: ContinuationPending) {
|
||||||
|
|||||||
@@ -91,12 +91,6 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
coroutineContext: CoroutineContext?
|
coroutineContext: CoroutineContext?
|
||||||
): Any? {
|
): Any? {
|
||||||
val cx = Context.enter() as RhinoContext
|
val cx = Context.enter() as RhinoContext
|
||||||
try {
|
|
||||||
cx.checkRecursive()
|
|
||||||
} catch (e: RhinoRecursionError) {
|
|
||||||
Context.exit()
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
val previousCoroutineContext = cx.coroutineContext
|
val previousCoroutineContext = cx.coroutineContext
|
||||||
if (coroutineContext != null && coroutineContext[Job] != null) {
|
if (coroutineContext != null && coroutineContext[Job] != null) {
|
||||||
cx.coroutineContext = coroutineContext
|
cx.coroutineContext = coroutineContext
|
||||||
@@ -105,6 +99,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
cx.recursiveCount++
|
cx.recursiveCount++
|
||||||
val ret: Any?
|
val ret: Any?
|
||||||
try {
|
try {
|
||||||
|
cx.checkRecursive()
|
||||||
var filename = this["javax.script.filename"] as? String
|
var filename = this["javax.script.filename"] as? String
|
||||||
filename = filename ?: "<Unknown source>"
|
filename = filename ?: "<Unknown source>"
|
||||||
ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
||||||
@@ -132,17 +127,12 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
@Throws(ContinuationPending::class)
|
@Throws(ContinuationPending::class)
|
||||||
override suspend fun evalSuspend(reader: Reader, scope: Scriptable): Any? {
|
override suspend fun evalSuspend(reader: Reader, scope: Scriptable): Any? {
|
||||||
val cx = Context.enter() as RhinoContext
|
val cx = Context.enter() as RhinoContext
|
||||||
try {
|
|
||||||
cx.checkRecursive()
|
|
||||||
} catch (e: RhinoRecursionError) {
|
|
||||||
Context.exit()
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
var ret: Any?
|
var ret: Any?
|
||||||
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
||||||
cx.allowScriptRun = true
|
cx.allowScriptRun = true
|
||||||
cx.recursiveCount++
|
cx.recursiveCount++
|
||||||
try {
|
try {
|
||||||
|
cx.checkRecursive()
|
||||||
var filename = this@RhinoScriptEngine["javax.script.filename"] as? String
|
var filename = this@RhinoScriptEngine["javax.script.filename"] as? String
|
||||||
filename = filename ?: "<Unknown source>"
|
filename = filename ?: "<Unknown source>"
|
||||||
val script = cx.compileReader(reader, filename, 1, null)
|
val script = cx.compileReader(reader, filename, 1, null)
|
||||||
|
|||||||
Reference in New Issue
Block a user