kunfei 3 years ago
parent
commit
c54f7cb3de

+ 2 - 13
modules/rhino1.7.3/src/main/java/com/script/rhino/ExternalScriptable.kt

@@ -37,23 +37,12 @@ import org.mozilla.javascript.Function
  * @since 1.6
  * @since 1.6
  */
  */
 internal class ExternalScriptable @JvmOverloads constructor(
 internal class ExternalScriptable @JvmOverloads constructor(
-    context: ScriptContext?,
-    indexedProps: MutableMap<Any, Any?> = HashMap()
+    val context: ScriptContext,
+    private val indexedProps: MutableMap<Any, Any?> = HashMap()
 ) : Scriptable {
 ) : Scriptable {
-    val context: ScriptContext
-    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
 
 
-    init {
-        if (context == null) {
-            throw NullPointerException("context is null")
-        } else {
-            this.context = context
-            this.indexedProps = indexedProps
-        }
-    }
-
     private fun isEmpty(name: String): Boolean {
     private fun isEmpty(name: String): Boolean {
         return name == ""
         return name == ""
     }
     }

+ 4 - 4
modules/rhino1.7.3/src/main/java/com/script/rhino/RhinoTopLevel.kt

@@ -39,7 +39,7 @@ import java.security.AccessControlContext
  * @author A. Sundararajan
  * @author A. Sundararajan
  * @since 1.6
  * @since 1.6
  */
  */
-@Suppress("UNUSED_PARAMETER")
+@Suppress("UNUSED_PARAMETER", "unused")
 class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
 class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
     ImporterTopLevel(cx, System.getSecurityManager() != null) {
     ImporterTopLevel(cx, System.getSecurityManager() != null) {
 
 
@@ -57,7 +57,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
 
 
         @JvmStatic
         @JvmStatic
         fun bindings(
         fun bindings(
-            cx: Context?,
+            cx: Context,
             thisObj: Scriptable?,
             thisObj: Scriptable?,
             args: Array<Any?>,
             args: Array<Any?>,
             funObj: Function?
             funObj: Function?
@@ -77,7 +77,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
         }
         }
 
 
         @JvmStatic
         @JvmStatic
-        fun scope(cx: Context?, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
+        fun scope(cx: Context, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
             if (args.size == 1) {
             if (args.size == 1) {
                 var arg = args[0]
                 var arg = args[0]
                 if (arg is Wrapper) {
                 if (arg is Wrapper) {
@@ -96,7 +96,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
         }
         }
 
 
         @JvmStatic
         @JvmStatic
-        fun sync(cx: Context?, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
+        fun sync(cx: Context, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
             return if (args.size == 1 && args[0] is Function) {
             return if (args.size == 1 && args[0] is Function) {
                 Synchronizer(args[0] as Function?)
                 Synchronizer(args[0] as Function?)
             } else {
             } else {

+ 2 - 13
modules/rhino1.7.4/src/main/java/com/script/rhino/ExternalScriptable.kt

@@ -37,23 +37,12 @@ import org.mozilla.javascript.Function
  * @since 1.6
  * @since 1.6
  */
  */
 internal class ExternalScriptable @JvmOverloads constructor(
 internal class ExternalScriptable @JvmOverloads constructor(
-    context: ScriptContext?,
-    indexedProps: MutableMap<Any, Any?> = HashMap()
+    val context: ScriptContext,
+    private val indexedProps: MutableMap<Any, Any?> = HashMap()
 ) : Scriptable {
 ) : Scriptable {
-    val context: ScriptContext
-    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
 
 
-    init {
-        if (context == null) {
-            throw NullPointerException("context is null")
-        } else {
-            this.context = context
-            this.indexedProps = indexedProps
-        }
-    }
-
     override fun getClassName(): String {
     override fun getClassName(): String {
         return "Global"
         return "Global"
     }
     }

+ 5 - 5
modules/rhino1.7.4/src/main/java/com/script/rhino/RhinoTopLevel.kt

@@ -39,7 +39,7 @@ import java.security.AccessControlContext
  * @author A. Sundararajan
  * @author A. Sundararajan
  * @since 1.6
  * @since 1.6
  */
  */
-@Suppress("UNUSED_PARAMETER")
+@Suppress("UNUSED_PARAMETER", "unused")
 class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
 class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
     ImporterTopLevel(cx, System.getSecurityManager() != null) {
     ImporterTopLevel(cx, System.getSecurityManager() != null) {
 
 
@@ -57,7 +57,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
 
 
         @JvmStatic
         @JvmStatic
         fun bindings(
         fun bindings(
-            cx: Context?,
+            cx: Context,
             thisObj: Scriptable?,
             thisObj: Scriptable?,
             args: Array<Any?>,
             args: Array<Any?>,
             funObj: Function?
             funObj: Function?
@@ -77,7 +77,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
         }
         }
 
 
         @JvmStatic
         @JvmStatic
-        fun scope(cx: Context?, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
+        fun scope(cx: Context, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
             if (args.size == 1) {
             if (args.size == 1) {
                 var arg = args[0]
                 var arg = args[0]
                 if (arg is Wrapper) {
                 if (arg is Wrapper) {
@@ -86,7 +86,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
                 if (arg is Bindings) {
                 if (arg is Bindings) {
                     val ctx: ScriptContext = SimpleScriptContext()
                     val ctx: ScriptContext = SimpleScriptContext()
                     ctx.setBindings(arg as Bindings?, 100)
                     ctx.setBindings(arg as Bindings?, 100)
-                    val res: Scriptable = ExternalScriptable(ctx)
+                    val res: Scriptable = cx.initSafeStandardObjects()
                     res.prototype = getObjectPrototype(thisObj)
                     res.prototype = getObjectPrototype(thisObj)
                     res.parentScope = getTopLevelScope(thisObj)
                     res.parentScope = getTopLevelScope(thisObj)
                     return res
                     return res
@@ -96,7 +96,7 @@ class RhinoTopLevel(cx: Context, val scriptEngine: RhinoScriptEngine) :
         }
         }
 
 
         @JvmStatic
         @JvmStatic
-        fun sync(cx: Context?, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
+        fun sync(cx: Context, thisObj: Scriptable?, args: Array<Any?>, funObj: Function?): Any {
             return if (args.size == 1 && args[0] is Function) {
             return if (args.size == 1 && args[0] is Function) {
                 Synchronizer(args[0] as Function?)
                 Synchronizer(args[0] as Function?)
             } else {
             } else {