优化
This commit is contained in:
@@ -40,6 +40,7 @@ import java.security.PrivilegedExceptionAction
|
|||||||
* @author Mike Grogan
|
* @author Mike Grogan
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
open class InterfaceImplementor(private val engine: Invocable) {
|
open class InterfaceImplementor(private val engine: Invocable) {
|
||||||
@Throws(ScriptException::class)
|
@Throws(ScriptException::class)
|
||||||
fun <T> getInterface(thiz: Any?, iface: Class<T>?): T? {
|
fun <T> getInterface(thiz: Any?, iface: Class<T>?): T? {
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ import org.mozilla.javascript.Function
|
|||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
@Suppress("unused", "UNUSED_PARAMETER")
|
@Suppress("unused", "UNUSED_PARAMETER")
|
||||||
class JSAdapter private constructor(val adaptee: Scriptable) : Scriptable, Function {
|
class JSAdapter private constructor(var adaptee: Scriptable) : Scriptable, Function {
|
||||||
private var prototype: Scriptable? = null
|
private var prototype: Scriptable? = null
|
||||||
private var parent: Scriptable? = null
|
private var parent: Scriptable? = null
|
||||||
private var isPrototype = false
|
private var isPrototype = false
|
||||||
@@ -249,7 +249,7 @@ class JSAdapter private constructor(val adaptee: Scriptable) : Scriptable, Funct
|
|||||||
val tmp: Scriptable?
|
val tmp: Scriptable?
|
||||||
return if (isPrototype) {
|
return if (isPrototype) {
|
||||||
tmp = ScriptableObject.getTopLevelScope(scope)
|
tmp = ScriptableObject.getTopLevelScope(scope)
|
||||||
if (args.size > 0) {
|
if (args.isNotEmpty()) {
|
||||||
JSAdapter(Context.toObject(args[0], tmp))
|
JSAdapter(Context.toObject(args[0], tmp))
|
||||||
} else {
|
} else {
|
||||||
throw Context.reportRuntimeError("JSAdapter requires adaptee")
|
throw Context.reportRuntimeError("JSAdapter requires adaptee")
|
||||||
@@ -270,7 +270,7 @@ class JSAdapter private constructor(val adaptee: Scriptable) : Scriptable, Funct
|
|||||||
|
|
||||||
private fun getAdapteeFunction(name: String): Function? {
|
private fun getAdapteeFunction(name: String): Function? {
|
||||||
val o = ScriptableObject.getProperty(adaptee, name)
|
val o = ScriptableObject.getProperty(adaptee, name)
|
||||||
return if (o is Function) o else null
|
return o as? Function
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun call(func: Function, args: Array<Any?>): Any {
|
private fun call(func: Function, args: Array<Any?>): Any {
|
||||||
@@ -279,8 +279,8 @@ class JSAdapter private constructor(val adaptee: Scriptable) : Scriptable, Funct
|
|||||||
val scope = func.parentScope
|
val scope = func.parentScope
|
||||||
return try {
|
return try {
|
||||||
func.call(cx, scope, thisObj, args)
|
func.call(cx, scope, thisObj, args)
|
||||||
} catch (var7: RhinoException) {
|
} catch (re: RhinoException) {
|
||||||
throw Context.reportRuntimeError(var7.message)
|
throw Context.reportRuntimeError(re.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user