From 1f74343a5aa25963adb82bfb24c103328a62b880 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 6 Apr 2023 22:40:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/script/rhino/ExternalScriptable.kt | 15 ++------------- .../main/java/com/script/rhino/RhinoTopLevel.kt | 8 ++++---- .../java/com/script/rhino/ExternalScriptable.kt | 15 ++------------- .../main/java/com/script/rhino/RhinoTopLevel.kt | 10 +++++----- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/modules/rhino1.7.3/src/main/java/com/script/rhino/ExternalScriptable.kt b/modules/rhino1.7.3/src/main/java/com/script/rhino/ExternalScriptable.kt index e00f49ff1..8bc693c6d 100644 --- a/modules/rhino1.7.3/src/main/java/com/script/rhino/ExternalScriptable.kt +++ b/modules/rhino1.7.3/src/main/java/com/script/rhino/ExternalScriptable.kt @@ -37,23 +37,12 @@ import org.mozilla.javascript.Function * @since 1.6 */ internal class ExternalScriptable @JvmOverloads constructor( - context: ScriptContext?, - indexedProps: MutableMap = HashMap() + val context: ScriptContext, + private val indexedProps: MutableMap = HashMap() ) : Scriptable { - val context: ScriptContext - private val indexedProps: MutableMap private var prototype: Scriptable? = null private var parent: Scriptable? = null - init { - if (context == null) { - throw NullPointerException("context is null") - } else { - this.context = context - this.indexedProps = indexedProps - } - } - private fun isEmpty(name: String): Boolean { return name == "" } diff --git a/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoTopLevel.kt b/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoTopLevel.kt index 5dfd89ea1..5d0a2f9a7 100644 --- a/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoTopLevel.kt +++ b/modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoTopLevel.kt @@ -39,7 +39,7 @@ import java.security.AccessControlContext * @author A. Sundararajan * @since 1.6 */ -@Suppress("UNUSED_PARAMETER") +@Suppress("UNUSED_PARAMETER", "unused") class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : ImporterTopLevel(cx, System.getSecurityManager() != null) { @@ -57,7 +57,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : @JvmStatic fun bindings( - cx: Context?, + cx: Context, thisObj: Scriptable?, args: Array, funObj: Function? @@ -77,7 +77,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : } @JvmStatic - fun scope(cx: Context?, thisObj: Scriptable?, args: Array, funObj: Function?): Any { + fun scope(cx: Context, thisObj: Scriptable?, args: Array, funObj: Function?): Any { if (args.size == 1) { var arg = args[0] if (arg is Wrapper) { @@ -96,7 +96,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : } @JvmStatic - fun sync(cx: Context?, thisObj: Scriptable?, args: Array, funObj: Function?): Any { + fun sync(cx: Context, thisObj: Scriptable?, args: Array, funObj: Function?): Any { return if (args.size == 1 && args[0] is Function) { Synchronizer(args[0] as Function?) } else { diff --git a/modules/rhino1.7.4/src/main/java/com/script/rhino/ExternalScriptable.kt b/modules/rhino1.7.4/src/main/java/com/script/rhino/ExternalScriptable.kt index f97a159cf..9be2af70f 100644 --- a/modules/rhino1.7.4/src/main/java/com/script/rhino/ExternalScriptable.kt +++ b/modules/rhino1.7.4/src/main/java/com/script/rhino/ExternalScriptable.kt @@ -37,23 +37,12 @@ import org.mozilla.javascript.Function * @since 1.6 */ internal class ExternalScriptable @JvmOverloads constructor( - context: ScriptContext?, - indexedProps: MutableMap = HashMap() + val context: ScriptContext, + private val indexedProps: MutableMap = HashMap() ) : Scriptable { - val context: ScriptContext - private val indexedProps: MutableMap private var prototype: Scriptable? = null private var parent: Scriptable? = null - init { - if (context == null) { - throw NullPointerException("context is null") - } else { - this.context = context - this.indexedProps = indexedProps - } - } - override fun getClassName(): String { return "Global" } diff --git a/modules/rhino1.7.4/src/main/java/com/script/rhino/RhinoTopLevel.kt b/modules/rhino1.7.4/src/main/java/com/script/rhino/RhinoTopLevel.kt index 5dfd89ea1..cc02e9053 100644 --- a/modules/rhino1.7.4/src/main/java/com/script/rhino/RhinoTopLevel.kt +++ b/modules/rhino1.7.4/src/main/java/com/script/rhino/RhinoTopLevel.kt @@ -39,7 +39,7 @@ import java.security.AccessControlContext * @author A. Sundararajan * @since 1.6 */ -@Suppress("UNUSED_PARAMETER") +@Suppress("UNUSED_PARAMETER", "unused") class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : ImporterTopLevel(cx, System.getSecurityManager() != null) { @@ -57,7 +57,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : @JvmStatic fun bindings( - cx: Context?, + cx: Context, thisObj: Scriptable?, args: Array, funObj: Function? @@ -77,7 +77,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : } @JvmStatic - fun scope(cx: Context?, thisObj: Scriptable?, args: Array, funObj: Function?): Any { + fun scope(cx: Context, thisObj: Scriptable?, args: Array, funObj: Function?): Any { if (args.size == 1) { var arg = args[0] if (arg is Wrapper) { @@ -86,7 +86,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : if (arg is Bindings) { val ctx: ScriptContext = SimpleScriptContext() ctx.setBindings(arg as Bindings?, 100) - val res: Scriptable = ExternalScriptable(ctx) + val res: Scriptable = cx.initSafeStandardObjects() res.prototype = getObjectPrototype(thisObj) res.parentScope = getTopLevelScope(thisObj) return res @@ -96,7 +96,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) : } @JvmStatic - fun sync(cx: Context?, thisObj: Scriptable?, args: Array, funObj: Function?): Any { + fun sync(cx: Context, thisObj: Scriptable?, args: Array, funObj: Function?): Any { return if (args.size == 1 && args[0] is Function) { Synchronizer(args[0] as Function?) } else {