6.7.0 - Alpha13 - 同步并兼容 Rhino 引擎上游代码 (2.0.0-SNAPSHOT)

This commit is contained in:
SuperMonster003
2025-12-25 16:49:18 +08:00
parent 7bb8486447
commit adc27e2c34
16 changed files with 35 additions and 35 deletions

View File

@@ -5,10 +5,7 @@
* @see https://raw.githubusercontent.com/taylorhakes/promise-polyfill/master/dist/polyfill.js
*/
/**
* @type {PromiseConstructorLike}
*/
module.exports = (/* @IIFE */ () => {
( /* @ModuleIIFE */ () => {
let _ = {
isArray(x) {
return Boolean(x && typeof x.length !== 'undefined');
@@ -314,5 +311,8 @@ module.exports = (/* @IIFE */ () => {
},
});
return Promise;
/**
* @type {PromiseConstructorLike}
*/
module.exports = Promise;
})();

View File

@@ -22,7 +22,7 @@ public class BindingNativeJavaObject extends NativeJavaObject {
if (this.javaObject != null) {
dynamicType = this.javaObject.getClass();
} else {
dynamicType = this.staticType;
dynamicType = this.staticType.asClass();
}

View File

@@ -35,6 +35,7 @@ import org.mozilla.javascript.ScriptableObject.PERMANENT
import org.mozilla.javascript.ScriptableObject.READONLY
import org.mozilla.javascript.commonjs.module.RequireBuilder
import org.mozilla.javascript.commonjs.module.provider.SoftCachingModuleScriptProvider
import org.mozilla.javascript.lc.type.TypeInfo
import java.io.File
import java.io.IOException
import java.io.InputStreamReader
@@ -106,14 +107,18 @@ open class RhinoJavaScriptEngine(private val androidContext: android.content.Con
override fun init() {
thread = Thread.currentThread()
scriptable.defineProp("global", scriptable, PERMANENT)
scriptable.defineProp("__engine__", this, READONLY or DONTENUM or PERMANENT)
initRequireBuilder(context, scriptable)
runtime.withTimeConsuming("runtime-init-prologue") {
it.initPrologue()
}
scriptable.defineProp("global", scriptable, PERMANENT)
scriptable.defineProp("__engine__", this, READONLY or DONTENUM or PERMANENT)
scriptable.defineProp("Promise", runtime.js_Promise, READONLY or PERMANENT)
scriptable.defineProp("ResultAdapter", runtime.js_ResultAdapter, READONLY or PERMANENT)
mInitScript.withTimeConsuming("script-init") { initScript ->
runCatching {
context.executeScriptWithContinuations(initScript, scriptable)
@@ -200,8 +205,7 @@ open class RhinoJavaScriptEngine(private val androidContext: android.content.Con
if (this is AutoJsContext) {
rhinoJavaScriptEngine = this@RhinoJavaScriptEngine
}
@Suppress("DEPRECATION")
optimizationLevel = -1
isInterpretedMode = true
languageVersion = Context.VERSION_ES6
locale = Locale.getDefault()
wrapFactory = mWrapFactory
@@ -209,9 +213,9 @@ open class RhinoJavaScriptEngine(private val androidContext: android.content.Con
private inner class WrapFactory : AndroidContextFactory.WrapFactory() {
override fun wrapAsJavaObject(cx: Context?, scope: Scriptable, javaObject: Any?, staticType: Class<*>?): Scriptable? {
override fun wrapAsJavaObject(cx: Context?, scope: Scriptable, javaObject: Any?, staticType: TypeInfo): Scriptable? {
return when (javaObject) {
is View -> ViewExtras.getNativeView(scope, /* view = */ javaObject, staticType, runtime)
is View -> ViewExtras.getNativeView(scope, /* view = */ javaObject, staticType.asClass(), runtime)
is Paint -> super.wrapAsJavaObject(cx, scope, RhinoPaint(javaObject), staticType)
else -> super.wrapAsJavaObject(cx, scope, javaObject, staticType)
}

View File

@@ -10,6 +10,7 @@ import org.autojs.autojs6.R
import org.mozilla.javascript.Context
import org.mozilla.javascript.ContextFactory
import org.mozilla.javascript.Scriptable
import org.mozilla.javascript.lc.type.TypeInfo
import java.io.File
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
@@ -51,8 +52,7 @@ open class AndroidContextFactory(private val cacheDirectory: File) : ContextFact
private fun setupContext(context: Context) {
context.apply {
instructionObserverThreshold = 10000
@Suppress("DEPRECATION")
optimizationLevel = -1
isInterpretedMode = true
languageVersion = Context.VERSION_ES6
locale = Locale.getDefault()
wrapFactory = this@AndroidContextFactory.wrapFactory
@@ -77,9 +77,9 @@ open class AndroidContextFactory(private val cacheDirectory: File) : ContextFact
isJavaPrimitiveWrap = Pref.getBoolean(R.string.key_rhino_java_primitive_wrap, R.bool.pref_rhino_java_primitive_wrap)
}
override fun wrap(cx: Context, scope: Scriptable, obj: Any?, staticType: Class<*>?): Any? = when {
obj is String -> bridges.toString(obj.toString())
staticType == UiObjectCollection::class.java -> (obj as? UiObjectCollection)?.let { bridges.asArray(it) } ?: UiObjectCollection.EMPTY
override fun wrap(cx: Context, scope: Scriptable, obj: Any?, staticType: TypeInfo): Any? = when {
obj is String -> bridges.toString(obj)
staticType.asClass() == UiObjectCollection::class.java -> (obj as? UiObjectCollection)?.let { bridges.asArray(it) } ?: UiObjectCollection.EMPTY
else -> super.wrap(cx, scope, obj, staticType)
}

View File

@@ -23,7 +23,7 @@ public class BindingNativeJavaObject extends NativeJavaObject {
if (this.javaObject != null) {
dynamicType = this.javaObject.getClass();
} else {
dynamicType = this.staticType;
dynamicType = this.staticType.asClass();
}
}

View File

@@ -107,8 +107,6 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
override val selfAssignmentGetters = listOf<Pair<String, Supplier<Any?>>>(
"WIDTH" to Supplier { ScreenMetrics.deviceScreenWidth },
"HEIGHT" to Supplier { ScreenMetrics.deviceScreenHeight },
"Promise" to Supplier { scriptRuntime.js_Promise },
"ResultAdapter" to Supplier { scriptRuntime.js_ResultAdapter },
)
companion object {

View File

@@ -54,7 +54,6 @@ import org.autojs.autojs6.R
import org.mozilla.javascript.BaseFunction
import org.mozilla.javascript.Context
import org.mozilla.javascript.NativeArray
import org.mozilla.javascript.NativeFunction
import org.mozilla.javascript.NativeObject
import org.mozilla.javascript.NativeWith
import org.mozilla.javascript.Scriptable
@@ -206,7 +205,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
override fun beforeCreateView(inflateContext: InflateContext, node: Node?, viewName: String, parent: ViewGroup?): View? {
val widgets = scriptRuntime.ui.widgets
if (widgets.contains(viewName)) {
val ctor = widgets.prop(viewName) as NativeFunction
val ctor = widgets.prop(viewName) as BaseFunction
val widget = withRhinoContext { cx ->
ctor.construct(cx, scriptRuntime.topLevelScope, arrayOf())
} as ScriptableObject

View File

@@ -728,10 +728,10 @@ object RhinoUtils {
}
@JvmStatic
fun js_object_getOwnPropertyDescriptor(value: ScriptableObject, key: Any): ScriptableObject? = withRhinoContext { cx ->
fun js_object_getOwnPropertyDescriptor(value: ScriptableObject, key: Any): ScriptableObject = withRhinoContext { cx ->
val topLevel = ImporterTopLevel(cx)
val obj = ensureScriptableObject(toObject(cx, topLevel, value))
obj.getOwnPropertyDescriptor(cx, key)
obj.getOwnPropertyDescriptor(cx, key).toScriptableObject(topLevel)
}
@JvmStatic
@@ -794,8 +794,6 @@ object RhinoUtils {
it.initStandardObjects()
cxRhino = it
}
@Suppress("DEPRECATION")
cx.optimizationLevel = -1
cx.languageVersion = Context.VERSION_ES6
cx.isInterpretedMode = true
function.invoke(cx)

View File

@@ -198,7 +198,7 @@ public class ContextWrapper extends Context {
Context.setCachingEnabled(cachingEnabled);
}
public static DebuggableScript getDebuggableView(Script script) {
public static DebuggableScript getDebuggableView(ScriptOrFn<?> script) {
return Context.getDebuggableView(script);
}