@nstudio/nativescript-compiler 9.2.0-alpha.16 → 9.2.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/kit/kit-index.js +9 -0
- package/dist/kotlin/access.js +14 -15
- package/dist/kotlin/arguments.js +2 -2
- package/dist/kotlin/assignment.js +22 -13
- package/dist/kotlin/builtins.js +67 -0
- package/dist/kotlin/calls.js +3 -2
- package/dist/kotlin/class-declaration.js +16 -1
- package/dist/kotlin/class-methods.js +2 -2
- package/dist/kotlin/components.js +2 -7
- package/dist/kotlin/core-api.js +3 -22
- package/dist/kotlin/declarations.js +86 -9
- package/dist/kotlin/expression-statements.js +13 -1
- package/dist/kotlin/functions.js +2 -4
- package/dist/kotlin/global-calls.js +1 -4
- package/dist/kotlin/literals.js +3 -10
- package/dist/kotlin/names.js +6 -4
- package/dist/kotlin/native/api.js +1 -1
- package/dist/kotlin/native/classfiles.js +2 -13
- package/dist/kotlin/operators.js +36 -30
- package/dist/kotlin/optional-chains.js +3 -10
- package/dist/kotlin/overrides.js +5 -17
- package/dist/kotlin/placement.js +1 -12
- package/dist/kotlin/state-backend.js +6 -2
- package/dist/kotlin/statements.js +1 -13
- package/dist/kotlin/translator.js +3 -11
- package/dist/kotlin/type-tests.js +1 -1
- package/dist/kotlin/types.js +6 -23
- package/dist/program/core-facts.js +9 -0
- package/dist/semantics/classes.js +15 -0
- package/dist/semantics/facts.js +38 -2
- package/dist/semantics/lang.js +29 -0
- package/dist/semantics/lower.js +144 -0
- package/dist/semantics/lowering-methods.js +120 -3
- package/dist/semantics/marks.js +30 -0
- package/dist/semantics/placement.js +9 -3
- package/dist/semantics/refusals.js +12 -11
- package/dist/semantics/signals.js +11 -0
- package/dist/semantics/states/missing.js +7 -0
- package/dist/semantics/tdz.js +142 -8
- package/dist/semantics/throws.js +1 -1
- package/dist/semantics/translator-methods.js +1 -1
- package/dist/swift/access.js +13 -17
- package/dist/swift/assignment.js +30 -16
- package/dist/swift/calls.js +13 -5
- package/dist/swift/classes.js +22 -10
- package/dist/swift/components.js +3 -7
- package/dist/swift/control-flow.js +1 -1
- package/dist/swift/conversion.js +5 -2
- package/dist/swift/core-api.js +11 -31
- package/dist/swift/declarations.js +1 -6
- package/dist/swift/expression-statements.js +7 -0
- package/dist/swift/expressions.js +6 -2
- package/dist/swift/from-any.js +1 -1
- package/dist/swift/functions.js +5 -6
- package/dist/swift/global-calls.js +1 -5
- package/dist/swift/lenient.js +0 -7
- package/dist/swift/literals.js +8 -3
- package/dist/swift/method-values.js +1 -19
- package/dist/swift/modules.js +5 -3
- package/dist/swift/names.js +3 -12
- package/dist/swift/native/api.js +3 -1
- package/dist/swift/native/calls.js +1 -1
- package/dist/swift/native/dispatch.js +2 -8
- package/dist/swift/object-classes.js +84 -1
- package/dist/swift/operators.js +37 -34
- package/dist/swift/optional-chains.js +1 -8
- package/dist/swift/parameters.js +0 -4
- package/dist/swift/placement.js +5 -15
- package/dist/swift/results.js +0 -4
- package/dist/swift/state-backend.js +3 -2
- package/dist/swift/statements.js +1 -13
- package/dist/swift/static-calls.js +2 -3
- package/dist/swift/syntax.js +9 -5
- package/dist/swift/translator.js +1 -11
- package/dist/swift/type-facts.js +3 -3
- package/dist/swift/types.js +3 -3
- package/dist/targets/ios/build.js +1 -1
- package/dist/types/adapter-api.d.ts +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/__Modules.kt +1 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/__Objects.kt +525 -99
- package/kit-android/generated/kotlin/org/nativescript/kit/accessibility_accessibility_common.kt +2 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/application_application_common.kt +29 -6
- package/kit-android/generated/kotlin/org/nativescript/kit/application_helpers_common.kt +14 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/color_color_utils.kt +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/css_mediaquery_index.kt +49 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_array_index.kt +0 -8
- package/kit-android/generated/kotlin/org/nativescript/kit/data_observable_index.kt +0 -16
- package/kit-android/generated/kotlin/org/nativescript/kit/data_virtual_array_index.kt +6 -4
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_index.kt +19 -7
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_http_request_internal_common.kt +14 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/http_http_request_internal_index.kt +19 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/matrix_index.kt +17 -29
- package/kit-android/generated/kotlin/org/nativescript/kit/media_query_list_index.kt +144 -22
- package/kit-android/generated/kotlin/org/nativescript/kit/npm_css_what_src_parse.kt +8 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/org.nativescript.NativeScriptLifecycleCallbacks.kt +2 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_builder_index.kt +0 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_bindable_expression_parser.kt +6 -10
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +531 -8
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_base_index.kt +0 -9
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_weak_event_listener_index.kt +3 -3
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_index.kt +19 -0
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_properties.kt +5 -2
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_styling_style_scope.kt +232 -174
- package/kit-android/generated/kotlin/org/nativescript/kit/ui_text_view_text_view_common.kt +1 -1
- package/kit-android/generated/kotlin/org/nativescript/kit/utils_android_runtime_version.kt +75 -0
- package/kit-android/generated/manifest.json +21 -18
- package/kit-android/generated/source-lines.json +1 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +547 -51
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Intl.kt +1 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +52 -6
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Strings.kt +32 -18
- package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
- package/kit-apple/Overlays/xml-free/Core/ui.builder.index.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +14 -10
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +3 -9
- package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +20 -21
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_index_section_view_ios_android.swift +5 -7
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_ios_android_.swift +130 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_eventName_object_oldIndex_newIndex.swift +2 -4
- package/kit-apple/Sources/NativeScriptKit/Core/Object_specified_substituted_reads.swift +115 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads.swift +113 -0
- package/kit-apple/Sources/NativeScriptKit/Core/Object_substituted_values_reads_.swift +113 -0
- package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +348 -330
- package/kit-apple/Sources/NativeScriptKit/Core/application.application.ios.swift +358 -359
- package/kit-apple/Sources/NativeScriptKit/Core/application.helpers-common.swift +47 -29
- package/kit-apple/Sources/NativeScriptKit/Core/connectivity.index.ios.swift +3 -1
- package/kit-apple/Sources/NativeScriptKit/Core/css-mediaquery.index.swift +95 -53
- package/kit-apple/Sources/NativeScriptKit/Core/css.CSS3Parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/css.parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/data.observable-array.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/file-system.file-system-access.ios.swift +52 -43
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.http-request-internal-common.swift +18 -0
- package/kit-apple/Sources/NativeScriptKit/Core/http.http-request-internal.index.ios.swift +66 -51
- package/kit-apple/Sources/NativeScriptKit/Core/image-source.index.ios.swift +67 -51
- package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
- package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +143 -32
- package/kit-apple/Sources/NativeScriptKit/Core/manifest.json +30 -19
- package/kit-apple/Sources/NativeScriptKit/Core/media-query-list.index.swift +190 -78
- package/kit-apple/Sources/NativeScriptKit/Core/native-window.native-window.ios.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.parse.swift +205 -201
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.stringify.swift +41 -42
- package/kit-apple/Sources/NativeScriptKit/Core/npm.css-what.src.types.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/trace.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.animation.index.ios.swift +77 -65
- package/kit-apple/Sources/NativeScriptKit/Core/ui.builder.index.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.properties.index.swift +1272 -824
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.index.ios.swift +8 -8
- package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view.view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.frame-common.swift +2 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.frame.index.ios.swift +6 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.flexbox-layout.index.ios.swift +22 -21
- package/kit-apple/Sources/NativeScriptKit/Core/ui.page.index.ios.swift +202 -188
- package/kit-apple/Sources/NativeScriptKit/Core/ui.repeater.index.swift +2 -6
- package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.index.ios.swift +3 -3
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.background.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.clip-path-function.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-animation-parser.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.font-common.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style-scope.swift +869 -838
- package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.style.index.swift +46 -31
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.formatted-string.swift +1 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.text-view.text-view-common.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.index.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.modal-transition.ios.swift +4 -4
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.page-transition.ios.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/ui.transition.shared-transition-helper.ios.swift +17 -17
- package/kit-apple/Sources/NativeScriptKit/Core/utils.android-runtime-version.swift +77 -0
- package/kit-apple/Sources/NativeScriptKit/Core/utils.debug-source.swift +2 -2
- package/kit-apple/Sources/NativeScriptKit/Core/xhr.index.swift +62 -61
- package/kit-apple/Sources/NativeScriptKit/Runtime/Array.swift +4 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +2 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Interop.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Intl.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Iterators.swift +1 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +413 -73
- package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +3 -2
- package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +14 -1
- package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +1 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +1 -0
- package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +2 -0
- package/package.json +2 -2
|
@@ -610,7 +610,7 @@ class JSDateTimeFormat(locales: Any? = null, options: Any? = null, required: Str
|
|
|
610
610
|
}
|
|
611
611
|
|
|
612
612
|
private fun zoneName(ms: Long, long: Boolean): String {
|
|
613
|
-
if (timeZoneId == "UTC") return if (long) "Coordinated Universal Time" else "UTC"
|
|
613
|
+
if (timeZoneId == "UTC" || timeZoneId == "Etc/UTC") return if (long) "Coordinated Universal Time" else "UTC"
|
|
614
614
|
// ICU's zone names start in 1970; before, a zone is its offset from GMT.
|
|
615
615
|
if (ms < 0) return offsetName(ms, long)
|
|
616
616
|
val dst = timeZone.inDaylightTime(java.util.Date(ms))
|
|
@@ -27,7 +27,7 @@ private fun jsJSONInternalize(holder: Any, key: String, reviver: Any?): Any? {
|
|
|
27
27
|
@Suppress("UNCHECKED_CAST") val array = value as JSArray<Any?>
|
|
28
28
|
for (i in 0 until array.size) if (i < array.size) array.setAt(i, jsJSONInternalize(array, i.toString(), reviver))
|
|
29
29
|
}
|
|
30
|
-
is JSObject -> for (k in value.keys) {
|
|
30
|
+
is JSObject -> for (k in value.keys.toList()) {
|
|
31
31
|
val revived = jsJSONInternalize(value, k, reviver)
|
|
32
32
|
if (revived == null) value.delete(k) else value[k] = revived
|
|
33
33
|
}
|
|
@@ -109,7 +109,7 @@ private class JSONParser(val source: String) {
|
|
|
109
109
|
value = top.array
|
|
110
110
|
}
|
|
111
111
|
is Container.Object -> {
|
|
112
|
-
top.obj
|
|
112
|
+
top.obj.defineParsed(top.key, value)
|
|
113
113
|
if (peek() == ','.code) {
|
|
114
114
|
position++
|
|
115
115
|
skipWhitespace()
|
|
@@ -365,7 +365,7 @@ interface JSToJSON {
|
|
|
365
365
|
|
|
366
366
|
/** SerializeJSONProperty and its kin, writing into one builder. */
|
|
367
367
|
private class JSONWriter(val gap: String?) {
|
|
368
|
-
private val out = StringBuilder()
|
|
368
|
+
private val out = StringBuilder(256)
|
|
369
369
|
/** The arrays and objects being written, outermost first, and the key each is written under (for a cycle's message). */
|
|
370
370
|
private val holders = ArrayList<Any>()
|
|
371
371
|
private val holderKeys = ArrayList<String>()
|
|
@@ -382,8 +382,12 @@ private class JSONWriter(val gap: String?) {
|
|
|
382
382
|
*/
|
|
383
383
|
private fun property(holder: Any?, key: String?, index: Int, value: Any?, depth: Int): Boolean {
|
|
384
384
|
var v = jsBox(value)
|
|
385
|
-
if (v is
|
|
386
|
-
|
|
385
|
+
if (v is JSObject) {
|
|
386
|
+
val toJSON = if (v.isPlainFast) v.storage["toJSON"] else v.jsGet("toJSON")
|
|
387
|
+
if (toJSON is Function<*>) v = jsBox(jsCall(toJSON, key ?: index.toString()))
|
|
388
|
+
} else if (v is JSToJSON) {
|
|
389
|
+
v = jsBox(v.jsToJSON(key ?: index.toString()))
|
|
390
|
+
} else if (v is JSDynamic && v !is JSError) {
|
|
387
391
|
val toJSON = v.jsGet("toJSON")
|
|
388
392
|
if (toJSON is Function<*>) v = jsBox(jsCall(toJSON, key ?: index.toString()))
|
|
389
393
|
}
|
|
@@ -409,12 +413,17 @@ private class JSONWriter(val gap: String?) {
|
|
|
409
413
|
val n = jsNumeric(v)
|
|
410
414
|
if (n != null) number(n)
|
|
411
415
|
else when (v) {
|
|
412
|
-
is JSArray<*> ->
|
|
416
|
+
is JSArray<*> -> {
|
|
417
|
+
val d = v.doubles
|
|
418
|
+
if (d != null && replacer == null) doubleArray(v, key ?: index.toString(), d, v.dSize, depth)
|
|
419
|
+
else array(v, key ?: index.toString(), v.storage, depth)
|
|
420
|
+
}
|
|
413
421
|
is JSMatch -> array(v, key ?: index.toString(), v.values.storage, depth)
|
|
414
422
|
is JSMatchIndices -> array(v, key ?: index.toString(), v.values.storage, depth)
|
|
415
423
|
is Pair<*, *> -> array(v, key ?: index.toString(), listOf(v.first, v.second), depth)
|
|
416
424
|
is Triple<*, *, *> -> array(v, key ?: index.toString(), listOf(v.first, v.second, v.third), depth)
|
|
417
425
|
is JSRegExp -> out.append("{}")
|
|
426
|
+
is JSObject -> if (v.isPlainFast && allowed == null && replacer == null) plainObj(v, key ?: index.toString(), depth) else obj(v, key ?: index.toString(), depth)
|
|
418
427
|
is JSDynamic -> obj(v, key ?: index.toString(), depth)
|
|
419
428
|
else -> out.append("{}")
|
|
420
429
|
}
|
|
@@ -481,6 +490,22 @@ private class JSONWriter(val gap: String?) {
|
|
|
481
490
|
holderKeys.removeAt(holderKeys.size - 1)
|
|
482
491
|
}
|
|
483
492
|
|
|
493
|
+
private fun doubleArray(owner: Any, key: String, elements: DoubleArray, count: Int, depth: Int) {
|
|
494
|
+
enter(key, owner)
|
|
495
|
+
if (count == 0) out.append("[]")
|
|
496
|
+
else {
|
|
497
|
+
out.append('[')
|
|
498
|
+
for (i in 0 until count) {
|
|
499
|
+
if (i > 0) out.append(',')
|
|
500
|
+
newline(depth + 1)
|
|
501
|
+
number(elements[i])
|
|
502
|
+
}
|
|
503
|
+
newline(depth)
|
|
504
|
+
out.append(']')
|
|
505
|
+
}
|
|
506
|
+
leave()
|
|
507
|
+
}
|
|
508
|
+
|
|
484
509
|
private fun array(owner: Any, key: String, elements: List<Any?>, depth: Int) {
|
|
485
510
|
enter(key, owner)
|
|
486
511
|
if (elements.isEmpty()) out.append("[]")
|
|
@@ -497,6 +522,27 @@ private class JSONWriter(val gap: String?) {
|
|
|
497
522
|
leave()
|
|
498
523
|
}
|
|
499
524
|
|
|
525
|
+
/** Fast path for a plain JSObject with no replacer, filter, slots, prototype, or reactive tracker. */
|
|
526
|
+
private fun plainObj(owner: JSObject, key: String, depth: Int) {
|
|
527
|
+
enter(key, owner)
|
|
528
|
+
val keys = owner.namedKeys
|
|
529
|
+
val map = owner.storage
|
|
530
|
+
out.append('{')
|
|
531
|
+
var written = false
|
|
532
|
+
for (i in 0 until keys.size) {
|
|
533
|
+
val k = keys[i]
|
|
534
|
+
val mark = out.length
|
|
535
|
+
if (written) out.append(',')
|
|
536
|
+
newline(depth + 1)
|
|
537
|
+
appendJSONQuoted(out, k)
|
|
538
|
+
out.append(if (gap == null) ":" else ": ")
|
|
539
|
+
if (property(owner, k, -1, map[k], depth + 1)) written = true else out.setLength(mark)
|
|
540
|
+
}
|
|
541
|
+
if (written) newline(depth)
|
|
542
|
+
out.append('}')
|
|
543
|
+
leave()
|
|
544
|
+
}
|
|
545
|
+
|
|
500
546
|
/** SerializeJSONObject: the keys as they are on entry, each value read as it is written. */
|
|
501
547
|
private fun obj(owner: JSDynamic, key: String, depth: Int) {
|
|
502
548
|
enter(key, owner)
|
|
@@ -356,6 +356,39 @@ fun <T : Any> jsMethodReceiver(self: Any?, own: T, cls: Class<*>): T = if (cls.i
|
|
|
356
356
|
/** A method read from a prototype for an instance (`View.prototype._setMinWidthNative`): the instance is its `this`. */
|
|
357
357
|
fun jsBoundTo(value: Any?, receiver: Any?): Any? = if (value is JSMethod) JSFunction { args -> value.call(receiver, args.toTypedArray()) } else value
|
|
358
358
|
|
|
359
|
+
/** Zero-vararg exact-arity fast paths for `jsCallMethod` (0–3 arguments). */
|
|
360
|
+
fun jsCallMethod(target: Any?, key: String): Any? {
|
|
361
|
+
if ((key == "bind" || key == "call" || key == "apply") && jsIsFunction(target)) return jsCallMethod(target, key, *JS_EMPTY_ARGS)
|
|
362
|
+
var f = jsGet(target, key)
|
|
363
|
+
if (jsBox(f) == null && jsBox(target) is JSDynamic && JSPrototypes.objectPrototype.has(key)) f = JSPrototypes.objectPrototype[key]
|
|
364
|
+
if (f is JSMethod) return jsBox(f.call(target, JS_EMPTY_ARGS))
|
|
365
|
+
return jsCall(f)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
fun jsCallMethod(target: Any?, key: String, a0: Any?): Any? {
|
|
369
|
+
if ((key == "bind" || key == "call" || key == "apply") && jsIsFunction(target)) return jsCallMethod(target, key, *arrayOf(a0))
|
|
370
|
+
var f = jsGet(target, key)
|
|
371
|
+
if (jsBox(f) == null && jsBox(target) is JSDynamic && JSPrototypes.objectPrototype.has(key)) f = JSPrototypes.objectPrototype[key]
|
|
372
|
+
if (f is JSMethod) return jsBox(f.call(target, arrayOf(a0)))
|
|
373
|
+
return jsCall(f, a0)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
fun jsCallMethod(target: Any?, key: String, a0: Any?, a1: Any?): Any? {
|
|
377
|
+
if ((key == "bind" || key == "call" || key == "apply") && jsIsFunction(target)) return jsCallMethod(target, key, *arrayOf(a0, a1))
|
|
378
|
+
var f = jsGet(target, key)
|
|
379
|
+
if (jsBox(f) == null && jsBox(target) is JSDynamic && JSPrototypes.objectPrototype.has(key)) f = JSPrototypes.objectPrototype[key]
|
|
380
|
+
if (f is JSMethod) return jsBox(f.call(target, arrayOf(a0, a1)))
|
|
381
|
+
return jsCall(f, a0, a1)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
fun jsCallMethod(target: Any?, key: String, a0: Any?, a1: Any?, a2: Any?): Any? {
|
|
385
|
+
if ((key == "bind" || key == "call" || key == "apply") && jsIsFunction(target)) return jsCallMethod(target, key, *arrayOf(a0, a1, a2))
|
|
386
|
+
var f = jsGet(target, key)
|
|
387
|
+
if (jsBox(f) == null && jsBox(target) is JSDynamic && JSPrototypes.objectPrototype.has(key)) f = JSPrototypes.objectPrototype[key]
|
|
388
|
+
if (f is JSMethod) return jsBox(f.call(target, arrayOf(a0, a1, a2)))
|
|
389
|
+
return jsCall(f, a0, a1, a2)
|
|
390
|
+
}
|
|
391
|
+
|
|
359
392
|
/** `object.method(args)` on an untyped object: a method sees the object as `this`. */
|
|
360
393
|
fun jsCallMethod(target: Any?, key: String, vararg args: Any?): Any? {
|
|
361
394
|
// `fn.call(thisArg, …)`, `fn.apply(thisArg, list)` of a function value: a method sees `thisArg`, any other function ignores it.
|
|
@@ -105,6 +105,14 @@ object JSPrototypes {
|
|
|
105
105
|
return objectPrototype
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
/** `Object.getPrototypeOf` of a class constructor: its superclass, else `Function.prototype`. */
|
|
109
|
+
fun prototypeOfClass(cls: Class<*>): Any? {
|
|
110
|
+
if (customPrototypes.containsKey(cls)) return customPrototypes[cls]
|
|
111
|
+
val superclass = cls.superclass
|
|
112
|
+
if (superclass != null && superclass != Any::class.java) return superclass
|
|
113
|
+
return builtin("Function")
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
/** The nearest prototype in a class's chain that has the key. */
|
|
109
117
|
fun holder(cls: Class<*>, key: String): JSObject? {
|
|
110
118
|
if (table.isEmpty() && declared.isEmpty()) return null
|
|
@@ -176,7 +184,7 @@ fun jsGetPrototypeOf(value: Any?): Any? = when (val v = jsBox(value)) {
|
|
|
176
184
|
null, JSNull -> throw JSException(JSTypeError("Cannot convert undefined or null to object"))
|
|
177
185
|
is JSObject -> JSPrototypes.prototypeOf(v)
|
|
178
186
|
is JSRecord<*> -> JSPrototypes.prototypeOf(v.obj)
|
|
179
|
-
is Class<*> -> JSPrototypes.
|
|
187
|
+
is Class<*> -> JSPrototypes.prototypeOfClass(v)
|
|
180
188
|
is JSArray<*>, is Pair<*, *>, is Triple<*, *, *> -> JSPrototypes.builtin("Array")
|
|
181
189
|
is String -> JSPrototypes.builtin("String")
|
|
182
190
|
is Boolean -> JSPrototypes.builtin("Boolean")
|
|
@@ -6,22 +6,29 @@ import java.util.Locale
|
|
|
6
6
|
// String and Math members whose JavaScript behavior differs from Kotlin's. Kotlin strings
|
|
7
7
|
// index UTF-16 code units, as JavaScript's do.
|
|
8
8
|
|
|
9
|
-
private
|
|
9
|
+
private val ASCII_CHARS = Array(128) { it.toChar().toString() }
|
|
10
|
+
|
|
11
|
+
private inline fun singleChar(c: Char): String = if (c.code < 128) ASCII_CHARS[c.code] else c.toString()
|
|
12
|
+
|
|
13
|
+
private fun clampIndex(v: Double, count: Int): Int {
|
|
14
|
+
val k = v.toInt()
|
|
15
|
+
return if (k <= 0) 0 else if (k >= count) count else k
|
|
16
|
+
}
|
|
10
17
|
|
|
11
18
|
/** Compares strings by UTF-16 code units, as JavaScript's `<` does: -1, 0 or 1. */
|
|
12
19
|
fun jsCompare(a: String, b: String): Int = a.compareTo(b).let { if (it < 0) -1 else if (it > 0) 1 else 0 }
|
|
13
20
|
|
|
14
|
-
fun jsIncludes(s: String, search: String, position: Double? = null): Boolean = s.indexOf(search,
|
|
21
|
+
fun jsIncludes(s: String, search: String, position: Double? = null): Boolean = s.indexOf(search, if (position == null) 0 else clampIndex(position, s.length)) >= 0
|
|
15
22
|
|
|
16
|
-
fun jsStartsWith(s: String, search: String, position: Double? = null): Boolean = s.startsWith(search,
|
|
23
|
+
fun jsStartsWith(s: String, search: String, position: Double? = null): Boolean = s.startsWith(search, if (position == null) 0 else clampIndex(position, s.length))
|
|
17
24
|
|
|
18
25
|
fun jsEndsWith(s: String, search: String, endPosition: Double? = null): Boolean {
|
|
19
|
-
val end =
|
|
26
|
+
val end = if (endPosition == null) s.length else clampIndex(endPosition, s.length)
|
|
20
27
|
return search.length <= end && s.regionMatches(end - search.length, search, 0, search.length)
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
fun jsIndexOf(s: String, search: String, position: Double? = null): Double {
|
|
24
|
-
val start =
|
|
31
|
+
val start = if (position == null) 0 else clampIndex(position, s.length)
|
|
25
32
|
if (search.isEmpty()) return start.toDouble()
|
|
26
33
|
return s.indexOf(search, start).toDouble()
|
|
27
34
|
}
|
|
@@ -35,15 +42,16 @@ fun jsLastIndexOf(s: String, search: String, fromIndex: Double? = null): Double
|
|
|
35
42
|
|
|
36
43
|
/** `s.slice(start, end)`: negative indexes count from the end; out-of-range clamps. */
|
|
37
44
|
fun jsSlice(s: String, start: Double = 0.0, end: Double? = null): String {
|
|
38
|
-
val
|
|
39
|
-
val
|
|
45
|
+
val len = s.length
|
|
46
|
+
val a = if (start >= 0.0) { val k = start.toInt(); if (k >= len) len else k } else jsRelativeIndex(start, len)
|
|
47
|
+
val b = if (end == null) len else if (end >= 0.0) { val k = end.toInt(); if (k >= len) len else k } else jsRelativeIndex(end, len)
|
|
40
48
|
return if (a < b) s.substring(a, b) else ""
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
/** `s.substring(a, b)`: negative and NaN are 0, and the bounds swap if reversed. */
|
|
44
52
|
fun jsSubstring(s: String, start: Double, end: Double? = null): String {
|
|
45
53
|
var a = clampIndex(start, s.length)
|
|
46
|
-
var b =
|
|
54
|
+
var b = if (end == null) s.length else clampIndex(end, s.length)
|
|
47
55
|
if (a > b) { val t = a; a = b; b = t }
|
|
48
56
|
return s.substring(a, b)
|
|
49
57
|
}
|
|
@@ -56,31 +64,37 @@ fun jsSubstr(s: String, start: Double, length: Double? = null): String {
|
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
fun jsCharAt(s: String, index: Double): String {
|
|
59
|
-
val i =
|
|
60
|
-
return if (i >= 0 && i < s.length) s[i
|
|
67
|
+
val i = index.toInt()
|
|
68
|
+
return if (i >= 0 && i < s.length) singleChar(s[i]) else ""
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
/** `s[index]`: undefined (null) past either end or at a fractional index, where `charAt` gives "". */
|
|
64
72
|
fun jsCharAtOrNull(s: String, index: Double): String? {
|
|
65
73
|
val i = index.toInt()
|
|
66
|
-
return if (i >= 0 && i < s.length && i.toDouble() == index) s[i]
|
|
74
|
+
return if (i >= 0 && i < s.length && i.toDouble() == index) singleChar(s[i]) else null
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
fun jsCharCodeAt(s: String, index: Double): Double {
|
|
70
|
-
val i =
|
|
71
|
-
return if (i >= 0 && i < s.length) s[i
|
|
78
|
+
val i = index.toInt()
|
|
79
|
+
return if (i >= 0 && i < s.length) s[i].code.toDouble() else Double.NaN
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
fun jsCodePointAt(s: String, index: Double): Double? {
|
|
75
|
-
val i =
|
|
83
|
+
val i = index.toInt()
|
|
76
84
|
if (i < 0 || i >= s.length) return null
|
|
77
|
-
|
|
85
|
+
val c = s[i]
|
|
86
|
+
if (!Character.isHighSurrogate(c) || i + 1 >= s.length) return c.code.toDouble()
|
|
87
|
+
val lo = s[i + 1]
|
|
88
|
+
return (if (Character.isLowSurrogate(lo)) Character.toCodePoint(c, lo) else c.code).toDouble()
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
fun jsStringAt(s: String, index: Double): String? {
|
|
81
|
-
var i =
|
|
82
|
-
if (i < 0)
|
|
83
|
-
|
|
92
|
+
var i = index.toInt()
|
|
93
|
+
if (i < 0) {
|
|
94
|
+
if (index <= -2_147_483_648.0) return null
|
|
95
|
+
i += s.length
|
|
96
|
+
}
|
|
97
|
+
return if (i >= 0 && i < s.length) singleChar(s[i]) else null
|
|
84
98
|
}
|
|
85
99
|
|
|
86
100
|
fun jsFromCharCode(vararg codes: Double): String = String(CharArray(codes.size) { (jsToUint32(codes[it]).toInt() and 0xFFFF).toChar() })
|
|
@@ -258,11 +258,12 @@ fun jsObjectOf(vararg entries: Pair<String, Any?>): JSObject = JSObject(*entries
|
|
|
258
258
|
* ascending, then the other keys in insertion order.
|
|
259
259
|
*/
|
|
260
260
|
class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConvertible {
|
|
261
|
-
|
|
262
|
-
private
|
|
263
|
-
|
|
261
|
+
internal val storage = HashMap<String, Any?>(8)
|
|
262
|
+
private var indexKeys: ArrayList<Long>? = null
|
|
263
|
+
internal val namedKeys = ArrayList<String>(8)
|
|
264
264
|
/** Properties that are accessors or not plain writable, enumerable, configurable data. */
|
|
265
|
-
private
|
|
265
|
+
private var slots: HashMap<String, JSPropertySlot>? = null
|
|
266
|
+
private var hasSymbols = false
|
|
266
267
|
var extensible = true
|
|
267
268
|
private set
|
|
268
269
|
var jsTracker: JSTracker? = null
|
|
@@ -273,6 +274,10 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
273
274
|
/** What weak collections hold for this object as their key. */
|
|
274
275
|
internal var weakSlots: JSWeakSlots? = null
|
|
275
276
|
|
|
277
|
+
/** True when this object has only plain enumerable string keys, no prototype, and no reactive tracker. */
|
|
278
|
+
internal val isPlainFast: Boolean
|
|
279
|
+
get() = indexKeys == null && !hasSymbols && slots == null && jsPrototype == null && jsTracker == null
|
|
280
|
+
|
|
276
281
|
constructor(entries: List<Pair<String, Any?>>) : this() {
|
|
277
282
|
for ((k, v) in entries) define(k, v)
|
|
278
283
|
}
|
|
@@ -285,7 +290,8 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
285
290
|
var jsPrototype: Any? = null
|
|
286
291
|
|
|
287
292
|
operator fun get(key: String): Any? {
|
|
288
|
-
|
|
293
|
+
val s = slots
|
|
294
|
+
if (s != null && s.isNotEmpty()) s[key]?.get?.let { return it(this) }
|
|
289
295
|
jsPrototype?.let { proto -> if (!storage.containsKey(key)) return jsBox(proto).let { p -> if (p is JSObject) p.get(key, this) else jsGet(p, key) } }
|
|
290
296
|
val tracker = jsTracker ?: return storage[key]
|
|
291
297
|
tracker.track()
|
|
@@ -294,7 +300,8 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
294
300
|
|
|
295
301
|
/** `object[key]` read for `receiver`, which an accessor sees as `this` (an instance reading its prototype's). */
|
|
296
302
|
fun get(key: String, receiver: Any?): Any? {
|
|
297
|
-
|
|
303
|
+
val s = slots
|
|
304
|
+
if (s != null && s.isNotEmpty()) s[key]?.let { if (it.isAccessor) return it.get?.invoke(receiver) }
|
|
298
305
|
val proto = jsBox(jsPrototype)
|
|
299
306
|
if (proto is JSObject && !storage.containsKey(key)) return proto.get(key, receiver)
|
|
300
307
|
return this[key]
|
|
@@ -311,16 +318,30 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
311
318
|
}
|
|
312
319
|
|
|
313
320
|
/** The setter of an accessor property; it takes the receiver as `this`. */
|
|
314
|
-
fun setter(key: String): ((Any?, Any?) -> Unit)? = slots
|
|
321
|
+
fun setter(key: String): ((Any?, Any?) -> Unit)? = slots?.get(key)?.takeIf { it.isAccessor }?.set
|
|
315
322
|
|
|
316
323
|
operator fun set(key: String, value: Any?) = put(key, value)
|
|
317
324
|
|
|
325
|
+
/** Fast property insertion for `JSON.parse` on a freshly created object. */
|
|
326
|
+
internal fun defineParsed(key: String, value: Any?) {
|
|
327
|
+
if (key.isEmpty() || key[0] !in '0'..'9') {
|
|
328
|
+
val existed = storage.containsKey(key)
|
|
329
|
+
storage[key] = value
|
|
330
|
+
if (!existed) {
|
|
331
|
+
namedKeys.add(key)
|
|
332
|
+
if (jsIsSymbolKey(key)) hasSymbols = true
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
define(key, value)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
318
339
|
/**
|
|
319
340
|
* `object[key] = value` in strict code: a read-only property, a getter without a setter
|
|
320
341
|
* or a new key on an object that is not extensible throws a TypeError.
|
|
321
342
|
*/
|
|
322
343
|
fun put(key: String, value: Any?) {
|
|
323
|
-
val slot = slots
|
|
344
|
+
val slot = slots?.get(key)
|
|
324
345
|
if (slot != null) {
|
|
325
346
|
if (slot.isAccessor) {
|
|
326
347
|
val setter = slot.set ?: throw JSException(JSTypeError("Cannot set property $key of #<Object> which has only a getter"))
|
|
@@ -350,7 +371,7 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
350
371
|
/** `Object.defineProperty(object, key, descriptor)`; attributes the descriptor leaves out are false for a new property. */
|
|
351
372
|
fun defineProperty(key: String, d: JSPropertyDescriptor) {
|
|
352
373
|
val exists = storage.containsKey(key)
|
|
353
|
-
val slot = slots
|
|
374
|
+
val slot = slots?.get(key) ?: JSPropertySlot(enumerable = exists, writable = exists, configurable = exists)
|
|
354
375
|
if (!exists && !extensible) throw JSException(JSTypeError("Cannot define property $key, object is not extensible"))
|
|
355
376
|
if (exists && !slot.configurable) {
|
|
356
377
|
val changes = d.get != null || d.set != null || d.configurable == true || (d.enumerable != null && d.enumerable != slot.enumerable) ||
|
|
@@ -366,14 +387,14 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
366
387
|
d.writable?.let { slot.writable = it }
|
|
367
388
|
d.configurable?.let { slot.configurable = it }
|
|
368
389
|
define(key, if (slot.isAccessor) null else if (d.hasValue) d.value else storage[key])
|
|
369
|
-
if (slot.isPlain) slots
|
|
390
|
+
if (slot.isPlain) slots?.remove(key) else (slots ?: HashMap<String, JSPropertySlot>(4).also { slots = it })[key] = slot
|
|
370
391
|
jsTracker?.trigger()
|
|
371
392
|
}
|
|
372
393
|
|
|
373
394
|
/** `Object.getOwnPropertyDescriptor(object, key)`. */
|
|
374
395
|
fun descriptor(key: String): JSObject? {
|
|
375
396
|
if (!storage.containsKey(key)) return null
|
|
376
|
-
val slot = slots
|
|
397
|
+
val slot = slots?.get(key) ?: JSPropertySlot()
|
|
377
398
|
if (slot.isAccessor) {
|
|
378
399
|
val g = slot.get
|
|
379
400
|
val s = slot.set
|
|
@@ -388,39 +409,60 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
388
409
|
fun restrict(sealed: Boolean, frozen: Boolean) {
|
|
389
410
|
extensible = false
|
|
390
411
|
if (!sealed && !frozen) return
|
|
391
|
-
|
|
392
|
-
|
|
412
|
+
val s = slots ?: HashMap<String, JSPropertySlot>(storage.size).also { slots = it }
|
|
413
|
+
val idx = indexKeys
|
|
414
|
+
if (idx != null) {
|
|
415
|
+
for (n in idx) {
|
|
416
|
+
val key = n.toString()
|
|
417
|
+
val slot = s[key] ?: JSPropertySlot()
|
|
418
|
+
slot.configurable = false
|
|
419
|
+
if (frozen && !slot.isAccessor) slot.writable = false
|
|
420
|
+
s[key] = slot
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
for (key in namedKeys) {
|
|
424
|
+
val slot = s[key] ?: JSPropertySlot()
|
|
393
425
|
slot.configurable = false
|
|
394
426
|
if (frozen && !slot.isAccessor) slot.writable = false
|
|
395
|
-
|
|
427
|
+
s[key] = slot
|
|
396
428
|
}
|
|
397
429
|
}
|
|
398
430
|
|
|
399
|
-
val isSealed: Boolean get() = !extensible && storage.keys.all { !(slots
|
|
400
|
-
val isFrozen: Boolean get() = !extensible && storage.keys.all { val s = slots
|
|
431
|
+
val isSealed: Boolean get() = !extensible && storage.keys.all { !(slots?.get(it) ?: JSPropertySlot()).configurable }
|
|
432
|
+
val isFrozen: Boolean get() = !extensible && storage.keys.all { val s = slots?.get(it) ?: JSPropertySlot(); !s.configurable && (s.isAccessor || !s.writable) }
|
|
401
433
|
|
|
402
434
|
override fun jsAccessorKind(key: String): String? {
|
|
403
|
-
val slot = slots
|
|
435
|
+
val slot = slots?.get(key) ?: return null
|
|
404
436
|
if (!slot.isAccessor) return null
|
|
405
437
|
return if (slot.get != null && slot.set != null) "Getter/Setter" else if (slot.get != null) "Getter" else "Setter"
|
|
406
438
|
}
|
|
407
439
|
|
|
408
440
|
/** `Object.getOwnPropertyNames(object)`: string keys, enumerable or not. */
|
|
409
|
-
val ownPropertyNames: List<String>
|
|
441
|
+
val ownPropertyNames: List<String>
|
|
442
|
+
get() {
|
|
443
|
+
val idx = indexKeys
|
|
444
|
+
if (idx == null && !hasSymbols) return namedKeys
|
|
445
|
+
val names = if (hasSymbols) namedKeys.filter { !jsIsSymbolKey(it) } else namedKeys
|
|
446
|
+
return if (idx == null || idx.isEmpty()) names else idx.map { it.toString() } + names
|
|
447
|
+
}
|
|
410
448
|
|
|
411
449
|
private fun define(key: String, value: Any?) {
|
|
412
450
|
if (storage.containsKey(key)) { storage[key] = value; return }
|
|
413
451
|
storage[key] = value
|
|
414
452
|
val index = jsArrayIndex(key)
|
|
415
453
|
if (index != null) {
|
|
454
|
+
val idx = indexKeys ?: ArrayList<Long>(4).also { indexKeys = it }
|
|
416
455
|
var low = 0
|
|
417
|
-
var high =
|
|
456
|
+
var high = idx.size
|
|
418
457
|
while (low < high) {
|
|
419
458
|
val mid = (low + high) / 2
|
|
420
|
-
if (
|
|
459
|
+
if (idx[mid] < index) low = mid + 1 else high = mid
|
|
421
460
|
}
|
|
422
|
-
|
|
423
|
-
} else
|
|
461
|
+
idx.add(low, index)
|
|
462
|
+
} else {
|
|
463
|
+
if (jsIsSymbolKey(key)) hasSymbols = true
|
|
464
|
+
namedKeys.add(key)
|
|
465
|
+
}
|
|
424
466
|
}
|
|
425
467
|
|
|
426
468
|
/** `key in object` for own keys. */
|
|
@@ -431,12 +473,12 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
431
473
|
|
|
432
474
|
/** `delete object[key]`. */
|
|
433
475
|
fun delete(key: String): Boolean {
|
|
434
|
-
slots
|
|
435
|
-
slots
|
|
476
|
+
slots?.get(key)?.let { if (!it.configurable) return false }
|
|
477
|
+
slots?.remove(key)
|
|
436
478
|
if (!storage.containsKey(key)) return true
|
|
437
479
|
storage.remove(key)
|
|
438
480
|
val index = jsArrayIndex(key)
|
|
439
|
-
if (index != null) indexKeys
|
|
481
|
+
if (index != null) indexKeys?.remove(index) else namedKeys.remove(key)
|
|
440
482
|
jsTracker?.trigger()
|
|
441
483
|
return true
|
|
442
484
|
}
|
|
@@ -444,14 +486,18 @@ class JSObject() : JSDynamic, JSSymbolKeyed, JSAccessorKeyed, JSReactiveConverti
|
|
|
444
486
|
val keys: List<String>
|
|
445
487
|
get() {
|
|
446
488
|
jsTracker?.track()
|
|
447
|
-
val
|
|
448
|
-
|
|
489
|
+
val idx = indexKeys
|
|
490
|
+
val s = slots
|
|
491
|
+
if ((idx == null || idx.isEmpty()) && !hasSymbols && (s == null || s.isEmpty())) return namedKeys
|
|
492
|
+
val names = if (hasSymbols) namedKeys.filter { !jsIsSymbolKey(it) } else namedKeys
|
|
493
|
+
val all = if (idx == null || idx.isEmpty()) names else idx.map { it.toString() } + names
|
|
494
|
+
return if (s == null || s.isEmpty()) all else all.filter { s[it]?.enumerable ?: true }
|
|
449
495
|
}
|
|
450
496
|
|
|
451
497
|
override val jsSymbolKeys: List<String>
|
|
452
498
|
get() {
|
|
453
499
|
jsTracker?.track()
|
|
454
|
-
return namedKeys.filter { jsIsSymbolKey(it) }
|
|
500
|
+
return if (!hasSymbols) emptyList() else namedKeys.filter { jsIsSymbolKey(it) }
|
|
455
501
|
}
|
|
456
502
|
|
|
457
503
|
override fun jsGet(key: String): Any? = this[key]
|
|
@@ -542,6 +588,69 @@ fun jsSet(target: Any?, key: String, value: Any?) {
|
|
|
542
588
|
}
|
|
543
589
|
}
|
|
544
590
|
|
|
591
|
+
internal val JS_EMPTY_ARGS: Array<Any?> = emptyArray()
|
|
592
|
+
|
|
593
|
+
/** Zero-vararg exact-arity fast paths for `jsCall` (0–3 arguments), avoiding `Object[]` allocation per call. */
|
|
594
|
+
@Suppress("UNCHECKED_CAST")
|
|
595
|
+
fun jsCall(function: Any?): Any? {
|
|
596
|
+
val result = when (function) {
|
|
597
|
+
is Function0<*> -> (function as () -> Any?)()
|
|
598
|
+
is Function1<*, *> -> (function as (Any?) -> Any?)(null)
|
|
599
|
+
is Function2<*, *, *> -> (function as (Any?, Any?) -> Any?)(null, null)
|
|
600
|
+
is Function3<*, *, *, *> -> (function as (Any?, Any?, Any?) -> Any?)(null, null, null)
|
|
601
|
+
is JSFunction -> function.body(emptyList())
|
|
602
|
+
is JSMethod -> function.call(null, JS_EMPTY_ARGS)
|
|
603
|
+
is JavaMethodRef -> function.call(emptyList())
|
|
604
|
+
else -> return jsCall(function, *JS_EMPTY_ARGS)
|
|
605
|
+
}
|
|
606
|
+
return jsBox(result)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
@Suppress("UNCHECKED_CAST")
|
|
610
|
+
fun jsCall(function: Any?, a0: Any?): Any? {
|
|
611
|
+
val result = when (function) {
|
|
612
|
+
is Function0<*> -> (function as () -> Any?)()
|
|
613
|
+
is Function1<*, *> -> (function as (Any?) -> Any?)(a0)
|
|
614
|
+
is Function2<*, *, *> -> (function as (Any?, Any?) -> Any?)(a0, null)
|
|
615
|
+
is Function3<*, *, *, *> -> (function as (Any?, Any?, Any?) -> Any?)(a0, null, null)
|
|
616
|
+
is JSFunction -> function.body(listOf(a0))
|
|
617
|
+
is JSMethod -> function.call(null, arrayOf(a0))
|
|
618
|
+
is JavaMethodRef -> function.call(listOf(a0))
|
|
619
|
+
else -> return jsCall(function, *arrayOf(a0))
|
|
620
|
+
}
|
|
621
|
+
return jsBox(result)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
@Suppress("UNCHECKED_CAST")
|
|
625
|
+
fun jsCall(function: Any?, a0: Any?, a1: Any?): Any? {
|
|
626
|
+
val result = when (function) {
|
|
627
|
+
is Function0<*> -> (function as () -> Any?)()
|
|
628
|
+
is Function1<*, *> -> (function as (Any?) -> Any?)(a0)
|
|
629
|
+
is Function2<*, *, *> -> (function as (Any?, Any?) -> Any?)(a0, a1)
|
|
630
|
+
is Function3<*, *, *, *> -> (function as (Any?, Any?, Any?) -> Any?)(a0, a1, null)
|
|
631
|
+
is JSFunction -> function.body(listOf(a0, a1))
|
|
632
|
+
is JSMethod -> function.call(null, arrayOf(a0, a1))
|
|
633
|
+
is JavaMethodRef -> function.call(listOf(a0, a1))
|
|
634
|
+
else -> return jsCall(function, *arrayOf(a0, a1))
|
|
635
|
+
}
|
|
636
|
+
return jsBox(result)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
@Suppress("UNCHECKED_CAST")
|
|
640
|
+
fun jsCall(function: Any?, a0: Any?, a1: Any?, a2: Any?): Any? {
|
|
641
|
+
val result = when (function) {
|
|
642
|
+
is Function0<*> -> (function as () -> Any?)()
|
|
643
|
+
is Function1<*, *> -> (function as (Any?) -> Any?)(a0)
|
|
644
|
+
is Function2<*, *, *> -> (function as (Any?, Any?) -> Any?)(a0, a1)
|
|
645
|
+
is Function3<*, *, *, *> -> (function as (Any?, Any?, Any?) -> Any?)(a0, a1, a2)
|
|
646
|
+
is JSFunction -> function.body(listOf(a0, a1, a2))
|
|
647
|
+
is JSMethod -> function.call(null, arrayOf(a0, a1, a2))
|
|
648
|
+
is JavaMethodRef -> function.call(listOf(a0, a1, a2))
|
|
649
|
+
else -> return jsCall(function, *arrayOf(a0, a1, a2))
|
|
650
|
+
}
|
|
651
|
+
return jsBox(result)
|
|
652
|
+
}
|
|
653
|
+
|
|
545
654
|
/** Calls a function stored in a dynamic value with JavaScript's argument rules. Anything else throws a TypeError. */
|
|
546
655
|
@Suppress("UNCHECKED_CAST")
|
|
547
656
|
fun jsCall(function: Any?, vararg args: Any?): Any? {
|
|
@@ -86,7 +86,7 @@ open class Builder: JSDynamic, JSExpando, JSStaticKeyed {
|
|
|
86
86
|
}()))
|
|
87
87
|
}
|
|
88
88
|
#sourceLocation(file:"@nativescript/core/ui.builder.index.ts",line:101)
|
|
89
|
-
return (componentView
|
|
89
|
+
return try jsCast(componentView, View.self)
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
#sourceLocation(file:"@nativescript/core/ui.builder.index.ts",line:105)
|
|
@@ -5680,40 +5680,44 @@ public struct FunctionCell_UIViewControllerOpt_to_any_UIViewControllerAnimatedTr
|
|
|
5680
5680
|
}
|
|
5681
5681
|
|
|
5682
5682
|
public struct
|
|
5683
|
-
|
|
5683
|
+
FunctionCell_any_UIViewControllerAnimatedTransitioning_Opt_to_any_UIViewControllerInteractiveTransitioning_Opt
|
|
5684
5684
|
{
|
|
5685
|
-
public let f:
|
|
5685
|
+
public let f:
|
|
5686
|
+
((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5686
5687
|
public static func implicit(
|
|
5687
5688
|
_ value: (
|
|
5688
|
-
(any UIViewControllerAnimatedTransitioning?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5689
|
+
((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5689
5690
|
)?
|
|
5690
|
-
) -> ((any UIViewControllerAnimatedTransitioning?) throws -> (any UIViewControllerInteractiveTransitioning)?)? {
|
|
5691
|
+
) -> (((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?)? {
|
|
5691
5692
|
value
|
|
5692
5693
|
}
|
|
5693
5694
|
public static func present(
|
|
5694
5695
|
_ value: (
|
|
5695
|
-
(any UIViewControllerAnimatedTransitioning?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5696
|
+
((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5696
5697
|
)?
|
|
5697
|
-
) throws -> (any UIViewControllerAnimatedTransitioning?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5698
|
+
) throws -> ((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5699
|
+
{
|
|
5698
5700
|
guard let value else { throw jsNoObject() }
|
|
5699
5701
|
return value
|
|
5700
5702
|
}
|
|
5701
5703
|
public static func script(
|
|
5702
5704
|
_ name: String, _ length: Int,
|
|
5703
5705
|
_ __f:
|
|
5704
|
-
@escaping (any UIViewControllerAnimatedTransitioning?) throws -> (
|
|
5706
|
+
@escaping ((any UIViewControllerAnimatedTransitioning)?) throws -> (
|
|
5705
5707
|
any UIViewControllerInteractiveTransitioning
|
|
5706
5708
|
)?
|
|
5707
5709
|
) -> JSFunctionObject {
|
|
5708
5710
|
jsBoxedFunction(Self(f: __f)) {
|
|
5709
5711
|
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
5710
|
-
return try __f((jsArg(__a, 0) as? any UIViewControllerAnimatedTransitioning))
|
|
5712
|
+
return try __f((jsArg(__a, 0) as? (any UIViewControllerAnimatedTransitioning)))
|
|
5711
5713
|
}
|
|
5712
5714
|
}
|
|
5713
5715
|
}
|
|
5714
5716
|
public static func scriptOrNil(
|
|
5715
5717
|
_ name: String, _ length: Int,
|
|
5716
|
-
_ __f: (
|
|
5718
|
+
_ __f: (
|
|
5719
|
+
((any UIViewControllerAnimatedTransitioning)?) throws -> (any UIViewControllerInteractiveTransitioning)?
|
|
5720
|
+
)?
|
|
5717
5721
|
) -> JSFunctionObject? { if let __f { return script(name, length, __f) } else { return nil } }
|
|
5718
5722
|
}
|
|
5719
5723
|
|
|
@@ -6333,7 +6337,7 @@ public struct FunctionCell_ListViewBaseOpt_to_Void {
|
|
|
6333
6337
|
{
|
|
6334
6338
|
jsBoxedFunction(Self(f: __f)) {
|
|
6335
6339
|
jsFunction(name, length) { (__a: [Any?]) throws -> Any? in
|
|
6336
|
-
try __f(
|
|
6340
|
+
try __f((try jsCast(jsArg(__a, 0), ListViewBase.self)))
|
|
6337
6341
|
return nil
|
|
6338
6342
|
}
|
|
6339
6343
|
}
|