6.6.2 - Alpha2 - shizuku/shell 等方法无法接受字符串参数的问题 (issue #310)

This commit is contained in:
SuperMonster003
2025-02-27 21:01:21 +08:00
parent b6368b403d
commit c1f2cda1ff
6 changed files with 52 additions and 42 deletions

View File

@@ -7,6 +7,7 @@
"dx 库在 Android 7.x 无法正常使用的问题 _[`issue #293`](http://issues.autojs6.com/293)_", "dx 库在 Android 7.x 无法正常使用的问题 _[`issue #293`](http://issues.autojs6.com/293)_",
"ScriptRuntime 使用 require 引用内置模块时可能出现的同步状态异常 (试修) _[`issue #298`](http://issues.autojs6.com/298)_", "ScriptRuntime 使用 require 引用内置模块时可能出现的同步状态异常 (试修) _[`issue #298`](http://issues.autojs6.com/298)_",
"notice 模块缺失 getBuilder 等扩展方法的问题 _[`issue #301`](http://issues.autojs6.com/301)_", "notice 模块缺失 getBuilder 等扩展方法的问题 _[`issue #301`](http://issues.autojs6.com/301)_",
"shizuku/shell 等方法无法接受字符串参数的问题 _[`issue #310`](http://issues.autojs6.com/310)_",
"floaty.window/floaty.rawWindow 无法在子线程执行的问题", "floaty.window/floaty.rawWindow 无法在子线程执行的问题",
"ui.inflate 返回值丢失 attr/on/click 等原型方法的问题", "ui.inflate 返回值丢失 attr/on/click 等原型方法的问题",
"代码编辑器跳转到行尾时可能跳转到下一行起始位置的问题" "代码编辑器跳转到行尾时可能跳转到下一行起始位置的问题"

View File

@@ -22,7 +22,7 @@ class RawWindow(private val supplier: BaseResizableFloatyWindow.ViewSupplier) :
private val mInflateException = VolatileDispose<RuntimeException>() private val mInflateException = VolatileDispose<RuntimeException>()
lateinit var contentView: View var contentView: View? = null
override fun onCreate(floatyService: FloatyService, windowManager: WindowManager) { override fun onCreate(floatyService: FloatyService, windowManager: WindowManager) {
try { try {

View File

@@ -135,7 +135,9 @@ class Floaty(private val uiHandler: UiHandler, private val scriptRuntime: Script
} }
fun findView(id: String?): View? { fun findView(id: String?): View? {
return mWindow?.let { JsViewHelper.findViewByStringId(it.contentView, id) } val win = mWindow ?: return null
val contentView = win.contentView ?: return null
return JsViewHelper.findViewByStringId(contentView, id)
} }
val x: Int val x: Int

View File

@@ -622,14 +622,15 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
private fun bindValueForApplyingAttribute(scriptRuntime: ScriptRuntime, value: String): String { private fun bindValueForApplyingAttribute(scriptRuntime: ScriptRuntime, value: String): String {
val ctx = scriptRuntime.ui.bindingContext ?: return value val ctx = scriptRuntime.ui.bindingContext ?: return value
val niceCtx = ctx as? Scriptable
?: Context.javaToJS(ctx, scriptRuntime.topLevelScope) as? Scriptable
?: scriptRuntime.topLevelScope
var tmp = value var tmp = value
var i = -1 var i = -1
while (tmp.indexOf("{{", i + 1).also { i = it } >= 0) { while (tmp.indexOf("{{", i + 1).also { i = it } >= 0) {
val j = tmp.indexOf("}}", i + 1) val j = tmp.indexOf("}}", i + 1)
if (j < 0) { if (j < 0) return tmp
return tmp val evaluated = evalInContext(tmp.slice(i + 2 until j), niceCtx)
}
val evaluated = evalInContext(scriptRuntime, tmp.slice(i + 2 until j), ctx)
tmp = tmp.slice(0 until i) + attrValueConvert(evaluated) + tmp.slice(j + 2 until tmp.length) tmp = tmp.slice(0 until i) + attrValueConvert(evaluated) + tmp.slice(j + 2 until tmp.length)
} }
return tmp return tmp
@@ -647,38 +648,39 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
else -> xml.toString() else -> xml.toString()
} }
private fun evalInContext(scriptRuntime: ScriptRuntime, expression: String, ctx: Any): Any { /**
val scope = scriptRuntime.topLevelScope * This method is used to execute a given JavaScript expression within a specified context
return withRhinoContext { context -> * and return the result of that execution.
*
// FIXME by SuperMonster003 on Jul 21, 2024. * zh-CN: 此方法用于在指定的上下文中执行所给定的 JavaScript 表达式, 并返回执行结果.
// ! This code snippet is difficult to convert to Kotlin. *
// ! The reason is that it contains JavaScript's "with" statement, * The core logic of this method comes from the following JavaScript code.
// ! and I haven't found a way to convert it in Rhino for now. *
// ! Use the literal JavaScript code to ensure the functionality temporarily. * zh-CN: 该方法的核心逻辑来源于以下 JavaScript 代码:
// ! zh-CN: *
// ! 这段代码转换为 Kotlin 有些困难. * ```JavaScript
// ! 因为它包含了 JavaScript 的 "with" 语句, * function evalInContext(expression, ctx) {
// ! 我暂时没有找到对应的 Rhino 转换方式. * return __exitIfError__(() => {
// ! 暂时先用 JavaScript 字面量代码的方式保证其功能性. * with (ctx) {
* return (/* @IIFE */ function () {
// language=JavaScript * return eval(expression);
val script = """ * })();
// noinspection JSUnusedLocalSymbols * }
function evalInContext(expression, ctx) { * });
return __exitIfError__(() => { * }
// noinspection WithStatementJS * ```
with (ctx) { *
return (/* @IIFE */ function () { * @param expression The JavaScript expression to evaluate as a string. (zh-CN: 用于执行的表达式.)
return eval(expression); * @param ctx The context (scriptable scope) in which the expression should be evaluated. (zh-CN: 提供给参数 expression 的作用于上下文.)
})(); * @return The result of evaluating the expression. (zh-CN: 参数 expression 执行结果.)
} */
}); private fun evalInContext(expression: String, ctx: Scriptable): Any? {
val iife = object : BaseFunction() {
override fun call(cx: Context, scope: Scriptable, thisObj: Scriptable, args: Array<out Any?>): Any? {
return cx.evaluateString(scope, expression, "<eval>", 1, null)
} }
""" }
val func = context.evaluateString(scope, script, "evalInContext", 1, null) as BaseFunction return callFunction(iife, ctx, ctx, emptyArray())
func.call(context, scope, scope, arrayOf(expression, ctx))
}!!
} }
private fun initListView(scriptRuntime: ScriptRuntime, list: JsListView) { private fun initListView(scriptRuntime: ScriptRuntime, list: JsListView) {

View File

@@ -22,6 +22,7 @@ import org.mozilla.javascript.AbstractEcmaObjectOperations
import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.BaseFunction
import org.mozilla.javascript.BoundFunction import org.mozilla.javascript.BoundFunction
import org.mozilla.javascript.Callable import org.mozilla.javascript.Callable
import org.mozilla.javascript.ConsString
import org.mozilla.javascript.Context import org.mozilla.javascript.Context
import org.mozilla.javascript.ContinuationPending import org.mozilla.javascript.ContinuationPending
import org.mozilla.javascript.ImporterTopLevel import org.mozilla.javascript.ImporterTopLevel
@@ -265,8 +266,12 @@ object RhinoUtils {
}!! }!!
@JvmStatic @JvmStatic
fun unwrap(o: Any?) = when (o) { fun unwrap(o: Any?): Any? = when (o) {
is Wrapper -> o.unwrap() is String -> o
is ConsString -> o.toString()
is Number -> Context.toNumber(o)
is Boolean -> Context.toBoolean(o)
is Wrapper -> unwrap(o.unwrap())
is Unit -> UNDEFINED is Unit -> UNDEFINED
else -> o else -> o
} }

View File

@@ -1,5 +1,5 @@
#Wed Feb 05 20:51:07 CST 2025 #Thu Feb 27 19:52:32 CST 2025
BUILD_TIME=1738759867266 BUILD_TIME=1740657152247
COMPILE_SDK_VERSION=34 COMPILE_SDK_VERSION=34
JAVA_VERSION=23 JAVA_VERSION=23
JAVA_VERSION_MIN_RADICAL=0 JAVA_VERSION_MIN_RADICAL=0
@@ -17,6 +17,6 @@ RAPID_OCR_OPENCV_MOBILE_LABEL_VERSION=13
RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3 RAPID_OCR_OPENCV_MOBILE_VERSION=4.5.3
TARGET_SDK_VERSION=34 TARGET_SDK_VERSION=34
TARGET_SDK_VERSION_INRT=29 TARGET_SDK_VERSION_INRT=29
VERSION_BUILD=2982 VERSION_BUILD=2985
VERSION_NAME=6.6.2 Alpha2 VERSION_NAME=6.6.2 Alpha2
VSCODE_EXT_REQUIRED_VERSION=1.0.8 VSCODE_EXT_REQUIRED_VERSION=1.0.8