|
@@ -33,6 +33,7 @@ import kotlinx.coroutines.withContext
|
|
|
import org.mozilla.javascript.*
|
|
import org.mozilla.javascript.*
|
|
|
import java.io.IOException
|
|
import java.io.IOException
|
|
|
import kotlin.coroutines.Continuation
|
|
import kotlin.coroutines.Continuation
|
|
|
|
|
+import kotlin.coroutines.CoroutineContext
|
|
|
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
|
|
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -96,6 +97,31 @@ internal class RhinoCompiledScript(
|
|
|
return result
|
|
return result
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ override fun eval(scope: Scriptable, coroutineContext: CoroutineContext?): Any? {
|
|
|
|
|
+ val cx = Context.enter()
|
|
|
|
|
+ if (cx is RhinoContext) {
|
|
|
|
|
+ cx.coroutineContext = coroutineContext
|
|
|
|
|
+ }
|
|
|
|
|
+ val result: Any?
|
|
|
|
|
+ try {
|
|
|
|
|
+ val ret = script.exec(cx, scope)
|
|
|
|
|
+ result = engine.unwrapReturnValue(ret)
|
|
|
|
|
+ } catch (re: RhinoException) {
|
|
|
|
|
+ val line = if (re.lineNumber() == 0) -1 else re.lineNumber()
|
|
|
|
|
+ val msg: String = if (re is JavaScriptException) {
|
|
|
|
|
+ re.value.toString()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ re.toString()
|
|
|
|
|
+ }
|
|
|
|
|
+ val se = ScriptException(msg, re.sourceName(), line)
|
|
|
|
|
+ se.initCause(re)
|
|
|
|
|
+ throw se
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ Context.exit()
|
|
|
|
|
+ }
|
|
|
|
|
+ return result
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
override suspend fun evalSuspend(scope: Scriptable): Any? {
|
|
override suspend fun evalSuspend(scope: Scriptable): Any? {
|
|
|
val cx = Context.enter()
|
|
val cx = Context.enter()
|
|
|
var ret: Any?
|
|
var ret: Any?
|