Kaynağa Gözat

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

- rhino 1.9.1 → 1.8.1
- VMBridgeReflect: 移除Context/ContextFactory fallback,恢复VMBridge反射
- ReadOnlyJavaObject/NativeBaseSource: 移除TypeInfoFactory适配,恢复Class<*>?构造
@

HapeLee 5 ay önce
ebeveyn
işleme
6cc229d9b9

+ 1 - 2
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 com.script.rhino.JavaObjectWrapFactory
 import org.mozilla.javascript.NativeJavaObject
 import org.mozilla.javascript.NativeJavaObject
 import org.mozilla.javascript.Scriptable
 import org.mozilla.javascript.Scriptable
-import org.mozilla.javascript.lc.type.TypeInfoFactory
 
 
 class NativeBaseSource(scope: Scriptable?, javaObject: Any, staticType: Class<*>?) :
 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 {
     override fun has(name: String, start: Scriptable): Boolean {
         if (name != "setVariable" && name.length > 3 && name.startsWith("set")) {
         if (name != "setVariable" && name.length > 3 && name.startsWith("set")) {

+ 1 - 1
gradle/libs.versions.toml

@@ -62,7 +62,7 @@ protobufJavalite = "4.26.1"
 quickChineseTransfer = "0.2.17"
 quickChineseTransfer = "0.2.17"
 room = "2.8.4"
 room = "2.8.4"
 splitties = "3.0.0"
 splitties = "3.0.0"
-rhino = "1.9.1"
+rhino = "1.8.1"
 desugar = "2.1.5"
 desugar = "2.1.5"
 
 
 activity = "1.13.0"
 activity = "1.13.0"

+ 1 - 2
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.NativeJavaObject
 import org.mozilla.javascript.Scriptable
 import org.mozilla.javascript.Scriptable
-import org.mozilla.javascript.lc.type.TypeInfoFactory
 
 
 class ReadOnlyJavaObject(scope: Scriptable?, javaObject: Any, staticType: Class<*>?) :
 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 {
     override fun has(name: String, start: Scriptable): Boolean {
         if (name.length > 3 && name.startsWith("set")) {
         if (name.length > 3 && name.startsWith("set")) {

+ 10 - 21
modules/rhino/src/main/java/com/script/rhino/VMBridgeReflect.kt

@@ -1,31 +1,20 @@
 package com.script.rhino
 package com.script.rhino
 
 
-import org.mozilla.javascript.Context
-import org.mozilla.javascript.ContextFactory
+import org.mozilla.javascript.VMBridge
 
 
 object VMBridgeReflect {
 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 {
     val contextLocal: ThreadLocal<Any> by lazy {
         @Suppress("UNCHECKED_CAST")
         @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>
     }
     }
 
 
 }
 }