6.6.2 - Alpha5 - 同步并兼容 Rhino 引擎上游代码 (1.8.1-SNAPSHOT)

This commit is contained in:
SuperMonster003
2025-04-11 15:20:22 +08:00
parent 0092344adb
commit 94b8542f16
10 changed files with 48 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ package org.autojs.autojs.runtime.api.augment.automator
import org.autojs.autojs.extension.ScriptableExtensions.prop
import org.autojs.autojs.runtime.ScriptRuntime
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.withRhinoContext
import org.mozilla.javascript.BaseFunction
import org.mozilla.javascript.BoundFunction
@@ -23,7 +24,7 @@ class RootAutomatorNativeObject(scriptRuntime: ScriptRuntime, waitForReady: Any?
}
init {
super.exportAsJSClass(MAX_PROTOTYPE_ID, this, false)
RhinoUtils.initNativeObjectPrototype(this)
defineProperty("__ra__", mRootAutomatorObject, READONLY or DONTENUM or PERMANENT)
}

View File

@@ -10,6 +10,7 @@ import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.runtime.api.augment.Augmentable
import org.autojs.autojs.runtime.api.augment.colors.Colors.parseRelativePercentage
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
import org.autojs.autojs.util.RhinoUtils.newBaseFunction
import org.autojs.autojs.util.StringUtils.uppercaseFirstChar
@@ -23,7 +24,7 @@ import org.mozilla.javascript.Scriptable
class ColorNativeObject @JvmOverloads constructor(color: Any? = BLACK) : NativeObject(), StringReadable {
init {
super.exportAsJSClass(MAX_PROTOTYPE_ID, this, false)
RhinoUtils.initNativeObjectPrototype(this)
}
private val mProxyTowardsNames by lazy {

View File

@@ -32,6 +32,7 @@ import org.autojs.autojs.runtime.api.augment.Augmentable
import org.autojs.autojs.runtime.api.augment.continuation.Continuation
import org.autojs.autojs.runtime.api.augment.continuation.Creator
import org.autojs.autojs.runtime.exception.WrappedIllegalArgumentException
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
import org.autojs.autojs.util.RhinoUtils.coerceIntNumber
import org.autojs.autojs.util.RhinoUtils.coerceLongNumber
@@ -305,7 +306,7 @@ class Http(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
private class ResponseBodyNativeObject(val resBody: ResponseBody, val responseWrapper: ResponseWrapper) : NativeObject() {
init {
super.exportAsJSClass(MAX_PROTOTYPE_ID, this, false)
RhinoUtils.initNativeObjectPrototype(this)
}
companion object : FlexibleArray() {

View File

@@ -6,6 +6,7 @@ import org.autojs.autojs.extension.AnyExtensions.isJsNullish
import org.autojs.autojs.extension.AnyExtensions.jsBrief
import org.autojs.autojs.extension.FlexibleArray
import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
import org.autojs.autojs.util.RhinoUtils.coerceString
import org.autojs.autojs.util.RhinoUtils.js_json_parse
@@ -35,7 +36,7 @@ class StorageNativeObject(@JvmField val name: String) : NativeObject(), StringRe
)
init {
super.exportAsJSClass(MAX_PROTOTYPE_ID, this, false)
RhinoUtils.initNativeObjectPrototype(this)
defineProperty("name", name, PERMANENT)
defineProperty("size", { storage.size() }, null, PERMANENT)
defineFunctionProperties(mFunctionNames, Getter::class.java, PERMANENT)

View File

@@ -8,6 +8,7 @@ import org.autojs.autojs.extension.ArrayExtensions.toNativeArray
import org.autojs.autojs.extension.FlexibleArray.Companion.ensureArgumentsAtMost
import org.autojs.autojs.extension.FlexibleArray.Companion.ensureArgumentsIsEmpty
import org.autojs.autojs.runtime.api.StringReadable
import org.autojs.autojs.util.RhinoUtils
import org.autojs.autojs.util.RhinoUtils.NOT_CONSTRUCTABLE
import org.autojs.autojs.util.RhinoUtils.newBaseFunction
import org.mozilla.javascript.Context
@@ -26,7 +27,7 @@ class MorseCodeNativeObject(val parser: MorseCodeParser) : NativeObject(), Strin
)
init {
super.exportAsJSClass(MAX_PROTOTYPE_ID, this, false)
RhinoUtils.initNativeObjectPrototype(this)
defineFunctionProperties(mFunctionNames, javaClass, PERMANENT)
defineProperty(StringReadable.KEY, newBaseFunction(StringReadable.KEY, { toStringReadable() }, NOT_CONSTRUCTABLE), READONLY or DONTENUM or PERMANENT)
defineProperty("pattern", { parser.pattern.toNativeArray() }, null, PERMANENT)

View File

@@ -1310,7 +1310,7 @@ object FileUtils {
/** Matroska Video, known for supporting multiple video, audio, subtitle tracks. */
MKV("mkv", TypeDataHolder.VIDEO),
/** QuickTime Movie format, native to Apples QuickTime player. */
/** QuickTime Movie format, native to Apple's QuickTime player. */
MOV("mov", TypeDataHolder.VIDEO),
/** Windows Media Video, a series of video codecs and their corresponding video coding formats. */
@@ -1526,7 +1526,7 @@ object FileUtils {
/** TMPGEnc Video Editor project. */
TPR("tpr", TypeDataHolder.VIDEO),
/** Windows Media, another format for Microsofts video system. */
/** Windows Media, another format for Microsoft's video system. */
WM("wm", TypeDataHolder.VIDEO),
/** Windows Media Player format. */

View File

@@ -83,6 +83,11 @@ object RhinoUtils {
ScriptableObject.getObjectPrototype(standardObjects)
}
@JvmStatic
val arrayPrototype: Scriptable by lazy {
ScriptableObject.getArrayPrototype(standardObjects)
}
@JvmStatic
val functionPrototype: Scriptable by lazy {
standardObjects["Function"].let {
@@ -816,17 +821,32 @@ object RhinoUtils {
}
@JvmStatic
fun newNativeObject() = NativeObject().also {
it.prototype = objectPrototype
fun initNativeObjectPrototype(o: NativeObject): NativeObject {
// val cx = ContextWrapper.getCurrentContext()
// try {
// val tmpScope: Scriptable = cx.initStandardObjects()
// NativeObject.init(tmpScope, false)
// o.prototype = tmpScope.get("Object", tmpScope) as Scriptable
// } finally {
// Context.exit()
// }
return o.apply { prototype = objectPrototype }
}
@JvmStatic
@JvmOverloads
fun newNativeArray(lengthArg: Long = 0) = NativeArray(lengthArg).also { it.exportAsJSClass(NativeArray.MAX_PROTOTYPE_ID, it, false) }
fun initNativeArrayPrototype(a: NativeArray): NativeArray {
return a.apply { prototype = arrayPrototype }
}
@JvmStatic
fun newNativeArray(array: Array<Any?>) = NativeArray(array).also { it.exportAsJSClass(NativeArray.MAX_PROTOTYPE_ID, it, false) }
fun newNativeObject() = initNativeObjectPrototype(NativeObject())
@JvmStatic
@JvmOverloads
fun newNativeArray(lengthArg: Long = 0) = initNativeArrayPrototype(NativeArray(lengthArg))
@JvmStatic
fun newNativeArray(array: Array<Any?>) = initNativeArrayPrototype(NativeArray(array))
@JvmStatic
fun hashCodeOfScriptable(other: Any?): Int? {
if (other !is Scriptable) return null

View File

@@ -56,6 +56,8 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import org.jetbrains.annotations.NotNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Locale;
import java.util.function.Consumer;
@@ -829,6 +831,7 @@ public class ColorPickerDialog extends DialogFragment implements ColorPickerView
// region Builder
@IntDef({TYPE_CUSTOM, TYPE_PRESETS})
@Retention(RetentionPolicy.SOURCE)
public @interface DialogType {
}

View File

@@ -18,12 +18,17 @@ package com.jaredrummler.android.colorpicker;
import androidx.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* The shape of the color preview
*/
@IntDef({ ColorShape.SQUARE, ColorShape.CIRCLE }) public @interface ColorShape {
@IntDef({ColorShape.SQUARE, ColorShape.CIRCLE})
@Retention(RetentionPolicy.SOURCE)
public @interface ColorShape {
int SQUARE = 0;
int SQUARE = 0;
int CIRCLE = 1;
int CIRCLE = 1;
}