优化
This commit is contained in:
@@ -193,21 +193,39 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
} else {
|
} else {
|
||||||
methodName = "valueOf"
|
methodName = "valueOf"
|
||||||
args = arrayOfNulls(1)
|
args = arrayOfNulls(1)
|
||||||
val hint: String = if (typeHint == null) {
|
val hint: String = when {
|
||||||
"undefined"
|
typeHint == null -> {
|
||||||
} else if (typeHint == ScriptRuntime.StringClass) {
|
"undefined"
|
||||||
"string"
|
}
|
||||||
} else if (typeHint == ScriptRuntime.ScriptableClass) {
|
typeHint == ScriptRuntime.StringClass -> {
|
||||||
"object"
|
"string"
|
||||||
} else if (typeHint == ScriptRuntime.FunctionClass) {
|
}
|
||||||
"function"
|
typeHint == ScriptRuntime.ScriptableClass -> {
|
||||||
} else if (typeHint != ScriptRuntime.BooleanClass && typeHint != java.lang.Boolean.TYPE) {
|
"object"
|
||||||
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")
|
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
|
args[0] = hint
|
||||||
}
|
}
|
||||||
@@ -255,15 +273,15 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
get() {
|
get() {
|
||||||
val list = ArrayList<String>()
|
val list = ArrayList<String>()
|
||||||
synchronized(context) {
|
synchronized(context) {
|
||||||
val var3: Iterator<*> = context.scopes.iterator()
|
val iterator: Iterator<*> = context.scopes.iterator()
|
||||||
while (var3.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
val scope = var3.next() as Int
|
val scope = iterator.next() as Int
|
||||||
val bindings = context.getBindings(scope)
|
val bindings = context.getBindings(scope)
|
||||||
if (bindings != null) {
|
if (bindings != null) {
|
||||||
list.ensureCapacity(bindings.size)
|
list.ensureCapacity(bindings.size)
|
||||||
val var6: Iterator<*> = bindings.keys.iterator()
|
val iterator1: Iterator<*> = bindings.keys.iterator()
|
||||||
while (var6.hasNext()) {
|
while (iterator1.hasNext()) {
|
||||||
val key = var6.next() as String
|
val key = iterator1.next() as String
|
||||||
list.add(key)
|
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 {
|
override fun construct(cx: Context, scope: Scriptable, args: Array<Any>): Scriptable {
|
||||||
return if (args.size == 2) {
|
return if (args.size == 2) {
|
||||||
var clazz: Class<*>? = null
|
var clazz: Class<*>? = null
|
||||||
val obj1 = args[0]
|
val obj = args[0]
|
||||||
if (obj1 is Wrapper) {
|
if (obj is Wrapper) {
|
||||||
val o = obj1.unwrap()
|
val o = obj.unwrap()
|
||||||
if (o is Class<*> && o.isInterface) {
|
if (o is Class<*> && o.isInterface) {
|
||||||
clazz = o
|
clazz = o
|
||||||
}
|
}
|
||||||
} else if (obj1 is Class<*> && obj1.isInterface) {
|
} else if (obj is Class<*> && obj.isInterface) {
|
||||||
clazz = obj1
|
clazz = obj
|
||||||
}
|
}
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
throw Context.reportRuntimeError("JavaAdapter: first arg should be interface Class")
|
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(
|
return if (accContext != null) AccessController.doPrivileged(
|
||||||
PrivilegedAction {
|
PrivilegedAction {
|
||||||
superDoTopCall(callable, cx, scope, thisObj, args)
|
superDoTopCall(callable, cx, scope, thisObj, args)
|
||||||
} as PrivilegedAction<*>, accContext) else superDoTopCall(
|
}, accContext
|
||||||
|
) else superDoTopCall(
|
||||||
callable,
|
callable,
|
||||||
cx,
|
cx,
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
Reference in New Issue
Block a user