mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -193,21 +193,39 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
||||
} else {
|
||||
methodName = "valueOf"
|
||||
args = arrayOfNulls(1)
|
||||
val hint: String = if (typeHint == null) {
|
||||
"undefined"
|
||||
} else if (typeHint == ScriptRuntime.StringClass) {
|
||||
"string"
|
||||
} else if (typeHint == ScriptRuntime.ScriptableClass) {
|
||||
"object"
|
||||
} else if (typeHint == ScriptRuntime.FunctionClass) {
|
||||
"function"
|
||||
} else if (typeHint != ScriptRuntime.BooleanClass && typeHint != java.lang.Boolean.TYPE) {
|
||||
if (typeHint != ScriptRuntime.NumberClass && typeHint != ScriptRuntime.ByteClass && typeHint != java.lang.Byte.TYPE && typeHint != ScriptRuntime.ShortClass && typeHint != java.lang.Short.TYPE && typeHint != ScriptRuntime.IntegerClass && typeHint != Integer.TYPE && typeHint != ScriptRuntime.FloatClass && typeHint != java.lang.Float.TYPE && typeHint != ScriptRuntime.DoubleClass && typeHint != java.lang.Double.TYPE) {
|
||||
throw Context.reportRuntimeError("Invalid JavaScript value of type $typeHint")
|
||||
val hint: String = when {
|
||||
typeHint == null -> {
|
||||
"undefined"
|
||||
}
|
||||
typeHint == ScriptRuntime.StringClass -> {
|
||||
"string"
|
||||
}
|
||||
typeHint == ScriptRuntime.ScriptableClass -> {
|
||||
"object"
|
||||
}
|
||||
typeHint == ScriptRuntime.FunctionClass -> {
|
||||
"function"
|
||||
}
|
||||
typeHint != ScriptRuntime.BooleanClass && typeHint != java.lang.Boolean.TYPE -> {
|
||||
if (typeHint != ScriptRuntime.NumberClass
|
||||
&& typeHint != ScriptRuntime.ByteClass
|
||||
&& typeHint != java.lang.Byte.TYPE
|
||||
&& typeHint != ScriptRuntime.ShortClass
|
||||
&& typeHint != java.lang.Short.TYPE
|
||||
&& typeHint != ScriptRuntime.IntegerClass
|
||||
&& typeHint != Integer.TYPE
|
||||
&& typeHint != ScriptRuntime.FloatClass
|
||||
&& typeHint != java.lang.Float.TYPE
|
||||
&& typeHint != ScriptRuntime.DoubleClass
|
||||
&& typeHint != java.lang.Double.TYPE
|
||||
) {
|
||||
throw Context.reportRuntimeError("Invalid JavaScript value of type $typeHint")
|
||||
}
|
||||
"number"
|
||||
}
|
||||
else -> {
|
||||
"boolean"
|
||||
}
|
||||
"number"
|
||||
} else {
|
||||
"boolean"
|
||||
}
|
||||
args[0] = hint
|
||||
}
|
||||
@@ -255,15 +273,15 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
||||
get() {
|
||||
val list = ArrayList<String>()
|
||||
synchronized(context) {
|
||||
val var3: Iterator<*> = context.scopes.iterator()
|
||||
while (var3.hasNext()) {
|
||||
val scope = var3.next() as Int
|
||||
val iterator: Iterator<*> = context.scopes.iterator()
|
||||
while (iterator.hasNext()) {
|
||||
val scope = iterator.next() as Int
|
||||
val bindings = context.getBindings(scope)
|
||||
if (bindings != null) {
|
||||
list.ensureCapacity(bindings.size)
|
||||
val var6: Iterator<*> = bindings.keys.iterator()
|
||||
while (var6.hasNext()) {
|
||||
val key = var6.next() as String
|
||||
val iterator1: Iterator<*> = bindings.keys.iterator()
|
||||
while (iterator1.hasNext()) {
|
||||
val key = iterator1.next() as String
|
||||
list.add(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +66,14 @@ internal class JavaAdapter private constructor(private val engine: Invocable) :
|
||||
override fun construct(cx: Context, scope: Scriptable, args: Array<Any>): Scriptable {
|
||||
return if (args.size == 2) {
|
||||
var clazz: Class<*>? = null
|
||||
val obj1 = args[0]
|
||||
if (obj1 is Wrapper) {
|
||||
val o = obj1.unwrap()
|
||||
val obj = args[0]
|
||||
if (obj is Wrapper) {
|
||||
val o = obj.unwrap()
|
||||
if (o is Class<*> && o.isInterface) {
|
||||
clazz = o
|
||||
}
|
||||
} else if (obj1 is Class<*> && obj1.isInterface) {
|
||||
clazz = obj1
|
||||
} else if (obj is Class<*> && obj.isInterface) {
|
||||
clazz = obj
|
||||
}
|
||||
if (clazz == null) {
|
||||
throw Context.reportRuntimeError("JavaAdapter: first arg should be interface Class")
|
||||
|
||||
@@ -289,7 +289,8 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
return if (accContext != null) AccessController.doPrivileged(
|
||||
PrivilegedAction {
|
||||
superDoTopCall(callable, cx, scope, thisObj, args)
|
||||
} as PrivilegedAction<*>, accContext) else superDoTopCall(
|
||||
}, accContext
|
||||
) else superDoTopCall(
|
||||
callable,
|
||||
cx,
|
||||
scope,
|
||||
|
||||
Reference in New Issue
Block a user