@nstudio/nativescript-compiler 9.2.0-alpha.16 → 9.2.0-alpha.17

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.
Files changed (60) hide show
  1. package/dist/kit/kit-index.js +9 -0
  2. package/dist/kotlin/access.js +7 -9
  3. package/dist/kotlin/arguments.js +2 -2
  4. package/dist/kotlin/class-declaration.js +20 -0
  5. package/dist/kotlin/components.js +2 -7
  6. package/dist/kotlin/core-api.js +2 -21
  7. package/dist/kotlin/declarations.js +86 -9
  8. package/dist/kotlin/functions.js +1 -4
  9. package/dist/kotlin/global-calls.js +1 -4
  10. package/dist/kotlin/literals.js +3 -6
  11. package/dist/kotlin/names.js +2 -0
  12. package/dist/kotlin/native/classfiles.js +2 -13
  13. package/dist/kotlin/operators.js +12 -6
  14. package/dist/kotlin/optional-chains.js +2 -9
  15. package/dist/kotlin/overrides.js +3 -15
  16. package/dist/kotlin/placement.js +1 -12
  17. package/dist/kotlin/statements.js +1 -13
  18. package/dist/kotlin/translator.js +2 -10
  19. package/dist/kotlin/type-tests.js +1 -1
  20. package/dist/kotlin/types.js +2 -19
  21. package/dist/program/core-facts.js +9 -0
  22. package/dist/semantics/facts.js +37 -1
  23. package/dist/semantics/lang.js +19 -0
  24. package/dist/semantics/lower.js +90 -0
  25. package/dist/semantics/lowering-methods.js +115 -3
  26. package/dist/semantics/marks.js +30 -0
  27. package/dist/semantics/refusals.js +12 -11
  28. package/dist/semantics/tdz.js +103 -8
  29. package/dist/swift/access.js +6 -8
  30. package/dist/swift/assignment.js +10 -2
  31. package/dist/swift/calls.js +7 -2
  32. package/dist/swift/classes.js +23 -9
  33. package/dist/swift/components.js +0 -4
  34. package/dist/swift/core-api.js +9 -29
  35. package/dist/swift/declarations.js +0 -5
  36. package/dist/swift/expression-statements.js +7 -0
  37. package/dist/swift/global-calls.js +0 -4
  38. package/dist/swift/lenient.js +3 -5
  39. package/dist/swift/method-values.js +1 -19
  40. package/dist/swift/modules.js +2 -0
  41. package/dist/swift/names.js +0 -9
  42. package/dist/swift/native/api.js +3 -1
  43. package/dist/swift/native/dispatch.js +2 -8
  44. package/dist/swift/operators.js +7 -6
  45. package/dist/swift/optional-chains.js +1 -8
  46. package/dist/swift/parameters.js +0 -4
  47. package/dist/swift/placement.js +1 -12
  48. package/dist/swift/results.js +0 -4
  49. package/dist/swift/statements.js +1 -13
  50. package/dist/swift/translator.js +0 -10
  51. package/dist/types/adapter-api.d.ts +3 -3
  52. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Array.kt +53 -12
  53. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/JSON.kt +30 -4
  54. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Language.kt +33 -0
  55. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Prototypes.kt +9 -1
  56. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Values.kt +137 -28
  57. package/kit-apple/Sources/NativeScriptKit/Core/js-libs.easysax.easysax.swift +24 -6
  58. package/kit-apple/Sources/NativeScriptKit/Runtime/JSON.swift +151 -82
  59. package/kit-apple/Sources/NativeScriptKit/Runtime/Prototypes.swift +13 -1
  60. package/package.json +1 -1
@@ -69,11 +69,15 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
69
69
  return read(i.toInt())
70
70
  }
71
71
 
72
- operator fun get(i: Int): T {
73
- track()
74
- return read(i)
72
+ private fun readTracked(i: Int): T {
73
+ jsTracker!!.track()
74
+ val v = storage[i]
75
+ jsReactiveAny(v)
76
+ return v
75
77
  }
76
78
 
79
+ operator fun get(i: Int): T = if (jsTracker == null) storage[i] else readTracked(i)
80
+
77
81
  operator fun get(i: Double): T = get(i.toInt())
78
82
 
79
83
  /** Indices a write past the end skipped (`a[1] = x` of an empty array): holes, which `for…in` and `Object.keys` leave out. */
@@ -424,60 +428,92 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
424
428
  }
