mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -35,5 +35,5 @@ android {
|
||||
}
|
||||
|
||||
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
|
||||
* @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 {
|
||||
val sm = System.getSecurityManager()
|
||||
if (sm != null) {
|
||||
@@ -50,22 +59,4 @@ internal class RhinoClassShutter private constructor() : ClassShutter {
|
||||
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
|
||||
|
||||
import com.script.*
|
||||
import com.script.rhino.RhinoClassShutter.Companion.instance
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.mozilla.javascript.*
|
||||
import org.mozilla.javascript.Function
|
||||
@@ -331,11 +330,18 @@ class RhinoScriptEngine : AbstractScriptEngine(), Invocable, Compilable {
|
||||
val cx = super.makeContext()
|
||||
cx.languageVersion = 200
|
||||
cx.optimizationLevel = -1
|
||||
cx.setClassShutter(instance)
|
||||
cx.wrapFactory = RhinoWrapFactory.instance
|
||||
cx.setClassShutter(RhinoClassShutter)
|
||||
cx.wrapFactory = RhinoWrapFactory
|
||||
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(
|
||||
callable: Callable,
|
||||
cx: Context,
|
||||
|
||||
@@ -44,7 +44,7 @@ import java.lang.reflect.Modifier
|
||||
* @author A. Sundararajan
|
||||
* @since 1.6
|
||||
*/
|
||||
internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
||||
object RhinoWrapFactory : WrapFactory() {
|
||||
|
||||
override fun wrapAsJavaObject(
|
||||
cx: Context,
|
||||
@@ -54,7 +54,7 @@ internal class RhinoWrapFactory private constructor() : WrapFactory() {
|
||||
): Scriptable? {
|
||||
scope?.delete("Packages")
|
||||
val sm = System.getSecurityManager()
|
||||
val classShutter = RhinoClassShutter.instance
|
||||
val classShutter = RhinoClassShutter
|
||||
return if (javaObject is ClassLoader) {
|
||||
sm?.checkPermission(RuntimePermission("getClassLoader"))
|
||||
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