revert: 回退rhino版本至1.8.1,移除1.9.1适配代码

- rhino 1.9.1 → 1.8.1
- VMBridgeReflect: 移除Context/ContextFactory fallback,恢复VMBridge反射
- ReadOnlyJavaObject/NativeBaseSource: 移除TypeInfoFactory适配,恢复Class<*>?构造
@
This commit is contained in:
HapeLee
2026-05-31 22:03:33 +08:00
parent c63cf8921d
commit 6cc229d9b9
4 changed files with 13 additions and 26 deletions
@@ -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")) {
+1 -1
View File
@@ -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"
@@ -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")) {
@@ -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<Any> 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<Any>
} 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<Any>
} 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<Any>
}
}
instance::class.java.getDeclaredField("contextLocal").apply {
isAccessible = true
}.get(null) as ThreadLocal<Any>
}
}