6.6.2 - Alpha5 - 同步并兼容 Rhino 引擎上游代码 (1.8.1-SNAPSHOT)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user