mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
e3aa72b315
commit
9d8cc72bbd
|
@ -1,25 +0,0 @@
|
|||
package com.script.rhino
|
||||
|
||||
import kotlinx.coroutines.ThreadContextElement
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class ContextElement : ThreadContextElement<Any?> {
|
||||
|
||||
companion object Key : CoroutineContext.Key<ContextElement>
|
||||
|
||||
override val key: CoroutineContext.Key<ContextElement>
|
||||
get() = Key
|
||||
|
||||
private val contextHelper: Any? = VMBridgeReflect.contextLocal.get()
|
||||
|
||||
override fun updateThreadContext(context: CoroutineContext): Any? {
|
||||
val oldState = VMBridgeReflect.contextLocal.get()
|
||||
VMBridgeReflect.contextLocal.set(contextHelper)
|
||||
return oldState
|
||||
}
|
||||
|
||||
override fun restoreThreadContext(context: CoroutineContext, oldState: Any?) {
|
||||
VMBridgeReflect.contextLocal.set(oldState)
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ import com.script.CompiledScript
|
|||
import com.script.ScriptContext
|
||||
import com.script.ScriptEngine
|
||||
import com.script.ScriptException
|
||||
import kotlinx.coroutines.asContextElement
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mozilla.javascript.*
|
||||
import java.io.IOException
|
||||
|
@ -98,7 +99,7 @@ internal class RhinoCompiledScript(
|
|||
override suspend fun evalSuspend(scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
var ret: Any?
|
||||
withContext(ContextElement()) {
|
||||
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
||||
try {
|
||||
try {
|
||||
ret = cx.executeScriptWithContinuations(script, scope)
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package com.script.rhino
|
||||
|
||||
import com.script.*
|
||||
import kotlinx.coroutines.asContextElement
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mozilla.javascript.*
|
||||
import org.mozilla.javascript.Function
|
||||
|
@ -87,7 +88,7 @@ object RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||
override suspend fun evalSuspend(reader: Reader, scope: Scriptable): Any? {
|
||||
val cx = Context.enter()
|
||||
var ret: Any?
|
||||
withContext(ContextElement()) {
|
||||
withContext(VMBridgeReflect.contextLocal.asContextElement()) {
|
||||
try {
|
||||
var filename = this@RhinoScriptEngine["javax.script.filename"] as? String
|
||||
filename = filename ?: "<Unknown source>"
|
||||
|
|
Loading…
Reference in New Issue
Block a user