Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autojs/src/main/assets/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ runtime.init();
global.keyboard = Object.create(runtime.keyboard);

global.process = require('process')
global.Promise = require('bluebird');
// global.Promise = require('bluebird');


//初始化全局函数
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ open class AndroidContextFactory(private val cacheDirectory: File) : ContextFact
context.languageVersion = Context.VERSION_ES6
context.locale = Locale.getDefault()
context.wrapFactory = wrapFactory
context.setTrackUnhandledPromiseRejections(true)
}

override fun doTopCall(
callable: org.mozilla.javascript.Callable,
cx: Context,
scope: Scriptable,
thisObj: Scriptable?,
args: Array<out Any?>
): Any? {
val result = super.doTopCall(callable, cx, scope, thisObj, args)
// 处理 Promise microtask 队列
cx.processMicrotasks()
return result
}

override fun onContextCreated(cx: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class ScriptBridges {
(Context.javaToJS(target, scope) as? Scriptable) ?: Undefined.SCRIPTABLE_UNDEFINED,
arg
)
// 不经过 doTopCall,需要单独处理 microtask
context.processMicrotasks()
context.getUnhandledPromiseTracker().process { reason ->
engine?.runtime?.console?.log("Unhandled Promise rejection: $reason")
}
} catch (e: Exception) {
if (Looper.getMainLooper() == Looper.myLooper()) {
engine?.runtime?.exit(e) ?: throw e
Expand Down