From 6cc229d9b92ff1dc1c3c1f771955a016b1d4ebd3 Mon Sep 17 00:00:00 2001 From: HapeLee <63206378+HapeLee@users.noreply.github.com> Date: Sun, 31 May 2026 22:03:33 +0800 Subject: [PATCH] =?UTF-8?q?@=20revert:=20=E5=9B=9E=E9=80=80rhino=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=87=B31.8.1=EF=BC=8C=E7=A7=BB=E9=99=A41.9.1?= =?UTF-8?q?=E9=80=82=E9=85=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - rhino 1.9.1 → 1.8.1 - VMBridgeReflect: 移除Context/ContextFactory fallback,恢复VMBridge反射 - ReadOnlyJavaObject/NativeBaseSource: 移除TypeInfoFactory适配,恢复Class<*>?构造 @ --- .../legado/app/help/rhino/NativeBaseSource.kt | 3 +- gradle/libs.versions.toml | 2 +- .../com/script/rhino/ReadOnlyJavaObject.kt | 3 +- .../java/com/script/rhino/VMBridgeReflect.kt | 31 ++++++------------- 4 files changed, 13 insertions(+), 26 deletions(-) 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 } }