6.7.0 - Alpha - 内置模块相关方法实参类型的异常消息增加类型摘要信息
This commit is contained in:
@@ -25,7 +25,7 @@ class SQLite(private val context: Context, private val scriptRuntime: ScriptRunt
|
||||
private class TypeAdapterImpl : Database.TypeAdapter {
|
||||
|
||||
override fun toContentValues(obj: Any?): ContentValues {
|
||||
require(obj is Map<*, *>) { "Argument obj for toContentValue must be a Map<String, Object> instead of ${obj.jsBrief()}" }
|
||||
require(obj is Map<*, *>) { "Argument \"obj\" ${obj.jsBrief()} for toContentValue must be a Map<String, Object>" }
|
||||
val contentValues = ContentValues()
|
||||
for ((k, v) in obj) {
|
||||
val key = coerceString(k)
|
||||
|
||||
@@ -106,7 +106,7 @@ class App(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
fun intentRhinoWithRuntime(scriptRuntime: ScriptRuntime, o: Any?): Intent = when (o) {
|
||||
is Intent -> o
|
||||
is NativeObject -> Intent().configure(scriptRuntime, o)
|
||||
else -> throw IllegalArgumentException("Argument for app.intent must be either an Intent or a JavaScript Object rather than ${o.jsBrief()}")
|
||||
else -> throw IllegalArgumentException("Argument \"o\" ${o.jsBrief()} for app.intent must be either an Intent or a JavaScript Object")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -453,7 +453,7 @@ class App(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
|
||||
@JvmStatic
|
||||
fun sendLocalBroadcastSyncRhino(intent: Any?) = undefined {
|
||||
require(intent is Intent?) { "Argument intent ${intent.jsBrief()} for app.sendLocalBroadcastSync must be a Intent" }
|
||||
require(intent is Intent?) { "Argument \"intent\" ${intent.jsBrief()} for app.sendLocalBroadcastSync must be a Intent" }
|
||||
sendLocalBroadcastSyncInternal(intent)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.autojs.autojs.annotation.RhinoSingletonFunctionInterface
|
||||
import org.autojs.autojs.core.image.ColorDetector
|
||||
import org.autojs.autojs.core.image.ColorTable
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsSpecies
|
||||
import org.autojs.autojs.extension.ArrayExtensions.jsArrayBrief
|
||||
import org.autojs.autojs.extension.ArrayExtensions.toNativeArray
|
||||
@@ -1321,7 +1322,7 @@ object Colors : Augmentable(), SimpleGetterProxy {
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun setPaintColorRhino(paint: Any?, color: Any?) {
|
||||
require(paint is Paint) { "Argument paint for colors.setPaintColor must be a Paint instead of ${paint?.javaClass}" }
|
||||
require(paint is Paint) { "Argument \"paint\" ${paint.jsBrief()} for colors.setPaintColor must be a Paint" }
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q -> {
|
||||
val (a, r, g, b) = toArgbRhino(color).map { it.roundToInt() }
|
||||
|
||||
@@ -57,7 +57,7 @@ class Continuation(private val scriptRuntime: ScriptRuntime) : Augmentable(scrip
|
||||
// @JvmStatic
|
||||
// @RhinoFunctionBody
|
||||
// fun awaitRhinoWithRuntime(scriptRuntime: ScriptRuntime, promise: Any?): Any? {
|
||||
// require(promise is ScriptableObject) { "Argument promise for continuation.await must be a ScriptableObject" }
|
||||
// require(promise is ScriptableObject) { "Argument \"promise\" ${promise.jsBrief()} for continuation.await must be a ScriptableObject" }
|
||||
// val scope = scriptRuntime.topLevelScope
|
||||
// val cont = Context.javaToJS(createRhinoWithRuntime(scriptRuntime, scope), scope) as Scriptable
|
||||
// val thenFunc = promise.prop("then")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.autojs.autojs.runtime.api.augment.continuation
|
||||
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.rhino.continuation.Continuation
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.util.RhinoUtils.UNDEFINED
|
||||
@@ -32,7 +33,7 @@ class Creator(scriptRuntime: ScriptRuntime, scope: Scriptable? = null) {
|
||||
}
|
||||
|
||||
fun resumeError(error: Any?) {
|
||||
require(!error.isJsNullish()) { "Argument error for continuation.resumeError must be non-nullish" }
|
||||
require(!error.isJsNullish()) { "Argument \"error\" ${error.jsBrief()} for continuation.resumeError must be non-nullish" }
|
||||
mContinuation.resumeWith(Continuation.Result.failure(error))
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
val selectedIndices = when {
|
||||
defaultIndices.isJsNullish() -> intArrayOf()
|
||||
defaultIndices is NativeArray -> defaultIndices.map { coerceIntNumber(it, 0) }.toIntArray()
|
||||
else -> throw WrappedIllegalArgumentException("Argument defaultIndices ${defaultIndices.jsBrief()} for dialogs.multiChoice is invalid")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"defaultIndices\" ${defaultIndices.jsBrief()} for dialogs.multiChoice is invalid")
|
||||
}
|
||||
val scope = scriptRuntime.topLevelScope
|
||||
when {
|
||||
@@ -531,7 +531,7 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
if (!properties.prop("progress").isJsNullish()) {
|
||||
val progress = properties.prop("progress")
|
||||
require(progress is NativeObject) {
|
||||
"Property progress of argument properties for dialogs.build must be a JavaScript Object"
|
||||
"Property \"progress\" ${progress.jsBrief()} of argument properties for dialogs.build must be a JavaScript Object"
|
||||
}
|
||||
val max = progress.inquire("max", ::coerceIntNumber, 0)
|
||||
val showMinMax = progress.inquire("showMinMax", ::coerceBoolean, false)
|
||||
@@ -558,7 +558,7 @@ class Dialogs(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
customView = customView.unwrap()
|
||||
}
|
||||
require(customView is View) {
|
||||
"Property customView ${customView.jsBrief()} of argument properties for dialogs.build is invalid"
|
||||
"Property \"customView\" ${customView.jsBrief()} of argument properties for dialogs.build is invalid"
|
||||
}
|
||||
val wrapInScrollView = properties.inquire("wrapInScrollView", ::coerceBoolean, true)
|
||||
builder.customView(customView, wrapInScrollView)
|
||||
|
||||
@@ -138,7 +138,7 @@ class Engines(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunt
|
||||
it.entries.forEach { (key, value) -> result.setArgument(coerceString(key), value) }
|
||||
}
|
||||
}
|
||||
else -> throw WrappedIllegalArgumentException("Argument config ${config.jsBrief()} for Engines#fillConfig is invalid")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"config\" ${config.jsBrief()} for Engines#fillConfig is invalid")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||
import org.autojs.autojs.core.eventloop.EventEmitter
|
||||
import org.autojs.autojs.core.looper.MainThreadProxy
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsSpecies
|
||||
import org.autojs.autojs.extension.FlexibleArray
|
||||
import org.autojs.autojs.extension.ScriptableExtensions.defineProp
|
||||
@@ -37,12 +38,12 @@ class Events(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
if (obj.isJsNullish()) {
|
||||
obj = newNativeObject()
|
||||
}
|
||||
require(obj is ScriptableObject) { "Argument obj for events.__asEmitter__ must be a ScriptableObject" }
|
||||
require(obj is ScriptableObject) { "Argument \"obj\" ${obj.jsBrief()} for events.__asEmitter__ must be a ScriptableObject" }
|
||||
val emitter: EventEmitter = when {
|
||||
thread.isJsNullish() -> scriptRuntime.events.emitter()
|
||||
thread is MainThreadProxy -> scriptRuntime.events.emitter(thread)
|
||||
thread is Thread -> scriptRuntime.events.emitter(thread)
|
||||
else -> throw WrappedIllegalArgumentException("Argument thread for events.__asEmitter__ must be a MainThreadProxy or Thread instead of ${thread.jsSpecies()}")
|
||||
else -> throw WrappedIllegalArgumentException("Argument thread ${thread.jsSpecies()} for events.__asEmitter__ must be a MainThreadProxy or Thread")
|
||||
}
|
||||
val scope = scriptRuntime.topLevelScope
|
||||
emitter.javaClass.declaredMethods.filter {
|
||||
|
||||
@@ -586,7 +586,7 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
when {
|
||||
base.isJsNullish() -> base = scriptRuntime.scale.baseX
|
||||
base is Number -> require(RhinoUtils.isInteger(base)) { "Scale base ${base.jsBrief()} must be a positive integer for cX" }
|
||||
else -> throw WrappedIllegalArgumentException("Argument base ${base.jsBrief()} for cX must be a number if provided")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"base\" ${base.jsBrief()} for cX must be a number if provided")
|
||||
}
|
||||
return@ensureArgumentsAtMost (deviceWidth * num / coerceIntNumber(base)).roundToLong().toDouble()
|
||||
}
|
||||
@@ -610,7 +610,7 @@ class Global(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
when {
|
||||
base.isJsNullish() -> base = scriptRuntime.scale.baseY
|
||||
base is Number -> require(RhinoUtils.isInteger(base)) { "Scale base ${base.jsBrief()} must be a positive integer for cY" }
|
||||
else -> throw WrappedIllegalArgumentException("Argument base ${base.jsBrief()} for cY must be a number if provided")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"base\" ${base.jsBrief()} for cY must be a number if provided")
|
||||
}
|
||||
return@ensureArgumentsAtMost (deviceHeight * num / coerceIntNumber(base)).roundToLong().toDouble()
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ class Http(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
@RhinoFunctionBody
|
||||
fun getRhinoWithRuntime(scriptRuntime: ScriptRuntime, url: Any?, options: Any? = null, callback: Any? = null): Any {
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument options ${options.jsBrief()} for http.get must be a JavaScript Object" }
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for http.get must be a JavaScript Object" }
|
||||
put(niceOptions, KEY_METHOD to METHOD_GET)
|
||||
return requestRhinoWithRuntime(scriptRuntime, url, niceOptions, callback)
|
||||
}
|
||||
@@ -184,7 +184,7 @@ class Http(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
@RhinoFunctionBody
|
||||
fun postRhinoWithRuntime(scriptRuntime: ScriptRuntime, url: Any?, data: Any? = null, options: Any? = null, callback: Any? = null): Any {
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument options ${options.jsBrief()} for http.post must be a JavaScript Object" }
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for http.post must be a JavaScript Object" }
|
||||
put(niceOptions, KEY_METHOD to METHOD_POST)
|
||||
putIfAbsent(niceOptions, KEY_CONTENT_TYPE to DEFAULT_CONTENT_TYPE)
|
||||
fillPostData(niceOptions, data)
|
||||
@@ -203,7 +203,7 @@ class Http(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
@RhinoFunctionBody
|
||||
fun postJsonRhinoWithRuntime(scriptRuntime: ScriptRuntime, url: Any?, data: Any?, options: Any? = null, callback: Any? = null): Any {
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument options ${options.jsBrief()} for http.postJson] must be a JavaScript Object" }
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for http.postJson] must be a JavaScript Object" }
|
||||
put(niceOptions, KEY_CONTENT_TYPE to Mime.APPLICATION_JSON)
|
||||
return postRhinoWithRuntime(scriptRuntime, url, data, niceOptions, callback)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class Http(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
@RhinoFunctionBody
|
||||
fun postMultipartRhinoWithRuntime(scriptRuntime: ScriptRuntime, url: Any?, files: Any?, options: Any? = null, callback: Any? = null): Any {
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument options ${options.jsBrief()} for http.postMultipart] must be a JavaScript Object" }
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for http.postMultipart] must be a JavaScript Object" }
|
||||
listOf(
|
||||
KEY_METHOD to METHOD_POST,
|
||||
KEY_CONTENT_TYPE to Mime.MULTIPART_FORM_DATA,
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.autojs.autojs.runtime.api.augment.jsox
|
||||
import org.autojs.autojs.annotation.RhinoFunctionBody
|
||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionWithThisObjInterface
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.ArrayExtensions.toNativeArray
|
||||
import org.autojs.autojs.extension.ArrayExtensions.unshiftWith
|
||||
import org.autojs.autojs.extension.FlexibleArray
|
||||
@@ -207,8 +208,8 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortByRhino(arr: Any?, selector: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(arr is NativeArray) { "Argument arr for Arrayx.sortBy must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument selector for Arrayx.sortBy must be a JavaScript Function" }
|
||||
require(arr is NativeArray) { "Argument \"arr\" ${arr.jsBrief()} for Arrayx.sortBy must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument \"selector\" ${selector.jsBrief()} for Arrayx.sortBy must be a JavaScript Function" }
|
||||
when {
|
||||
arr.length < 2 -> arr
|
||||
else -> {
|
||||
@@ -229,8 +230,8 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortByDescendingRhino(arr: Any?, selector: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(arr is NativeArray) { "Argument arr for Arrayx.sortByDescending must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument selector for Arrayx.sortByDescending must be a JavaScript Function" }
|
||||
require(arr is NativeArray) { "Argument \"arr\" ${arr.jsBrief()} for Arrayx.sortByDescending must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument \"selector\" ${selector.jsBrief()} for Arrayx.sortByDescending must be a JavaScript Function" }
|
||||
when {
|
||||
arr.length < 2 -> arr
|
||||
else -> {
|
||||
@@ -250,7 +251,7 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortDescendingRhino(arr: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(arr is NativeArray) { "Argument arr for Arrayx.sortDescending must be a JavaScript Array" }
|
||||
require(arr is NativeArray) { "Argument \"arr\" ${arr.jsBrief()} for Arrayx.sortDescending must be a JavaScript Array" }
|
||||
NativeArray.js_sort(cx, arr, arr, arrayOf(toCompareFunctionDesc()))
|
||||
arr
|
||||
}
|
||||
@@ -264,7 +265,7 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortedRhino(it: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(it is NativeArray) { "Argument arr for Arrayx.sorted must be a JavaScript Array" }
|
||||
require(it is NativeArray) { "Argument \"arr\" ${it.jsBrief()} for Arrayx.sorted must be a JavaScript Array" }
|
||||
val copied = it.slice(it.indices).toNativeArray()
|
||||
NativeArray.js_sort(cx, it, copied, arrayOf(toCompareFunctionAsc()))
|
||||
copied
|
||||
@@ -279,7 +280,7 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortedDescendingRhino(it: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(it is NativeArray) { "Argument arr for Arrayx.sortedDescending must be a JavaScript Array" }
|
||||
require(it is NativeArray) { "Argument \"arr\" ${it.jsBrief()} for Arrayx.sortedDescending must be a JavaScript Array" }
|
||||
val copied = it.slice(it.indices).toNativeArray()
|
||||
NativeArray.js_sort(cx, it, copied, arrayOf(toCompareFunctionDesc()))
|
||||
copied
|
||||
@@ -295,8 +296,8 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortedByRhino(arr: Any?, selector: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(arr is NativeArray) { "Argument arr for Arrayx.sortedBy must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument selector for Arrayx.sortedBy must be a JavaScript Function" }
|
||||
require(arr is NativeArray) { "Argument \"arr\" ${arr.jsBrief()} for Arrayx.sortedBy must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument \"selector\" ${selector.jsBrief()} for Arrayx.sortedBy must be a JavaScript Function" }
|
||||
val copied = arr.slice(arr.indices).toNativeArray()
|
||||
when {
|
||||
arr.length < 2 -> copied
|
||||
@@ -317,8 +318,8 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun sortedByDescendingRhino(arr: Any?, selector: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(arr is NativeArray) { "Argument arr for Arrayx.sortedByDescending must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument selector for Arrayx.sortedByDescending must be a JavaScript Function" }
|
||||
require(arr is NativeArray) { "Argument \"arr\" ${arr.jsBrief()} for Arrayx.sortedByDescending must be a JavaScript Array" }
|
||||
require(selector is BaseFunction) { "Argument \"selector\" ${selector.jsBrief()} for Arrayx.sortedByDescending must be a JavaScript Function" }
|
||||
val copied = arr.slice(arr.indices).toNativeArray()
|
||||
when {
|
||||
arr.length < 2 -> copied
|
||||
@@ -338,7 +339,7 @@ class Arrayx(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun shuffleRhino(it: Any?): NativeArray = withRhinoContext { cx ->
|
||||
require(it is NativeArray) { "Argument arr for Arrayx.shuffle must be a JavaScript Array" }
|
||||
require(it is NativeArray) { "Argument \"arr\" ${it.jsBrief()} for Arrayx.shuffle must be a JavaScript Array" }
|
||||
NativeArray.js_sort(cx, it, it, arrayOf(toCompareFunctionRandom()))
|
||||
it
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.autojs.autojs.runtime.api.augment.mime
|
||||
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
import org.autojs.autojs.runtime.api.augment.Augmentable
|
||||
import org.autojs.autojs.runtime.api.augment.Invokable
|
||||
@@ -9,7 +8,6 @@ import org.autojs.autojs.util.RhinoUtils.coerceString
|
||||
class Mime(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime), Invokable {
|
||||
|
||||
override fun invoke(vararg args: Any?): JsMime = ensureArgumentsOnlyOne(args) { mimeStr ->
|
||||
// require(mimeStr is String) { "Argument mimeStr ${mimeStr.jsBrief()} for function mime must be a string" }
|
||||
JsMime(coerceString(mimeStr))
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ object OpenCC : Augmentable(), Invokable {
|
||||
throw WrappedIllegalArgumentException("Unknown type \"$type\" for opencc")
|
||||
}
|
||||
is ConversionType -> ChineseConverter.convert(coerceString(s), type, globalContext)
|
||||
else -> throw WrappedIllegalArgumentException("Argument type ${type.jsBrief()} for opencc.convert is invalid")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"type\" ${type.jsBrief()} for opencc.convert is invalid")
|
||||
}
|
||||
|
||||
/* OpenCC internal conversion. */
|
||||
|
||||
@@ -42,10 +42,10 @@ class SQLite(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRunti
|
||||
require(niceName.isNotEmpty()) { "Argument name of sqlite.open() must not be empty" }
|
||||
|
||||
val niceOptions = if (options.isJsNullish()) newNativeObject() else options
|
||||
require(niceOptions is NativeObject) { "Argument options ${options.jsBrief()} for sqlite.open() must be a JavaScript Object" }
|
||||
require(niceOptions is NativeObject) { "Argument \"options\" ${options.jsBrief()} for sqlite.open() must be a JavaScript Object" }
|
||||
|
||||
val niceCallback = callback.jsSanitize()?.jsTryToJava<DatabaseCallback>()
|
||||
require(niceCallback is DatabaseCallback?) { "Argument callback ${callback.jsBrief()} for sqlite.open() must be a DatabaseCallback" }
|
||||
require(niceCallback is DatabaseCallback?) { "Argument \"callback\" ${callback.jsBrief()} for sqlite.open() must be a DatabaseCallback" }
|
||||
|
||||
scriptRuntime.sqlite.open(
|
||||
name = niceName,
|
||||
|
||||
@@ -84,7 +84,7 @@ class Tasks(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
is TimedTask -> TimedTaskManager.addTaskSync(task)
|
||||
is IntentTask -> TimedTaskManager.addTaskSync(task)
|
||||
else -> listOf(
|
||||
"Argument task ${task.jsBrief()} for tasks.addTask",
|
||||
"Argument \"task\" ${task.jsBrief()} for tasks.addTask",
|
||||
"must be either TimedTask or IntentTask",
|
||||
).joinToString(" ").let { throw WrappedIllegalArgumentException(it) }
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.autojs.autojs.runtime.api.augment.threads
|
||||
|
||||
import org.autojs.autojs.annotation.RhinoRuntimeFunctionInterface
|
||||
import org.autojs.autojs.core.looper.TimerThread
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.FlexibleArray
|
||||
import org.autojs.autojs.extension.ScriptableObjectExtensions.inquire
|
||||
import org.autojs.autojs.runtime.ScriptRuntime
|
||||
@@ -74,7 +75,7 @@ class Threads(scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime) {
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun sync(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Synchronizer = ensureArgumentsLengthInRange(args, 1..2) {
|
||||
val (func, lock) = it
|
||||
require(func is BaseFunction) { "Argument func for global.sync must be a JavaScript Function" }
|
||||
require(func is BaseFunction) { "Argument \"func\" ${func.jsBrief()} for global.sync must be a JavaScript Function" }
|
||||
Synchronizer(func, lock)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class ToastParser(private val msg: Any?, long: Any? = null, forcible: Any? = nul
|
||||
badge.long.matches(o) -> true
|
||||
badge.short.matches(o) -> false
|
||||
badge.forcible.matches(o) -> isLong.also { this.isForcible = true }
|
||||
else -> throw IllegalArgumentException("Argument isLong ${o.jsBrief()} for Toast.Parser is invalid")
|
||||
else -> throw IllegalArgumentException("Argument \"isLong\" ${o.jsBrief()} for Toast.Parser is invalid")
|
||||
}
|
||||
else -> isLong
|
||||
}.also { isLong = it }
|
||||
@@ -53,7 +53,7 @@ class ToastParser(private val msg: Any?, long: Any? = null, forcible: Any? = nul
|
||||
badge.forcible.matches(o) -> true
|
||||
badge.long.matches(o) -> isForcible.also { this.isLong = true }
|
||||
badge.short.matches(o) -> isForcible.also { this.isLong = false }
|
||||
else -> throw IllegalArgumentException("Argument isForcible ${o.jsBrief()} for Toast.Parser is invalid")
|
||||
else -> throw IllegalArgumentException("Argument \"isForcible\" ${o.jsBrief()} for Toast.Parser is invalid")
|
||||
}
|
||||
else -> isForcible
|
||||
}.also { isForcible = it }
|
||||
|
||||
@@ -349,11 +349,11 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoFunctionBody
|
||||
fun __inflateRhinoRuntime__(scriptRuntime: ScriptRuntime, ctx: Any?, xml: Any?, parent: Any?, isAttachedToParent: Any?): View {
|
||||
require(ctx is InflateContext) {
|
||||
"Augment ctx for ui.__inflate__ must be a InflateContext instead of ${ctx.jsBrief()}"
|
||||
"Argument \"ctx\" ${ctx.jsBrief()} for ui.__inflate__ must be a InflateContext instead of ${ctx.jsBrief()}"
|
||||
}
|
||||
val parentView = parent.jsSanitize()
|
||||
require(parentView is ViewGroup?) {
|
||||
"Augment parentView for ui.__inflate__ must be a ViewGroup instead of ${parentView.jsBrief()}"
|
||||
"Argument \"parentView\" ${parentView.jsBrief()} for ui.__inflate__ must be a ViewGroup instead of ${parentView.jsBrief()}"
|
||||
}
|
||||
return scriptRuntime.ui.layoutInflater.inflate(ctx, toXMLString(xml), parentView, coerceBoolean(isAttachedToParent, false))
|
||||
}
|
||||
@@ -370,7 +370,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
fun inflateRhinoRuntime(scriptRuntime: ScriptRuntime, xml: Any?, parent: Any? = null, isAttachedToParent: Any? = false): NativeView {
|
||||
val parentView = parent.jsSanitize()
|
||||
require(parentView is ViewGroup?) {
|
||||
"Augment parentView for ui.inflate must be a ViewGroup instead of ${parentView.jsBrief()}"
|
||||
"Argument \"parentView\" ${parentView.jsBrief()} for ui.inflate must be a ViewGroup instead of ${parentView.jsBrief()}"
|
||||
}
|
||||
val activity = getActivity(scriptRuntime)
|
||||
scriptRuntime.ui.layoutInflater.context = when {
|
||||
@@ -404,7 +404,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoFunctionBody
|
||||
fun runRhinoRuntime(scriptRuntime: ScriptRuntime, action: Any?): Any? {
|
||||
require(action is BaseFunction) {
|
||||
"Argument action for ui.run must be a JavaScript Function instead of ${action.jsBrief()}"
|
||||
"Argument \"action\" ${action.jsBrief()} for ui.run must be a JavaScript Function"
|
||||
}
|
||||
return when {
|
||||
RhinoUtils.isUiThread() -> callFunction(scriptRuntime, action, arrayOf())
|
||||
@@ -451,7 +451,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoFunctionBody
|
||||
fun postRhinoRuntime(scriptRuntime: ScriptRuntime, action: Any?, delay: Any? = null): Boolean {
|
||||
require(action is BaseFunction) {
|
||||
"Argument action for ui.post must be a JavaScript Function instead of ${action.jsBrief()}"
|
||||
"Argument \"action\" ${action.jsBrief()} for ui.post must be a JavaScript Function"
|
||||
}
|
||||
return when {
|
||||
delay.isJsNullish() -> scriptRuntime.uiHandler.post(wrapUiAction(scriptRuntime, action))
|
||||
@@ -492,10 +492,10 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
fun registerWidgetRhinoRuntime(scriptRuntime: ScriptRuntime, name: Any?, widget: Any?): Undefined {
|
||||
val niceName = coerceString(name, "")
|
||||
require(niceName.isNotEmpty()) {
|
||||
"Argument name for ui.registerWidget must be a valid non-empty string"
|
||||
"Argument \"name\" ${name.jsBrief()} for ui.registerWidget must be a valid non-empty string"
|
||||
}
|
||||
require(widget is BaseFunction) {
|
||||
"Argument widget for ui.registerWidget must be a JavaScript Function instead of ${widget.jsBrief()}"
|
||||
"Argument \"widget\" ${widget.jsBrief()} for ui.registerWidget must be a JavaScript Function"
|
||||
}
|
||||
scriptRuntime.ui.widgets.defineProp(niceName, widget)
|
||||
return UNDEFINED
|
||||
@@ -511,7 +511,7 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoFunctionBody
|
||||
fun setContentViewRhinoRuntime(scriptRuntime: ScriptRuntime, view: Any?): Undefined {
|
||||
require(view is View) {
|
||||
"Argument view for ui.setContentView must be a View instead of ${view.jsBrief()}"
|
||||
"Argument \"view\" ${view.jsBrief()} for ui.setContentView must be a View"
|
||||
}
|
||||
ensureActivity(scriptRuntime) { activity ->
|
||||
scriptRuntime.ui.view = view
|
||||
@@ -617,13 +617,8 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun findById(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Any? = ensureArgumentsOnlyOne(args) { id ->
|
||||
when {
|
||||
id.isJsNullish() -> {
|
||||
findByIdRhinoWithRuntime(scriptRuntime, null)
|
||||
}
|
||||
else -> {
|
||||
// require(id is String) { "Argument id for ui.findById must be a string instead of ${id.jsBrief()}" }
|
||||
findByIdRhinoWithRuntime(scriptRuntime, coerceString(id))
|
||||
}
|
||||
id.isJsNullish() -> findByIdRhinoWithRuntime(scriptRuntime, null)
|
||||
else -> findByIdRhinoWithRuntime(scriptRuntime, coerceString(id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,15 +633,10 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun findByStringId(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Any? = ensureArgumentsLength(args, 2) { argList ->
|
||||
val (view, id) = argList
|
||||
require(view is View) { "Argument view for ui.findByStringId must be a View instead of ${view.jsBrief()}" }
|
||||
require(view is View) { "Argument \"view\" ${view.jsBrief()} for ui.findByStringId must be a View" }
|
||||
when {
|
||||
id.isJsNullish() -> {
|
||||
findByStringIdRhinoRuntime(scriptRuntime, view, null)
|
||||
}
|
||||
else -> {
|
||||
// require(id is String) { "Argument id for ui.findByStringId must be a string instead of ${id.jsBrief()}" }
|
||||
findByStringIdRhinoRuntime(scriptRuntime, view, coerceString(id))
|
||||
}
|
||||
id.isJsNullish() -> findByStringIdRhinoRuntime(scriptRuntime, view, null)
|
||||
else -> findByStringIdRhinoRuntime(scriptRuntime, view, coerceString(id))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,13 +651,8 @@ class UI(private val scriptRuntime: ScriptRuntime) : AugmentableProxy(scriptRunt
|
||||
@RhinoRuntimeFunctionInterface
|
||||
fun findView(scriptRuntime: ScriptRuntime, args: Array<out Any?>): Any? = ensureArgumentsOnlyOne(args) { id ->
|
||||
when {
|
||||
id.isJsNullish() -> {
|
||||
findByIdRhinoWithRuntime(scriptRuntime, null)
|
||||
}
|
||||
else -> {
|
||||
// require(id is String) { "Argument id for ui.findView must be a string instead of ${id.jsBrief()}" }
|
||||
findByIdRhinoWithRuntime(scriptRuntime, coerceString(id))
|
||||
}
|
||||
id.isJsNullish() -> findByIdRhinoWithRuntime(scriptRuntime, null)
|
||||
else -> findByIdRhinoWithRuntime(scriptRuntime, coerceString(id))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ object UIWidget : FlexibleArray() {
|
||||
@RhinoStandardFunctionInterface
|
||||
fun notifyViewCreated(cx: Context, thisObj: Scriptable, args: Array<Any?>, funObj: Function): Undefined = ensureArgumentsOnlyOne(args) { view ->
|
||||
require(view is View) {
|
||||
"Argument view for ui.Widget#notifyViewCreated must be a View instead of ${view.jsBrief()}"
|
||||
"Argument \"view\" ${view.jsBrief()} for ui.Widget#notifyViewCreated must be a View"
|
||||
}
|
||||
val onViewCreatedFunc = thisObj.prop("onViewCreated")
|
||||
if (onViewCreatedFunc is BaseFunction) {
|
||||
@@ -136,7 +136,7 @@ object UIWidget : FlexibleArray() {
|
||||
@RhinoStandardFunctionInterface
|
||||
fun notifyAfterInflation(cx: Context, thisObj: Scriptable, args: Array<Any?>, funObj: Function): Undefined = ensureArgumentsOnlyOne(args) { view ->
|
||||
require(view is View) {
|
||||
"Argument view for ui.Widget#notifyAfterInflation must be a View instead of ${view.jsBrief()}"
|
||||
"Argument \"view\" ${view.jsBrief()} for ui.Widget#notifyAfterInflation must be a View"
|
||||
}
|
||||
val onFinishInflationFunc = thisObj.prop("onFinishInflation")
|
||||
if (onFinishInflationFunc is BaseFunction) {
|
||||
@@ -147,7 +147,7 @@ object UIWidget : FlexibleArray() {
|
||||
|
||||
private fun getAttrsObject(thisObj: Scriptable) = thisObj.prop("__attrs__").also { attrsObject ->
|
||||
require(attrsObject is NativeObject) {
|
||||
"Argument __attrs__ for instance of ui.Widget must be a NativeObject instead of ${attrsObject.jsBrief()}"
|
||||
"Argument \"__attrs__\" ${attrsObject.jsBrief()} for instance of ui.Widget must be a NativeObject"
|
||||
}
|
||||
} as NativeObject
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.autojs.autojs.annotation.RhinoFunctionBody
|
||||
import org.autojs.autojs.core.automator.UiObjectCollection
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNonNullObject
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.ArrayExtensions.toNativeObject
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component1
|
||||
import org.autojs.autojs.extension.FlexibleArray.Companion.component2
|
||||
@@ -231,7 +232,7 @@ object Inspect : Augmentable(), Invokable {
|
||||
opt.colors = Context.toBoolean(optionColors)
|
||||
}
|
||||
}
|
||||
else -> throw WrappedIllegalArgumentException("Argument options for util.inspect must be a JavaScript Object")
|
||||
else -> throw WrappedIllegalArgumentException("Argument \"options\" ${options.jsBrief()} for util.inspect must be a JavaScript Object")
|
||||
}
|
||||
val ctx = Ctx().also {
|
||||
it.showHidden = opt.showHidden
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.autojs.autojs.runtime.api.augment.util
|
||||
import org.autojs.autojs.annotation.RhinoFunctionBody
|
||||
import org.autojs.autojs.annotation.RhinoSingletonFunctionInterface
|
||||
import org.autojs.autojs.extension.AnyExtensions.isJsNullish
|
||||
import org.autojs.autojs.extension.AnyExtensions.jsBrief
|
||||
import org.autojs.autojs.extension.ArrayExtensions.toNativeArray
|
||||
import org.autojs.autojs.extension.ScriptableExtensions.prop
|
||||
import org.autojs.autojs.runtime.api.augment.Augmentable
|
||||
@@ -92,7 +93,7 @@ object Java : Augmentable() {
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun objectToMap(args: Array<out Any?>): Any? = ensureArgumentsOnlyOne(args) { o ->
|
||||
if (o.isJsNullish()) return@ensureArgumentsOnlyOne null
|
||||
if (o !is NativeObject) throw WrappedIllegalArgumentException("Argument for util.objectToMap must be a JavaScript Object")
|
||||
if (o !is NativeObject) throw WrappedIllegalArgumentException("Argument \"o\" ${o.jsBrief()} for util.objectToMap must be a JavaScript Object")
|
||||
hashMapOf<String, Any?>().also { map ->
|
||||
for (key in ScriptableObject.getPropertyIds(o)) {
|
||||
map[key.toString()] = o.prop(key.toString())
|
||||
@@ -104,7 +105,7 @@ object Java : Augmentable() {
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun mapToObject(args: Array<out Any?>): Any? = ensureArgumentsOnlyOne(args) { map ->
|
||||
if (map.isJsNullish()) return@ensureArgumentsOnlyOne null
|
||||
if (map !is Map<*, *>) throw WrappedIllegalArgumentException("Argument for util.mapToObject must be a Java Map")
|
||||
if (map !is Map<*, *>) throw WrappedIllegalArgumentException("Argument \"map\" ${map.jsBrief()} for util.mapToObject must be a Java Map")
|
||||
newNativeObject().also { o ->
|
||||
val iter = map.iterator()
|
||||
while (iter.hasNext()) {
|
||||
|
||||
@@ -321,9 +321,9 @@ object Util : Augmentable() {
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun __assignFunctions__Rhino(src: Any?, target: Any?, funcNames: Any?) {
|
||||
if (src !is ScriptableObject) throw WrappedIllegalArgumentException("Argument src for util.__assignFunctions__ must be a ScriptableObject")
|
||||
if (target !is ScriptableObject) throw WrappedIllegalArgumentException("Argument target for util.__assignFunctions__ must be a ScriptableObject")
|
||||
if (funcNames !is NativeArray) throw WrappedIllegalArgumentException("Argument funcNames for util.__assignFunctions__ must be a NativeArray")
|
||||
if (src !is ScriptableObject) throw WrappedIllegalArgumentException("Argument \"src\" ${src.jsBrief()} for util.__assignFunctions__ must be a ScriptableObject")
|
||||
if (target !is ScriptableObject) throw WrappedIllegalArgumentException("Argument \"target\" ${target.jsBrief()} for util.__assignFunctions__ must be a ScriptableObject")
|
||||
if (funcNames !is NativeArray) throw WrappedIllegalArgumentException("Argument \"funcNames\" ${funcNames.jsBrief()} for util.__assignFunctions__ must be a NativeArray")
|
||||
|
||||
funcNames.forEach { funcName ->
|
||||
val name = Context.toString(funcName)
|
||||
@@ -461,14 +461,14 @@ object Util : Augmentable() {
|
||||
@JvmStatic
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun `class`(args: Array<out Any?>): Scriptable = ensureArgumentsOnlyOne(args) { o ->
|
||||
require(o != null) { "Argument for util.class must be non-null" }
|
||||
require(o != null) { "Argument \"o\" ${o.jsBrief()} for util.class must be non-null" }
|
||||
getClassInternal(o)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun getClass(args: Array<out Any?>): Scriptable = ensureArgumentsOnlyOne(args) { o ->
|
||||
require(o != null) { "Argument for util.getClass must be non-null" }
|
||||
require(o != null) { "Argument \"o\" ${o.jsBrief()} for util.getClass must be non-null" }
|
||||
getClassInternal(o)
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ object Util : Augmentable() {
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun className(args: Array<out Any?>): String = ensureArgumentsOnlyOne(args) {
|
||||
when (it) {
|
||||
null -> throw WrappedIllegalArgumentException("Argument for util.className must be non-null")
|
||||
null -> throw WrappedIllegalArgumentException("Argument \"o\" ${it.jsBrief()} for util.className must be non-null")
|
||||
is Class<*> -> it.name
|
||||
else -> it.javaClass.name
|
||||
}
|
||||
@@ -486,7 +486,7 @@ object Util : Augmentable() {
|
||||
@RhinoSingletonFunctionInterface
|
||||
fun getClassName(args: Array<out Any?>): String = ensureArgumentsOnlyOne(args) {
|
||||
when (it) {
|
||||
null -> throw WrappedIllegalArgumentException("Argument for util.getClassName must be non-null")
|
||||
null -> throw WrappedIllegalArgumentException("Argument \"o\" ${it.jsBrief()} for util.getClassName must be non-null")
|
||||
is Class<*> -> it.name
|
||||
else -> it.javaClass.name
|
||||
}
|
||||
@@ -513,7 +513,7 @@ object Util : Augmentable() {
|
||||
else -> throw Error("Unknown pattern $pattern for util.checkStringArgument")
|
||||
}
|
||||
val niceSrc = when {
|
||||
src.isJsNullish() -> throw WrappedIllegalArgumentException("Argument src for util.checkStringArgument must be non-nullish")
|
||||
src.isJsNullish() -> throw WrappedIllegalArgumentException("Argument \"src\" ${src.jsBrief()} for util.checkStringArgument must be non-nullish")
|
||||
isPrimitiveRhino(src) -> Context.toString(src)
|
||||
else -> throw Error("Param src must be non-nullish")
|
||||
}
|
||||
@@ -530,8 +530,8 @@ object Util : Augmentable() {
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun assureStringStartsWithRhino(s: Any?, start: Any?): String {
|
||||
if (s !is String) throw WrappedIllegalArgumentException("Argument s for util.assureStringStartsWith must be a string")
|
||||
if (start !is String) throw WrappedIllegalArgumentException("Argument start for util.assureStringStartsWith must be a string")
|
||||
if (s !is String) throw WrappedIllegalArgumentException("Argument \"s\" ${s.jsBrief()} for util.assureStringStartsWith must be a string")
|
||||
if (start !is String) throw WrappedIllegalArgumentException("Argument \"start\" ${start.jsBrief()} for util.assureStringStartsWith must be a string")
|
||||
return if (s.startsWith(start)) s else start + s
|
||||
}
|
||||
|
||||
@@ -545,8 +545,8 @@ object Util : Augmentable() {
|
||||
@JvmStatic
|
||||
@RhinoFunctionBody
|
||||
fun assureStringEndsWithRhino(s: Any?, end: Any?): String {
|
||||
if (s !is String) throw WrappedIllegalArgumentException("Argument s for util.assureStringEndsWith must be a string")
|
||||
if (end !is String) throw WrappedIllegalArgumentException("Argument end for util.assureStringEndsWith must be a string")
|
||||
if (s !is String) throw WrappedIllegalArgumentException("Argument \"s\" ${s.jsBrief()} for util.assureStringEndsWith must be a string")
|
||||
if (end !is String) throw WrappedIllegalArgumentException("Argument \"end\" ${end.jsBrief()} for util.assureStringEndsWith must be a string")
|
||||
return if (s.endsWith(end)) s else s + end
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class Zip(private val scriptRuntime: ScriptRuntime) : Augmentable(scriptRuntime)
|
||||
fun zipFiles(scriptRuntime: ScriptRuntime, args: Array<out Any?>): ZipNativeObject = ensureArgumentsLengthInRange(args, 2..3) { argList ->
|
||||
var (filePathList, destZipPath, options) = argList
|
||||
require(filePathList is Iterable<*>) {
|
||||
"Argument filePathList ${filePathList.jsBrief()} for zip.${Companion::zipFiles.name} must be an Iterable"
|
||||
"Argument \"filePathList\" ${filePathList.jsBrief()} for zip.${Companion::zipFiles.name} must be an Iterable"
|
||||
}
|
||||
val fileList = mutableListOf<File>()
|
||||
filePathList.forEach { filePath ->
|
||||
|
||||
@@ -60,7 +60,7 @@ class ZipNativeObject(
|
||||
else -> {
|
||||
val pathString = coerceString(rawPath)
|
||||
require(pathString.isNotBlank()) {
|
||||
"Argument path ${pathString.jsBrief()} for zip.$operationName cannot be empty"
|
||||
"Argument \"path\" ${pathString.jsBrief()} for zip.$operationName cannot be empty"
|
||||
}
|
||||
scriptRuntime.files.nonNullPath(pathString)
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class ZipNativeObject(
|
||||
else -> {
|
||||
val niceOptions = rawOptions
|
||||
require(niceOptions is ScriptableObject) {
|
||||
"Argument options ${niceOptions.jsBrief()} for zip.$operationName must be a JavaScript Object"
|
||||
"Argument \"options\" ${niceOptions.jsBrief()} for zip.$operationName must be a JavaScript Object"
|
||||
}
|
||||
niceOptions
|
||||
}
|
||||
@@ -131,7 +131,7 @@ class ZipNativeObject(
|
||||
return params
|
||||
}
|
||||
require(opts is ScriptableObject) {
|
||||
"Argument options ${opts.jsBrief()} for zip.$funcName must be a JavaScript Object"
|
||||
"Argument \"options\" ${opts.jsBrief()} for zip.$funcName must be a JavaScript Object"
|
||||
}
|
||||
params.aesKeyStrength = opts.inquire("aesKeyStrength", { o, def ->
|
||||
o.toAesKeyStrength() ?: def
|
||||
@@ -247,7 +247,7 @@ class ZipNativeObject(
|
||||
return params
|
||||
}
|
||||
require(opts is ScriptableObject) {
|
||||
"Argument options ${opts.jsBrief()} for zip.$funcName must be a JavaScript Object"
|
||||
"Argument \"options\" ${opts.jsBrief()} for zip.$funcName must be a JavaScript Object"
|
||||
}
|
||||
opts.inquire("isExtractSymbolicLinks", ::coerceBoolean, true)
|
||||
opts.inquire("password") { coerceString(it) }?.let { password ->
|
||||
@@ -385,7 +385,7 @@ class ZipNativeObject(
|
||||
val zip = thisObj as ZipNativeObject
|
||||
val (filePathList, options) = argList
|
||||
require(filePathList is Iterable<*>) {
|
||||
"Argument filePathList ${filePathList.jsBrief()} for ${ZipNativeObject::class.java.simpleName}#${Companion::addFiles.name} must be an Iterable"
|
||||
"Argument \"filePathList\" ${filePathList.jsBrief()} for ${ZipNativeObject::class.java.simpleName}#${Companion::addFiles.name} must be an Iterable"
|
||||
}
|
||||
val fileList = mutableListOf<File>()
|
||||
filePathList.forEach { rawFilePath ->
|
||||
|
||||
Reference in New Issue
Block a user