425
429
 
426
430
  fun forEach(f: (T) -> Unit) {
431
+ val list = storage
427
432
  val n = size
428
433
  var i = 0
429
- while (i < n && i < storage.size) { f(read(i)); i++ }
434
+ if (jsTracker == null) {
435
+ while (i < n && i < list.size) { f(list[i]); i++ }
436
+ } else {
437
+ while (i < n && i < list.size) { f(read(i)); i++ }
438
+ }
430
439
  }
431
440
 
432
441
  fun forEach(f: (T, Double) -> Unit) {
442
+ val list = storage
433
443
  val n = size
434
444
  var i = 0
435
- while (i < n && i < storage.size) { f(read(i), i.toDouble()); i++ }
445
+ if (jsTracker == null) {
446
+ while (i < n && i < list.size) { f(list[i], i.toDouble()); i++ }
447
+ } else {
448
+ while (i < n && i < list.size) { f(read(i), i.toDouble()); i++ }
449
+ }
436
450
  }
437
451
 
438
452
  fun forEach(f: (T, Double, JSArray<T>) -> Unit) {
453
+ val list = storage
439
454
  val n = size
440
455
  var i = 0
441
- while (i < n && i < storage.size) { f(read(i), i.toDouble(), this); i++ }
456
+ while (i < n && i < list.size) { f(read(i), i.toDouble(), this); i++ }
442
457
  }
443
458
 
444
459
  fun <U> map(f: (T) -> U): JSArray<U> {
460
+ val list = storage
445
461
  val n = size
446
462
  val out = ArrayList<U>(n)
447
463
  var i = 0
448
- while (i < n && i < storage.size) { out.add(f(read(i))); i++ }
464
+ if (jsTracker == null) {
465
+ while (i < n && i < list.size) { out.add(f(list[i])); i++ }
466
+ } else {
467
+ while (i < n && i < list.size) { out.add(f(read(i))); i++ }
468
+ }
449
469
  return JSArray(out)
450
470
  }
451
471
 
452
472
  fun <U> map(f: (T, Double) -> U): JSArray<U> {
473
+ val list = storage
453
474
  val n = size
454
475
  val out = ArrayList<U>(n)
455
476
  var i = 0
456
- while (i < n && i < storage.size) { out.add(f(read(i), i.toDouble())); i++ }
477
+ if (jsTracker == null) {
478
+ while (i < n && i < list.size) { out.add(f(list[i], i.toDouble())); i++ }
479
+ } else {
480
+ while (i < n && i < list.size) { out.add(f(read(i), i.toDouble())); i++ }
481
+ }
457
482
  return JSArray(out)
458
483
  }
459
484
 
460
485
  fun <U> map(f: (T, Double, JSArray<T>) -> U): JSArray<U> {
486
+ val list = storage
461
487
  val n = size
462
488
  val out = ArrayList<U>(n)
463
489
  var i = 0
464
- while (i < n && i < storage.size) { out.add(f(read(i), i.toDouble(), this)); i++ }
490
+ while (i < n && i < list.size) { out.add(f(read(i), i.toDouble(), this)); i++ }
465
491
  return JSArray(out)
466
492
  }
467
493
 
468
494
  fun filter(f: (T) -> Boolean): JSArray<T> {
495
+ val list = storage
469
496
  val n = size
470
497
  val out = ArrayList<T>()
471
498
  var i = 0
472
- while (i < n && i < storage.size) { val v = read(i); if (f(v)) out.add(v); i++ }
499
+ if (jsTracker == null) {
500
+ while (i < n && i < list.size) { val v = list[i]; if (f(v)) out.add(v); i++ }
501
+ } else {
502
+ while (i < n && i < list.size) { val v = read(i); if (f(v)) out.add(v); i++ }
503
+ }
473
504
  return JSArray(out)
474
505
  }
475
506
 
