优化
This commit is contained in:
+1
-1
@@ -35,5 +35,5 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(fileTree(dir: 'lib', include: ['rhino-1.7.13-2.jar']))
|
api(fileTree(dir: 'lib', include: ['rhino-1.7.14-2.jar']))
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,16 @@ import org.mozilla.javascript.ClassShutter
|
|||||||
* @author A. Sundararajan
|
* @author A. Sundararajan
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
internal class RhinoClassShutter private constructor() : ClassShutter {
|
object RhinoClassShutter : ClassShutter {
|
||||||
|
|
||||||
|
private val protectedClasses by lazy {
|
||||||
|
val protectedClasses = HashMap<Any, Any>()
|
||||||
|
protectedClasses["java.lang.Runtime"] = java.lang.Boolean.TRUE
|
||||||
|
protectedClasses["java.io.File"] = java.lang.Boolean.TRUE
|
||||||
|
protectedClasses["java.security.AccessController"] = java.lang.Boolean.TRUE
|
||||||
|
protectedClasses
|
||||||
|
}
|
||||||
|
|
||||||
override fun visibleToScripts(fullClassName: String): Boolean {
|
override fun visibleToScripts(fullClassName: String): Boolean {
|
||||||
val sm = System.getSecurityManager()
|
val sm = System.getSecurityManager()
|
||||||
if (sm != null) {
|
if (sm != null) {
|
||||||
@@ -50,22 +59,4 @@ internal class RhinoClassShutter private constructor() : ClassShutter {
|
|||||||
return protectedClasses[fullClassName] == null
|
return protectedClasses[fullClassName] == null
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val protectedClasses by lazy {
|
|
||||||
val protectedClasses = HashMap<Any, Any>()
|
|
||||||
protectedClasses["java.lang.Runtime"] = java.lang.Boolean.TRUE
|
|
||||||
protectedClasses["java.io.File"] = java.lang.Boolean.TRUE
|
|
||||||
protectedClasses["java.security.AccessController"] = java.lang.Boolean.TRUE
|
|
||||||
protectedClasses
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
val instance: ClassShutter by lazy {
|
|
||||||
val theInstance = RhinoClassShutter()
|
|
||||||
theInstance
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
package com.script.rhino
|
package com.script.rhino
|
||||||
|
|
||||||
import com.script.*
|
import com.script.*
|
||||||
import com.script.rhino.RhinoClassShutter.Companion.instance
|
|
||||||
import org.intellij.lang.annotations.Language
|
import org.intellij.lang.annotations.Language
|
||||||
import org.mozilla.javascript.*
|
import org.mozilla.javascript.*
|
||||||
import org.mozilla.javascript.Function
|
import org.mozilla.javascript.Function
|
||||||
@@ -331,11 +330,18 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
|||||||
val cx = super.makeContext()
|
val cx = super.makeContext()
|
||||||
cx.languageVersion = 200
|
cx.languageVersion = 200
|
||||||
cx.optimizationLevel = -1
|
cx.optimizationLevel = -1
|
||||||
cx.setClassShutter(instance)
|
cx.setClassShutter(RhinoClassShutter)
|
||||||
cx.wrapFactory = RhinoWrapFactory.instance
|
cx.wrapFactory = RhinoWrapFactory
|
||||||
return cx
|
return cx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hasFeature(cx: Context?, featureIndex: Int): Boolean {
|
||||||
|
if (featureIndex == Context.FEATURE_ENABLE_JAVA_MAP_ACCESS) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return super.hasFeature(cx, featureIndex)
|
||||||
|
}
|
||||||
|
|
||||||
override fun doTopCall(
|
override fun doTopCall(
|
||||||
callable: Callable,
|
callable: Callable,
|
||||||
cx: Context,
|
cx: Context,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ import java.lang.reflect.Modifier
|
|||||||
* @author A. Sundararajan
|
* @author A. Sundararajan
|
||||||
* @since 1.6
|
* @since 1.6
|
||||||
*/
|
*/
|
||||||
internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
object RhinoWrapFactory : WrapFactory() {
|
||||||
|
|
||||||
override fun wrapAsJavaObject(
|
override fun wrapAsJavaObject(
|
||||||
cx: Context,
|
cx: Context,
|
||||||
@@ -54,7 +54,7 @@ internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
|||||||
): Scriptable? {
|
): Scriptable? {
|
||||||
scope?.delete("Packages")
|
scope?.delete("Packages")
|
||||||
val sm = System.getSecurityManager()
|
val sm = System.getSecurityManager()
|
||||||
val classShutter = RhinoClassShutter.instance
|
val classShutter = RhinoClassShutter
|
||||||
return if (javaObject is ClassLoader) {
|
return if (javaObject is ClassLoader) {
|
||||||
sm?.checkPermission(RuntimePermission("getClassLoader"))
|
sm?.checkPermission(RuntimePermission("getClassLoader"))
|
||||||
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
super.wrapAsJavaObject(cx, scope, javaObject, staticType)
|
||||||
@@ -115,17 +115,4 @@ internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private var theInstance: RhinoWrapFactory? = null
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@get:Synchronized
|
|
||||||
val instance: WrapFactory?
|
|
||||||
get() {
|
|
||||||
if (theInstance == null) {
|
|
||||||
theInstance = RhinoWrapFactory()
|
|
||||||
}
|
|
||||||
return theInstance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user