From 9579db0f25e2f615cc3bc39c76c2825edc76b333 Mon Sep 17 00:00:00 2001 From: aiselp Date: Wed, 14 Jun 2023 17:26:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8Btimer=E5=B7=A5=E4=BD=9C=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/autojs/autojs/core/looper/Timer.kt | 17 ++++++++++++----- version.properties | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt b/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt index 95dad6c9..368caa7d 100644 --- a/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt +++ b/app/src/main/java/org/autojs/autojs/core/looper/Timer.kt @@ -7,6 +7,7 @@ import org.autojs.autojs.runtime.ScriptRuntime import org.mozilla.javascript.BaseFunction import org.mozilla.javascript.Context import org.mozilla.javascript.Scriptable +import org.mozilla.javascript.Undefined import java.util.concurrent.ConcurrentHashMap import kotlin.random.Random @@ -22,6 +23,7 @@ class Timer( private val mRuntime: ScriptRuntime = runtime private val mHandler: Handler = Handler(looper) private val isUiLoop: Boolean = looper == Looper.getMainLooper() + private val context: Context? by lazy { Context.getCurrentContext() } constructor(runtime: ScriptRuntime, ) : this(runtime, Looper.myLooper()!!) @@ -36,17 +38,22 @@ class Timer( return id } - private fun callFunction(callback: Any, thiz: Any?, args :Any?) { - val myArgs = args?.let { args as Array<*> }?: emptyArray() - val map = myArgs.map { Context.javaToJS(it, callback as BaseFunction) } + private fun callFunction(callback: Any, thiz: Any?, args: Any?) { + val func = callback as BaseFunction + val map: Array = + (args as? Array<*>)?.map { Context.javaToJS(it, callback.parentScope) } + ?.toTypedArray() ?: emptyArray() try { - (callback as BaseFunction).call(Context.getCurrentContext(),callback.parentScope, - thiz as? Scriptable?, map.toTypedArray() + func.call( + context ?: Context.enter(), func.parentScope, + thiz as? Scriptable ?: Undefined.SCRIPTABLE_UNDEFINED, map ) } catch (e: Exception) { if (isUiLoop) { mRuntime.exit(e) } else throw e + }finally { + context ?: Context.exit() } } diff --git a/version.properties b/version.properties index f08a7391..afcad997 100644 --- a/version.properties +++ b/version.properties @@ -1,8 +1,8 @@ -#Wed Jun 14 13:27:56 CST 2023 -BUILD_TIME=1686720476407 +#Wed Jun 14 18:20:43 CST 2023 +BUILD_TIME=1686738043084 COMPILE_SDK_VERSION=33 JAVA_VERSION=20 MIN_SDK_VERSION=24 TARGET_SDK_VERSION=33 -VERSION_BUILD=1914 +VERSION_BUILD=1916 VERSION_NAME=6.3.1