mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -42,15 +42,11 @@ abstract class AbstractScriptEngine(val bindings: Bindings? = null) : ScriptEngi
|
||||
}
|
||||
|
||||
override fun put(key: String, value: Any?) {
|
||||
val nn = getBindings(100)
|
||||
if (nn != null) {
|
||||
nn[key] = value
|
||||
}
|
||||
getBindings(100)?.put(key, value)
|
||||
}
|
||||
|
||||
override fun get(key: String): Any? {
|
||||
val nn = getBindings(100)
|
||||
return nn?.get(key)
|
||||
return getBindings(100)?.get(key)
|
||||
}
|
||||
|
||||
override fun eval(script: String, scope: Scriptable): Any? {
|
||||
|
||||
@@ -43,12 +43,12 @@ class ScriptException : Exception {
|
||||
if (fileName == null) {
|
||||
return ret!!
|
||||
}
|
||||
var ret2 = ret + " in " + fileName
|
||||
var ret2 = "$ret in $fileName"
|
||||
if (lineNumber != -1) {
|
||||
ret2 = ret2 + " at line number " + lineNumber
|
||||
ret2 = "$ret2 at line number $lineNumber"
|
||||
}
|
||||
return if (columnNumber != -1) {
|
||||
ret2 + " at column number " + columnNumber
|
||||
"$ret2 at column number $columnNumber"
|
||||
} else ret2
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,11 @@ class SimpleBindings @JvmOverloads constructor(
|
||||
) : Bindings {
|
||||
|
||||
override fun put(key: String, value: Any?): Any? {
|
||||
checkKey(key)
|
||||
return map.put(key, value)
|
||||
}
|
||||
|
||||
override fun putAll(from: Map<out String, Any?>) {
|
||||
for ((key, value) in from) {
|
||||
checkKey(key)
|
||||
this[key] = value
|
||||
}
|
||||
map.putAll(from)
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
@@ -24,7 +20,6 @@ class SimpleBindings @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
override fun containsKey(key: String): Boolean {
|
||||
checkKey(key)
|
||||
return map.containsKey(key)
|
||||
}
|
||||
|
||||
@@ -36,7 +31,6 @@ class SimpleBindings @JvmOverloads constructor(
|
||||
get() = map.entries
|
||||
|
||||
override operator fun get(key: String): Any? {
|
||||
checkKey(key)
|
||||
return map[key]
|
||||
}
|
||||
|
||||
@@ -48,7 +42,6 @@ class SimpleBindings @JvmOverloads constructor(
|
||||
get() = map.keys
|
||||
|
||||
override fun remove(key: String): Any? {
|
||||
checkKey(key)
|
||||
return map.remove(key)
|
||||
}
|
||||
|
||||
@@ -58,13 +51,4 @@ class SimpleBindings @JvmOverloads constructor(
|
||||
override val values: MutableCollection<Any?>
|
||||
get() = map.values
|
||||
|
||||
private fun checkKey(key: Any?) {
|
||||
if (key == null) {
|
||||
throw NullPointerException("key can not be null")
|
||||
}
|
||||
if (key !is String) {
|
||||
throw ClassCastException("key should be a String")
|
||||
}
|
||||
require(key != "") { "key can not be empty" }
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ open class SimpleScriptContext : ScriptContext {
|
||||
if (engineScope.containsKey(name)) {
|
||||
return this.getAttribute(name, 100)
|
||||
}
|
||||
return if (globalScope == null || !globalScope!!.containsKey(name)) {
|
||||
return if (globalScope?.containsKey(name) != true) {
|
||||
null
|
||||
} else this.getAttribute(name, 200)
|
||||
}
|
||||
@@ -47,9 +47,7 @@ open class SimpleScriptContext : ScriptContext {
|
||||
return engineScope[name]
|
||||
}
|
||||
200 -> {
|
||||
return if (globalScope != null) {
|
||||
globalScope!![name]
|
||||
} else null
|
||||
return globalScope?.get(name)
|
||||
}
|
||||
}
|
||||
throw IllegalArgumentException("Illegal scope value.")
|
||||
@@ -58,14 +56,10 @@ open class SimpleScriptContext : ScriptContext {
|
||||
override fun removeAttribute(name: String, scope: Int): Any? {
|
||||
when (scope) {
|
||||
100 -> {
|
||||
return if (getBindings(100) != null) {
|
||||
getBindings(100)!!.remove(name)
|
||||
} else null
|
||||
return getBindings(100)?.remove(name)
|
||||
}
|
||||
200 -> {
|
||||
return if (getBindings(200) != null) {
|
||||
getBindings(200)!!.remove(name)
|
||||
} else null
|
||||
return getBindings(200)?.remove(name)
|
||||
}
|
||||
}
|
||||
throw IllegalArgumentException("Illegal scope value.")
|
||||
@@ -89,7 +83,7 @@ open class SimpleScriptContext : ScriptContext {
|
||||
if (engineScope.containsKey(name)) {
|
||||
return 100
|
||||
}
|
||||
return if (globalScope == null || !globalScope!!.containsKey(name)) {
|
||||
return if (globalScope?.containsKey(name) != true) {
|
||||
-1
|
||||
} else 200
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user