476
507
  fun filter(f: (T, Double) -> Boolean): JSArray<T> {
508
+ val list = storage
477
509
  val n = size
478
510
  val out = ArrayList<T>()
479
511
  var i = 0
480
- while (i < n && i < storage.size) { val v = read(i); if (f(v, i.toDouble())) out.add(v); i++ }
512
+ if (jsTracker == null) {
513
+ while (i < n && i < list.size) { val v = list[i]; if (f(v, i.toDouble())) out.add(v); i++ }
514
+ } else {
515
+ while (i < n && i < list.size) { val v = read(i); if (f(v, i.toDouble())) out.add(v); i++ }
516
+ }
481
517
  return JSArray(out)
482
518
  }
483
519
 
@@ -507,9 +543,14 @@ open class JSArray<T>(storage: ArrayList<T>) : Iterable<T>, JSReactiveConvertibl
507
543
 
508
544
  fun <U> reduce(f: (U, T) -> U, initial: U): U {
509
545
  var acc = initial
546
+ val list = storage
510
547
  val n = size
511
548
  var i = 0
512
- while (i < n && i < storage.size) { acc = f(acc, read(i)); i++ }
549
+ if (jsTracker == null) {
550
+ while (i < n && i < list.size) { acc = f(acc, list[i]); i++ }
551
+ } else {
552
+ while (i < n && i < list.size) { acc = f(acc, read(i)); i++ }
553
+ }
513
554
  return acc
514
555
  }
515
556
 
@@ -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[top.key] = value
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 JSToJSON) v = jsBox(v.jsToJSON(key ?: index.toString()))
386
- else if (v is JSDynamic && v !is JSError) {
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
  }
@@ -415,6 +419,7 @@ private class JSONWriter(val gap: String?) {
415
419
  is Pair<*, *> -> array(v, key ?: index.toString(), listOf(v.first, v.second), depth)
416
420
  is Triple<*, *, *> -> array(v, key ?: index.toString(), listOf(v.first, v.second, v.third), depth)
417
421
  is JSRegExp -> out.append("{}")
422
+ is JSObject -> if (v.isPlainFast && allowed == null && replacer == null) plainObj(v, key ?: index.toString(), depth) else obj(v, key ?: index.toString(), depth)
418
423
  is JSDynamic -> obj(v, key ?: index.toString(), depth)
419
424
  else -> out.append("{}")
420
425
  }
@@ -497,6 +502,27 @@ private class JSONWriter(val gap: String?) {
497
502
  leave()
498
503
  }
499
504
 
505
+ /** Fast path for a plain JSObject with no replacer, filter, slots, prototype, or reactive tracker. */
506
+ private fun plainObj(owner: JSObject, key: String, depth: Int) {
507
+ enter(key, owner)
508
+ val keys = owner.namedKeys
509
+ val map = owner.storage
510
+ out.append('{')
511
+ var written = false
512
+ for (i in 0 until keys.size) {
513
+ val k = keys[i]
514
+ val mark = out.length
515
+ if (written) out.append(',')
516
+ newline(depth + 1)
517
+ appendJSONQuoted(out, k)
518
+ out.append(if (gap == null) ":" else ": ")
519
+ if (property(owner, k, -1, map[k], depth + 1)) written = true else out.setLength(mark)
520
+ }
521
+ if (written) newline(depth)
522
+ out.append('}')
523
+ leave()
524
+ }
525
+
500
526
  /** SerializeJSONObject: the keys as they are on entry, each value read as it is written. */
501
527
  private fun obj(owner: JSDynamic, key: String, depth: Int) {
502
528
  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.builtin("Function")
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")
@@ -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
- private val storage = HashMap<String, Any?>()
262
- private val indexKeys = ArrayList<Long>()
263
- private val namedKeys = ArrayList<String>()
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 val slots = HashMap<String, JSPropertySlot>()
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
- if (slots.isNotEmpty()) slots[key]?.get?.let { return it(this) }
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
- if (slots.isNotEmpty()) slots[key]?.let { if (it.isAccessor) return it.get?.invoke(receiver) }
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[key]?.takeIf { it.isAccessor }?.set
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[key]
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[key] ?: JSPropertySlot(enumerable = exists, writable = exists, configurable = exists)
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.remove(key) else slots[key] = slot
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[key] ?: JSPropertySlot()
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
- for (key in indexKeys.map { it.toString() } + namedKeys) {
392
- val slot = slots[key] ?: JSPropertySlot()
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
- slots[key] = slot
427
+ s[key] = slot
396
428
  }
397
429
  }
