diff --git a/app/src/main/java/io/legado/app/help/rhino/NativeBaseSource.kt b/app/src/main/java/io/legado/app/help/rhino/NativeBaseSource.kt index ea9432cd4..ed50b4d88 100644 --- a/app/src/main/java/io/legado/app/help/rhino/NativeBaseSource.kt +++ b/app/src/main/java/io/legado/app/help/rhino/NativeBaseSource.kt @@ -3,10 +3,9 @@ package io.legado.app.help.rhino import com.script.rhino.JavaObjectWrapFactory import org.mozilla.javascript.NativeJavaObject import org.mozilla.javascript.Scriptable -import org.mozilla.javascript.lc.type.TypeInfoFactory class NativeBaseSource(scope: Scriptable?, javaObject: Any, staticType: Class<*>?) : - NativeJavaObject(scope, javaObject, staticType?.let { TypeInfoFactory.GLOBAL.create(it) }) { + NativeJavaObject(scope, javaObject, staticType) { override fun has(name: String, start: Scriptable): Boolean { if (name != "setVariable" && name.length > 3 && name.startsWith("set")) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f08e995c2..32a306478 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -62,7 +62,7 @@ protobufJavalite = "4.26.1" quickChineseTransfer = "0.2.17" room = "2.8.4" splitties = "3.0.0" -rhino = "1.9.1" +rhino = "1.8.1" desugar = "2.1.5" activity = "1.13.0" diff --git a/modules/rhino/src/main/java/com/script/rhino/ReadOnlyJavaObject.kt b/modules/rhino/src/main/java/com/script/rhino/ReadOnlyJavaObject.kt index 7a8d5e43e..15477e212 100644 --- a/modules/rhino/src/main/java/com/script/rhino/ReadOnlyJavaObject.kt +++ b/modules/rhino/src/main/java/com/script/rhino/ReadOnlyJavaObject.kt @@ -2,10 +2,9 @@ package com.script.rhino import org.mozilla.javascript.NativeJavaObject import org.mozilla.javascript.Scriptable -import org.mozilla.javascript.lc.type.TypeInfoFactory class ReadOnlyJavaObject(scope: Scriptable?, javaObject: Any, staticType: Class<*>?) : - NativeJavaObject(scope, javaObject, staticType?.let { TypeInfoFactory.GLOBAL.create(it) }) { + NativeJavaObject(scope, javaObject, staticType) { override fun has(name: String, start: Scriptable): Boolean { if (name.length > 3 && name.startsWith("set")) { diff --git a/modules/rhino/src/main/java/com/script/rhino/VMBridgeReflect.kt b/modules/rhino/src/main/java/com/script/rhino/VMBridgeReflect.kt index 79febff5e..eac5e209b 100644 --- a/modules/rhino/src/main/java/com/script/rhino/VMBridgeReflect.kt +++ b/modules/rhino/src/main/java/com/script/rhino/VMBridgeReflect.kt @@ -1,31 +1,20 @@ package com.script.rhino -import org.mozilla.javascript.Context -import org.mozilla.javascript.ContextFactory +import org.mozilla.javascript.VMBridge object VMBridgeReflect { + val instance: VMBridge by lazy { + VMBridge::class.java.getDeclaredField("instance").apply { + isAccessible = true + }.get(null) as VMBridge + } + val contextLocal: ThreadLocal by lazy { @Suppress("UNCHECKED_CAST") - try { - // Rhino 1.9.1+ uses threadContextLocal directly in Context class - val field = Context::class.java.getDeclaredField("threadContextLocal") - field.isAccessible = true - field.get(null) as ThreadLocal - } catch (e: Exception) { - try { - // Fallback for some versions or custom builds - val factory = ContextFactory.getGlobal() - val field = ContextFactory::class.java.getDeclaredField("localContext") - field.isAccessible = true - field.get(factory) as ThreadLocal - } catch (e2: Exception) { - // Older versions used threadContextHelper (Object) which held a ThreadLocal - val field = Context::class.java.getDeclaredField("threadContextHelper") - field.isAccessible = true - field.get(null) as ThreadLocal - } - } + instance::class.java.getDeclaredField("contextLocal").apply { + isAccessible = true + }.get(null) as ThreadLocal } }