diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/RootAutomatorNativeObject.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/RootAutomatorNativeObject.kt index 8a0e7eb4..14bacdd3 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/RootAutomatorNativeObject.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/automator/RootAutomatorNativeObject.kt @@ -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) } diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/colors/ColorNativeObject.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/colors/ColorNativeObject.kt index 0eed276b..84d5fe7d 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/colors/ColorNativeObject.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/colors/ColorNativeObject.kt @@ -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 { diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/http/Http.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/http/Http.kt index 0ddc3312..aaa11e76 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/http/Http.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/http/Http.kt @@ -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() { diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/storages/StorageNativeObject.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/storages/StorageNativeObject.kt index 48adbb97..97653fb1 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/storages/StorageNativeObject.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/storages/StorageNativeObject.kt @@ -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) diff --git a/app/src/main/java/org/autojs/autojs/runtime/api/augment/util/MorseCodeNativeObject.kt b/app/src/main/java/org/autojs/autojs/runtime/api/augment/util/MorseCodeNativeObject.kt index 2d50bee4..36db8e4f 100644 --- a/app/src/main/java/org/autojs/autojs/runtime/api/augment/util/MorseCodeNativeObject.kt +++ b/app/src/main/java/org/autojs/autojs/runtime/api/augment/util/MorseCodeNativeObject.kt @@ -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) diff --git a/app/src/main/java/org/autojs/autojs/util/FileUtils.kt b/app/src/main/java/org/autojs/autojs/util/FileUtils.kt index b364096a..2edafcaa 100644 --- a/app/src/main/java/org/autojs/autojs/util/FileUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/FileUtils.kt @@ -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 Apple’s 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 Microsoft’s video system. */ + /** Windows Media, another format for Microsoft's video system. */ WM("wm", TypeDataHolder.VIDEO), /** Windows Media Player format. */ diff --git a/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt b/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt index ceac8def..b0fd2593 100644 --- a/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt +++ b/app/src/main/java/org/autojs/autojs/util/RhinoUtils.kt @@ -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) = 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) = initNativeArrayPrototype(NativeArray(array)) @JvmStatic fun hashCodeOfScriptable(other: Any?): Int? { if (other !is Scriptable) return null diff --git a/libs/org.mozilla.rhino-1.8.1-snapshot.jar b/libs/org.mozilla.rhino-1.8.1-snapshot.jar index fae607d5..a6c46e70 100644 Binary files a/libs/org.mozilla.rhino-1.8.1-snapshot.jar and b/libs/org.mozilla.rhino-1.8.1-snapshot.jar differ diff --git a/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java b/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java index dd5b9ab1..f2d4af34 100644 --- a/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java +++ b/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorPickerDialog.java @@ -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 { } diff --git a/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorShape.java b/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorShape.java index 34fdf56c..b43a3195 100644 --- a/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorShape.java +++ b/modules/color-picker/src/main/java/com/jaredrummler/android/colorpicker/ColorShape.java @@ -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; }