优化
This commit is contained in:
@@ -38,10 +38,10 @@ import org.mozilla.javascript.Function
|
|||||||
*/
|
*/
|
||||||
internal class ExternalScriptable @JvmOverloads constructor(
|
internal class ExternalScriptable @JvmOverloads constructor(
|
||||||
context: ScriptContext?,
|
context: ScriptContext?,
|
||||||
indexedProps: MutableMap<Any, Any> = HashMap()
|
indexedProps: MutableMap<Any, Any?> = HashMap()
|
||||||
) : Scriptable {
|
) : Scriptable {
|
||||||
val context: ScriptContext
|
val context: ScriptContext
|
||||||
private val indexedProps: MutableMap<Any, Any>
|
private val indexedProps: MutableMap<Any, Any?>
|
||||||
private var prototype: Scriptable? = null
|
private var prototype: Scriptable? = null
|
||||||
private var parent: Scriptable? = null
|
private var parent: Scriptable? = null
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun get(name: String, start: Scriptable): Any {
|
override fun get(name: String, start: Scriptable): Any? {
|
||||||
return if (this.isEmpty(name)) {
|
return if (this.isEmpty(name)) {
|
||||||
indexedProps.getOrElse(name) { Scriptable.NOT_FOUND }
|
indexedProps.getOrElse(name) { Scriptable.NOT_FOUND }
|
||||||
} else {
|
} else {
|
||||||
@@ -80,7 +80,7 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
override fun get(index: Int, start: Scriptable): Any {
|
override fun get(index: Int, start: Scriptable): Any? {
|
||||||
return indexedProps.getOrElse(index) { Scriptable.NOT_FOUND }
|
return indexedProps.getOrElse(index) { Scriptable.NOT_FOUND }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
return indexedProps.containsKey(index)
|
return indexedProps.containsKey(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun put(name: String, start: Scriptable, value: Any) {
|
override fun put(name: String, start: Scriptable, value: Any?) {
|
||||||
if (start === this) {
|
if (start === this) {
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
if (this.isEmpty(name)) {
|
if (this.isEmpty(name)) {
|
||||||
@@ -272,7 +272,7 @@ internal class ExternalScriptable @JvmOverloads constructor(
|
|||||||
return list.toTypedArray()
|
return list.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun jsToJava(jsObj: Any): Any {
|
private fun jsToJava(jsObj: Any?): Any? {
|
||||||
return if (jsObj is Wrapper) {
|
return if (jsObj is Wrapper) {
|
||||||
if (jsObj is NativeJavaClass) {
|
if (jsObj is NativeJavaClass) {
|
||||||
jsObj
|
jsObj
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import java.security.*
|
|||||||
class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||||
var accessContext: AccessControlContext? = null
|
var accessContext: AccessControlContext? = null
|
||||||
private var topLevel: RhinoTopLevel? = null
|
private var topLevel: RhinoTopLevel? = null
|
||||||
private val indexedProps: MutableMap<Any, Any>
|
private val indexedProps: MutableMap<Any, Any?>
|
||||||
private val implementor: InterfaceImplementor
|
private val implementor: InterfaceImplementor
|
||||||
|
|
||||||
@Throws(ScriptException::class)
|
@Throws(ScriptException::class)
|
||||||
@@ -58,7 +58,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
val scope = getRuntimeScope(ctxt)
|
val scope = getRuntimeScope(ctxt)
|
||||||
var filename = this["javax.script.filename"] as? String
|
var filename = this["javax.script.filename"] as? String
|
||||||
filename = filename ?: "<Unknown source>"
|
filename = filename ?: "<Unknown source>"
|
||||||
ret = cx.evaluateReader(scope, reader, filename, 1, null as Any?)
|
ret = cx.evaluateReader(scope, reader, filename, 1, null)
|
||||||
} catch (re: RhinoException) {
|
} catch (re: RhinoException) {
|
||||||
val line = if (re.lineNumber() == 0) -1 else re.lineNumber()
|
val line = if (re.lineNumber() == 0) -1 else re.lineNumber()
|
||||||
val msg: String = if (re is JavaScriptException) {
|
val msg: String = if (re is JavaScriptException) {
|
||||||
@@ -92,7 +92,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
|
|
||||||
@Throws(ScriptException::class, NoSuchMethodException::class)
|
@Throws(ScriptException::class, NoSuchMethodException::class)
|
||||||
override fun invokeFunction(name: String, vararg args: Any): Any? {
|
override fun invokeFunction(name: String, vararg args: Any): Any? {
|
||||||
return this.invoke(null as Any?, name, *args)
|
return this.invoke(null, name, *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(ScriptException::class, NoSuchMethodException::class)
|
@Throws(ScriptException::class, NoSuchMethodException::class)
|
||||||
@@ -140,7 +140,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
|
|
||||||
override fun <T> getInterface(clasz: Class<T>): T? {
|
override fun <T> getInterface(clasz: Class<T>): T? {
|
||||||
return try {
|
return try {
|
||||||
implementor.getInterface(null as Any?, clasz)
|
implementor.getInterface(null, clasz)
|
||||||
} catch (var3: ScriptException) {
|
} catch (var3: ScriptException) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -191,7 +191,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
js,
|
js,
|
||||||
"print",
|
"print",
|
||||||
1,
|
1,
|
||||||
null as Any?
|
null
|
||||||
)
|
)
|
||||||
} finally {
|
} finally {
|
||||||
Context.exit()
|
Context.exit()
|
||||||
@@ -214,7 +214,7 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
fileName = "<Unknown Source>"
|
fileName = "<Unknown Source>"
|
||||||
}
|
}
|
||||||
val scr = cx.compileReader(script, fileName, 1, null as Any?)
|
val scr = cx.compileReader(script, fileName, 1, null)
|
||||||
ret = RhinoCompiledScript(this, scr)
|
ret = RhinoCompiledScript(this, scr)
|
||||||
} catch (var9: Exception) {
|
} catch (var9: Exception) {
|
||||||
throw ScriptException(var9)
|
throw ScriptException(var9)
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
|||||||
scope: Scriptable?,
|
scope: Scriptable?,
|
||||||
obj: Any?,
|
obj: Any?,
|
||||||
type: Class<*>?
|
type: Class<*>?
|
||||||
) : NativeJavaObject(scope, null as Any?, type) {
|
) : NativeJavaObject(scope, null, type) {
|
||||||
init {
|
init {
|
||||||
javaObject = obj
|
javaObject = obj
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user