diff --git a/rhino/src/main/java/com/script/AbstractScriptEngine.kt b/rhino/src/main/java/com/script/AbstractScriptEngine.kt index aa32073c9..1a454d464 100644 --- a/rhino/src/main/java/com/script/AbstractScriptEngine.kt +++ b/rhino/src/main/java/com/script/AbstractScriptEngine.kt @@ -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? { diff --git a/rhino/src/main/java/com/script/ScriptException.kt b/rhino/src/main/java/com/script/ScriptException.kt index 4737c2222..3053826b6 100644 --- a/rhino/src/main/java/com/script/ScriptException.kt +++ b/rhino/src/main/java/com/script/ScriptException.kt @@ -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 } } \ No newline at end of file diff --git a/rhino/src/main/java/com/script/SimpleBindings.kt b/rhino/src/main/java/com/script/SimpleBindings.kt index 7fdf28853..d7f32086e 100644 --- a/rhino/src/main/java/com/script/SimpleBindings.kt +++ b/rhino/src/main/java/com/script/SimpleBindings.kt @@ -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) { - 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 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" } - } } \ No newline at end of file diff --git a/rhino/src/main/java/com/script/SimpleScriptContext.kt b/rhino/src/main/java/com/script/SimpleScriptContext.kt index 41dca6077..db8d881d4 100644 --- a/rhino/src/main/java/com/script/SimpleScriptContext.kt +++ b/rhino/src/main/java/com/script/SimpleScriptContext.kt @@ -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 }