398
430
 
399
- val isSealed: Boolean get() = !extensible && storage.keys.all { !(slots[it] ?: JSPropertySlot()).configurable }
400
- val isFrozen: Boolean get() = !extensible && storage.keys.all { val s = slots[it] ?: JSPropertySlot(); !s.configurable && (s.isAccessor || !s.writable) }
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[key] ?: return null
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> get() = indexKeys.map { it.toString() } + namedKeys.filter { !jsIsSymbolKey(it) }
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 = indexKeys.size
456
+ var high = idx.size
418
457
  while (low < high) {
419
458
  val mid = (low + high) / 2
420
- if (indexKeys[mid] < index) low = mid + 1 else high = mid
459
+ if (idx[mid] < index) low = mid + 1 else high = mid
421
460
  }
422
- indexKeys.add(low, index)
423
- } else namedKeys.add(key)
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[key]?.let { if (!it.configurable) return false }
435
- slots.remove(key)
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.remove(index) else namedKeys.remove(key)
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 all = indexKeys.map { it.toString() } + namedKeys.filter { !jsIsSymbolKey(it) }
448
- return if (slots.isEmpty()) all else all.filter { slots[it]?.enumerable ?: true }
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? {
@@ -710,8 +710,15 @@ open class EasySAXParser: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
710
710
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:541)
711
711
  if self.is_onComment && !stop {
712
712
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:542)
713
- ok = try jsCallee(
714
- FunctionCell_String_AnyOpt_to_String_Opt_to_AnyOpt_Opt_to_AnyOpt.present(self.onComment))(
713
+ ok = try
714
+ ({ () throws -> (String, ((Any?) throws -> String)?, (() throws -> Any?)?) throws -> Any in
715
+ guard
716
+ let __fn =
717
+ try FunctionCell_String_AnyOpt_to_String_Opt_to_AnyOpt_Opt_to_AnyOpt.present(
718
+ self.onComment)
719
+ else { throw JSException(JSTypeError("this.onComment is not a function")) }
720
+ return __fn
721
+ }())(
715
722
  jsSubstring(xml, i + 4, j),
716
723
  FunctionCell_AnyOpt_to_String.declared(
717
724
  "Core_js_libs_easysax_easysax.unEntities",
@@ -739,8 +746,14 @@ open class EasySAXParser: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
739
746
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:556)
740
747
  if self.is_onAttention && !stop {
741
748
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:557)
742
- ok = try jsCallee(
743
- FunctionCell_String_AnyOpt_to_String_Opt_to_AnyOpt_Opt_to_AnyOpt.present(self.onAttention))(
749
+ ok = try
750
+ ({ () throws -> (String, ((Any?) throws -> String)?, (() throws -> Any?)?) throws -> Any in
751
+ guard
752
+ let __fn = try FunctionCell_String_AnyOpt_to_String_Opt_to_AnyOpt_Opt_to_AnyOpt.present(
753
+ self.onAttention)
754
+ else { throw JSException(JSTypeError("this.onAttention is not a function")) }
755
+ return __fn
756
+ }())(
744
757
  jsSubstring(xml, i, j + 1),
745
758
  FunctionCell_AnyOpt_to_String.declared(
746
759
  "Core_js_libs_easysax_easysax.unEntities",
@@ -770,8 +783,13 @@ open class EasySAXParser: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
770
783
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:572)
771
784
  if self.is_onQuestion {
772
785
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:573)
773
- ok = try jsCallee(FunctionCell_String_to_AnyOpt_Opt_to_AnyOpt.present(self.onQuestion))(
774
- jsSubstring(xml, i, j + 2), position(i))
786
+ ok = try
787
+ ({ () throws -> (String, (() throws -> Any?)?) throws -> Any in
788
+ guard
789
+ let __fn = try FunctionCell_String_to_AnyOpt_Opt_to_AnyOpt.present(self.onQuestion)
790
+ else { throw JSException(JSTypeError("this.onQuestion is not a function")) }
791
+ return __fn
792
+ }())(jsSubstring(xml, i, j + 2), position(i))
775
793
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:574)
776
794
  if jsStrictEquals(ok, false) {
777
795
  #sourceLocation(file:"@nativescript/core/js-libs.easysax.easysax.ts",line:574)