6.7.0 - Alpha6 - 修复 util.class[Name]/getClass[Name] 可能返回错误结果的问题
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
"isJavaClass/isJavaPackage 等全局方法无效的问题",
|
"isJavaClass/isJavaPackage 等全局方法无效的问题",
|
||||||
"timers.keepAlive 方法 timeout 参数功能无效的问题",
|
"timers.keepAlive 方法 timeout 参数功能无效的问题",
|
||||||
"floaty.window/rawWindow 方法无法接受字符串参数的问题",
|
"floaty.window/rawWindow 方法无法接受字符串参数的问题",
|
||||||
|
"util.class[Name]/getClass[Name] 可能返回错误结果的问题",
|
||||||
"使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题",
|
"使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题",
|
||||||
"canvas 元素控件 setMaxFps 方法内部帧率计算错误",
|
"canvas 元素控件 setMaxFps 方法内部帧率计算错误",
|
||||||
"images.concat 方法纵向拼接时宽度值计算错误",
|
"images.concat 方法纵向拼接时宽度值计算错误",
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ import org.autojs.autojs.runtime.api.Threads as ApiThreads
|
|||||||
import org.autojs.autojs.runtime.api.Timers as ApiTimers
|
import org.autojs.autojs.runtime.api.Timers as ApiTimers
|
||||||
import org.autojs.autojs.runtime.api.Toaster as ApiToaster
|
import org.autojs.autojs.runtime.api.Toaster as ApiToaster
|
||||||
import org.autojs.autojs.runtime.api.UI as ApiUI
|
import org.autojs.autojs.runtime.api.UI as ApiUI
|
||||||
|
import org.autojs.autojs.runtime.api.Util as ApiUtil
|
||||||
import org.autojs.autojs.runtime.api.augment.autojs.Version as AutojsVersion
|
import org.autojs.autojs.runtime.api.augment.autojs.Version as AutojsVersion
|
||||||
import org.autojs.autojs.runtime.api.augment.global.Legacy as GlobalLegacy
|
import org.autojs.autojs.runtime.api.augment.global.Legacy as GlobalLegacy
|
||||||
import org.autojs.autojs.runtime.api.augment.notice.Channel as NoticeChannel
|
import org.autojs.autojs.runtime.api.augment.notice.Channel as NoticeChannel
|
||||||
@@ -241,6 +242,10 @@ class ScriptRuntime private constructor(builder: Builder) {
|
|||||||
@ScriptVariable
|
@ScriptVariable
|
||||||
val ui: ApiUI
|
val ui: ApiUI
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
@ScriptVariable
|
||||||
|
val util: ApiUtil
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@ScriptVariable
|
@ScriptVariable
|
||||||
val dialogs = ApiDialogs(this)
|
val dialogs = ApiDialogs(this)
|
||||||
@@ -453,6 +458,7 @@ class ScriptRuntime private constructor(builder: Builder) {
|
|||||||
floaty = ApiFloaty(uiHandler, this)
|
floaty = ApiFloaty(uiHandler, this)
|
||||||
|
|
||||||
ui = ApiUI(mUiHandlerAppContext, this)
|
ui = ApiUI(mUiHandlerAppContext, this)
|
||||||
|
util = ApiUtil(mUiHandlerAppContext, this)
|
||||||
images = ApiImages(mUiHandlerAppContext, this)
|
images = ApiImages(mUiHandlerAppContext, this)
|
||||||
device = ApiDevice(mUiHandlerAppContext)
|
device = ApiDevice(mUiHandlerAppContext)
|
||||||
media = ApiMedia(mUiHandlerAppContext, this)
|
media = ApiMedia(mUiHandlerAppContext, this)
|
||||||
@@ -711,7 +717,7 @@ class ScriptRuntime private constructor(builder: Builder) {
|
|||||||
Global(this).assignWithGlobal(target, topLevelScope, GlobalClasses)
|
Global(this).assignWithGlobal(target, topLevelScope, GlobalClasses)
|
||||||
GlobalLegacy(this).assignWithGlobal(target, topLevelScope)
|
GlobalLegacy(this).assignWithGlobal(target, topLevelScope)
|
||||||
IsNullish.augmentWithGlobal(target, topLevelScope, false)
|
IsNullish.augmentWithGlobal(target, topLevelScope, false)
|
||||||
Util.augmentWithGlobal(target, topLevelScope, true).apply {
|
Util.augmentWithGlobal(target, topLevelScope, util, true).apply {
|
||||||
UtilJava.augmentWithGlobal(this, topLevelScope, false)
|
UtilJava.augmentWithGlobal(this, topLevelScope, false)
|
||||||
UtilVersion.augmentWithGlobal(this, topLevelScope, false)
|
UtilVersion.augmentWithGlobal(this, topLevelScope, false)
|
||||||
UtilVersionCodes.augmentWithGlobal(this, topLevelScope, VersionCodesInfo.obj, false)
|
UtilVersionCodes.augmentWithGlobal(this, topLevelScope, VersionCodesInfo.obj, false)
|
||||||
|
|||||||
23
app/src/main/java/org/autojs/autojs/runtime/api/Util.kt
Normal file
23
app/src/main/java/org/autojs/autojs/runtime/api/Util.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package org.autojs.autojs.runtime.api
|
||||||
|
|
||||||
|
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||||
|
import org.autojs.autojs.runtime.ScriptRuntime
|
||||||
|
|
||||||
|
class Util(private val context: android.content.Context, private val scriptRuntime: ScriptRuntime) {
|
||||||
|
|
||||||
|
fun `class`(o: Any?) = getClassInternal(o, "class")
|
||||||
|
|
||||||
|
fun getClass(o: Any?) = getClassInternal(o, "getClass")
|
||||||
|
|
||||||
|
fun className(o: Any?) = getClassNameInternal(o, "className")
|
||||||
|
|
||||||
|
fun getClassName(o: Any?) = getClassNameInternal(o, "getClassName")
|
||||||
|
|
||||||
|
private fun getClassInternal(o: Any?, methodName: String): Class<out Any> {
|
||||||
|
require(o != null) { "Argument \"o\" ${o.jsBrief()} for util.$methodName must be non-null" }
|
||||||
|
return o as? Class<*> ?: o.javaClass
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getClassNameInternal(o: Any?, methodName: String): String = getClassInternal(o, methodName).name
|
||||||
|
|
||||||
|
}
|
||||||
@@ -89,10 +89,6 @@ object Util : Augmentable() {
|
|||||||
::deprecate.name,
|
::deprecate.name,
|
||||||
::debuglog.name,
|
::debuglog.name,
|
||||||
::log.name,
|
::log.name,
|
||||||
::`class`.name,
|
|
||||||
::getClass.name,
|
|
||||||
::className.name,
|
|
||||||
::getClassName.name,
|
|
||||||
::checkStringArgument.name,
|
::checkStringArgument.name,
|
||||||
::assureStringStartsWith.name,
|
::assureStringStartsWith.name,
|
||||||
::assureStringEndsWith.name,
|
::assureStringEndsWith.name,
|
||||||
@@ -458,40 +454,6 @@ object Util : Augmentable() {
|
|||||||
AutoJs.instance.globalConsole.log("%s - %s", timestamp, formatRhino(*arguments))
|
AutoJs.instance.globalConsole.log("%s - %s", timestamp, formatRhino(*arguments))
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@RhinoSingletonFunctionInterface
|
|
||||||
fun `class`(args: Array<out Any?>): Scriptable = ensureArgumentsOnlyOne(args) { o ->
|
|
||||||
require(o != null) { "Argument \"o\" ${o.jsBrief()} for util.class must be non-null" }
|
|
||||||
getClassInternal(o)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@RhinoSingletonFunctionInterface
|
|
||||||
fun getClass(args: Array<out Any?>): Scriptable = ensureArgumentsOnlyOne(args) { o ->
|
|
||||||
require(o != null) { "Argument \"o\" ${o.jsBrief()} for util.getClass must be non-null" }
|
|
||||||
getClassInternal(o)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@RhinoSingletonFunctionInterface
|
|
||||||
fun className(args: Array<out Any?>): String = ensureArgumentsOnlyOne(args) {
|
|
||||||
when (it) {
|
|
||||||
null -> throw WrappedIllegalArgumentException("Argument \"o\" ${it.jsBrief()} for util.className must be non-null")
|
|
||||||
is Class<*> -> it.name
|
|
||||||
else -> it.javaClass.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@RhinoSingletonFunctionInterface
|
|
||||||
fun getClassName(args: Array<out Any?>): String = ensureArgumentsOnlyOne(args) {
|
|
||||||
when (it) {
|
|
||||||
null -> throw WrappedIllegalArgumentException("Argument \"o\" ${it.jsBrief()} for util.getClassName must be non-null")
|
|
||||||
is Class<*> -> it.name
|
|
||||||
else -> it.javaClass.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Deprecated("Deprecated in Java", ReplaceWith("checkStringArgument(args)"))
|
@Deprecated("Deprecated in Java", ReplaceWith("checkStringArgument(args)"))
|
||||||
@RhinoSingletonFunctionInterface
|
@RhinoSingletonFunctionInterface
|
||||||
@@ -768,11 +730,6 @@ object Util : Augmentable() {
|
|||||||
coerceNumber(DisplayUtils.pxToSp(coerceFloatNumber(it)))
|
coerceNumber(DisplayUtils.pxToSp(coerceFloatNumber(it)))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getClassInternal(o: Any): Scriptable = when (o) {
|
|
||||||
is Class<*> -> o
|
|
||||||
else -> o.javaClass
|
|
||||||
}.let { cls -> withRhinoContext { cx -> cx.wrapFactory.wrapJavaClass(cx, ImporterTopLevel(cx), cls) } }
|
|
||||||
|
|
||||||
internal class RegularFunction(private val func: BaseFunction) : BaseFunction() {
|
internal class RegularFunction(private val func: BaseFunction) : BaseFunction() {
|
||||||
|
|
||||||
override fun call(cx: Context, scope: Scriptable, thisObj: Scriptable?, args: Array<out Any?>): Any {
|
override fun call(cx: Context, scope: Scriptable, thisObj: Scriptable?, args: Array<out Any?>): Any {
|
||||||
|
|||||||
Reference in New Issue
Block a user