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

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 (90) hide show
  1. package/dist/driver/compile.js +4 -3
  2. package/dist/kotlin/arguments.js +2 -1
  3. package/dist/kotlin/builtins.js +14 -3
  4. package/dist/kotlin/class-accessors.js +1 -1
  5. package/dist/kotlin/class-constructor.js +3 -1
  6. package/dist/kotlin/class-declaration.js +3 -2
  7. package/dist/kotlin/class-methods.js +29 -12
  8. package/dist/kotlin/components.js +39 -14
  9. package/dist/kotlin/construction.js +4 -5
  10. package/dist/kotlin/conversion.js +16 -3
  11. package/dist/kotlin/core-api.js +14 -7
  12. package/dist/kotlin/declarations.js +1 -1
  13. package/dist/kotlin/expressions.js +10 -5
  14. package/dist/kotlin/modules.js +7 -3
  15. package/dist/kotlin/names.js +5 -2
  16. package/dist/kotlin/optional-chains.js +24 -5
  17. package/dist/kotlin/overrides.js +7 -2
  18. package/dist/kotlin/placement.js +5 -4
  19. package/dist/kotlin/translator.js +0 -39
  20. package/dist/kotlin/types.js +4 -5
  21. package/dist/kotlin/untyped-values.js +7 -1
  22. package/dist/program/program.js +3 -3
  23. package/dist/semantics/apis/array.js +11 -0
  24. package/dist/semantics/classes.js +24 -0
  25. package/dist/semantics/config.js +2 -0
  26. package/dist/semantics/forms/by-name.js +45 -19
  27. package/dist/semantics/globals.js +8 -2
  28. package/dist/semantics/lang.js +21 -1
  29. package/dist/semantics/ledger.js +0 -24
  30. package/dist/semantics/platform-globals.js +0 -16
  31. package/dist/semantics/refusals.js +1 -1
  32. package/dist/semantics/runtime.js +2 -0
  33. package/dist/semantics/throws.js +7 -0
  34. package/dist/semantics/worker-state.js +41 -1
  35. package/dist/swift/assignment.js +3 -0
  36. package/dist/swift/builtins.js +8 -10
  37. package/dist/swift/class-accessors.js +1 -1
  38. package/dist/swift/class-declaration.js +3 -2
  39. package/dist/swift/class-methods.js +19 -2
  40. package/dist/swift/construction.js +5 -1
  41. package/dist/swift/conversion.js +1 -1
  42. package/dist/swift/expressions.js +2 -4
  43. package/dist/swift/from-any.js +5 -0
  44. package/dist/swift/global-calls.js +8 -1
  45. package/dist/swift/object-classes.js +2 -1
  46. package/dist/swift/placement.js +6 -0
  47. package/dist/swift/protocols.js +30 -20
  48. package/dist/swift/types.js +4 -3
  49. package/dist/targets/ios/build.js +22 -7
  50. package/docs/cli/compile-ios.md +1 -1
  51. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_properties_index.kt +6 -6
  52. package/kit-android/generated/kotlin/org/nativescript/kit/ui_core_view_view_common.kt +1 -1
  53. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Collections.kt +15 -6
  54. package/kit-android/src/main/kotlin/org/nativescript/kit/runtime/Promise.kt +1 -1
  55. package/kit-apple/Overlays/xml-free/Core/ui.core.bindable.index.swift +13 -2
  56. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity1.swift +0 -12
  57. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity2.swift +0 -39
  58. package/kit-apple/Sources/NativeScriptKit/Core/FunctionCells.Arity3Plus.swift +0 -44
  59. package/kit-apple/Sources/NativeScriptKit/Core/application.application-common.swift +19 -2
  60. package/kit-apple/Sources/NativeScriptKit/Core/color.color-common.swift +17 -0
  61. package/kit-apple/Sources/NativeScriptKit/Core/color.index.ios.swift +60 -0
  62. package/kit-apple/Sources/NativeScriptKit/Core/kit-index.json +90 -25
  63. package/kit-apple/Sources/NativeScriptKit/Core/text.text-common.swift +9 -1
  64. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.bindable.index.swift +13 -2
  65. package/kit-apple/Sources/NativeScriptKit/Core/ui.core.view-base.index.swift +26 -2
  66. package/kit-apple/Sources/NativeScriptKit/Core/ui.gestures.gestures-common.swift +2 -0
  67. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.liquid-glass-container.index.ios.swift +12 -2
  68. package/kit-apple/Sources/NativeScriptKit/Core/ui.layouts.root-layout.root-layout-common.swift +46 -6
  69. package/kit-apple/Sources/NativeScriptKit/Core/ui.list-view.index.ios.swift +37 -3
  70. package/kit-apple/Sources/NativeScriptKit/Core/ui.split-view.split-view-common.swift +12 -1
  71. package/kit-apple/Sources/NativeScriptKit/Core/ui.styling.css-selector.swift +50 -6
  72. package/kit-apple/Sources/NativeScriptKit/Core/ui.text-base.text-base-common.swift +13 -1
  73. package/kit-apple/Sources/NativeScriptKit/Runtime/Collections.swift +5 -1
  74. package/kit-apple/Sources/NativeScriptKit/Runtime/Dynamic.swift +13 -2
  75. package/kit-apple/Sources/NativeScriptKit/Runtime/Errors.swift +10 -2
  76. package/kit-apple/Sources/NativeScriptKit/Runtime/Functions.swift +57 -12
  77. package/kit-apple/Sources/NativeScriptKit/Runtime/Lowering.swift +12 -3
  78. package/kit-apple/Sources/NativeScriptKit/Runtime/Promise.swift +56 -29
  79. package/kit-apple/Sources/NativeScriptKit/Runtime/Realm.swift +92 -0
  80. package/kit-apple/Sources/NativeScriptKit/Runtime/Record.swift +25 -5
  81. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExp.swift +13 -4
  82. package/kit-apple/Sources/NativeScriptKit/Runtime/RegExpEngine.swift +14 -5
  83. package/kit-apple/Sources/NativeScriptKit/Runtime/Symbol.swift +28 -6
  84. package/kit-apple/Sources/NativeScriptKit/Runtime/Threads.swift +2 -2
  85. package/kit-apple/Sources/NativeScriptKit/Runtime/Timers.swift +93 -47
  86. package/kit-apple/Sources/NativeScriptKit/Runtime/TypedArrays.swift +37 -9
  87. package/kit-apple/Sources/NativeScriptKit/Runtime/Values.swift +6 -4
  88. package/kit-apple/Sources/NativeScriptKit/Runtime/Views.swift +11 -2
  89. package/kit-apple/Sources/NativeScriptKit/Runtime/Workers.swift +680 -0
  90. package/package.json +1 -1
@@ -2325,7 +2325,19 @@ open class ViewBase: Observable, JSStringConvertible {
2325
2325
  }
2326
2326
  case 4:
2327
2327
  switch key {
2328
- case "bind": return FunctionCell_AnyOpt_AnyOpt_to_Void.script("bind", 1, self.bind)
2328
+ case "bind":
2329
+ return { (__f: @escaping (Any?, Any?) throws -> Void) -> JSFunctionObject in
2330
+ jsBoxedFunction(FunctionCell_AnyOpt_AnyOpt_to_Void(f: __f)) {
2331
+ jsFunction("bind", 1) { (__a: [Any?]) throws -> Any? in
2332
+ if __a.count <= 1 {
2333
+ try self.bind(jsArg(__a, 0))
2334
+ return nil
2335
+ }
2336
+ try __f(jsArg(__a, 0), jsArg(__a, 1))
2337
+ return nil
2338
+ }
2339
+ }
2340
+ }(self.bind)
2329
2341
  default: break
2330
2342
  }
2331
2343
  case 6:
@@ -2437,7 +2449,19 @@ open class ViewBase: Observable, JSStringConvertible {
2437
2449
  case "effectiveLeft": return self.effectiveLeft
2438
2450
  case "ensureDomNode": return FunctionCell_none_to_Void.script("ensureDomNode", 0, self.ensureDomNode)
2439
2451
  case "_layoutParent": return FunctionCell_none_to_Void.script("_layoutParent", 0, self._layoutParent)
2440
- case "performLayout": return FunctionCell_Double_to_Void.script("performLayout", 0, self.performLayout)
2452
+ case "performLayout":
2453
+ return { (__f: @escaping (Double) throws -> Void) -> JSFunctionObject in
2454
+ jsBoxedFunction(FunctionCell_Double_to_Void(f: __f)) {
2455
+ jsFunction("performLayout", 0) { (__a: [Any?]) throws -> Any? in
2456
+ if __a.count <= 0 {
2457
+ try self.performLayout()
2458
+ return nil
2459
+ }
2460
+ try __f((try jsConvertedNumber(jsArg(__a, 0))))
2461
+ return nil
2462
+ }
2463
+ }
2464
+ }(self.performLayout)
2441
2465
  case "requestLayout": return FunctionCell_none_to_Void.script("requestLayout", 0, self.requestLayout)
2442
2466
  case "setNativeView": return FunctionCell_AnyOpt_to_Void.script("setNativeView", 1, self.setNativeView)
2443
2467
  case "_dialogClosed": return FunctionCell_none_to_Void.script("_dialogClosed", 0, self._dialogClosed)
@@ -99,11 +99,13 @@ open class GesturesObserverBase: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed
99
99
  case 7:
100
100
  switch key {
101
101
  case "_target": return self._target
102
+ case "context": return self.context
102
103
  default: break
103
104
  }
104
105
  case 8:
105
106
  switch key {
106
107
  case "_context": return self._context
108
+ case "callback": return FunctionCell_AnyOpt_to_Void.scriptOrNil("", 1, self.callback)
107
109
  default: break
108
110
  }
109
111
  case 9:
@@ -335,8 +335,18 @@ open class LiquidGlassContainer: LiquidGlassContainerCommon {
335
335
  case 28:
336
336
  switch key {
337
337
  case "_normalizeChildrenTransforms":
338
- return FunctionCell_Bool_to_Void.script(
339
- "_normalizeChildrenTransforms", 0, self._normalizeChildrenTransforms)
338
+ return { (__f: @escaping (Bool) throws -> Void) -> JSFunctionObject in
339
+ jsBoxedFunction(FunctionCell_Bool_to_Void(f: __f)) {
340
+ jsFunction("_normalizeChildrenTransforms", 0) { (__a: [Any?]) throws -> Any? in
341
+ if __a.count <= 0 {
342
+ try self._normalizeChildrenTransforms()
343
+ return nil
344
+ }
345
+ try __f((try jsConvertedBool(jsArg(__a, 0))))
346
+ return nil
347
+ }
348
+ }
349
+ }(self._normalizeChildrenTransforms)
340
350
  default: break
341
351
  }
342
352
  default: break
@@ -788,7 +788,15 @@ open class RootLayoutBase: GridLayout {
788
788
  switch key.utf8.count {
789
789
  case 4:
790
790
  switch key {
791
- case "open": return FunctionCell_ViewOpt_AnyOpt_to_JSPromise_Void_Opt.script("open", 1, self.`open`)
791
+ case "open":
792
+ return { (__f: @escaping (View?, Any?) throws -> JSPromise<Void>?) -> JSFunctionObject in
793
+ jsBoxedFunction(FunctionCell_ViewOpt_AnyOpt_to_JSPromise_Void_Opt(f: __f)) {
794
+ jsFunction("open", 1) { (__a: [Any?]) throws -> Any? in
795
+ if __a.count <= 1 { return try self.`open`((try jsCast(jsArg(__a, 0), View.self))) }
796
+ return try __f((try jsCast(jsArg(__a, 0), View.self)), jsArg(__a, 1))
797
+ }
798
+ }
799
+ }(self.`open`)
792
800
  default: break
793
801
  }
794
802
  case 5:
@@ -820,7 +828,17 @@ open class RootLayoutBase: GridLayout {
820
828
  case 12:
821
829
  switch key {
822
830
  case "bringToFront":
823
- return FunctionCell_ViewOpt_Bool_to_JSPromise_Void_Opt.script("bringToFront", 1, self.bringToFront)
831
+ return { (__f: @escaping (View?, Bool) throws -> JSPromise<Void>?) -> JSFunctionObject in
832
+ jsBoxedFunction(FunctionCell_ViewOpt_Bool_to_JSPromise_Void_Opt(f: __f)) {
833
+ jsFunction("bringToFront", 1) { (__a: [Any?]) throws -> Any? in
834
+ if __a.count <= 1 {
835
+ return try self.bringToFront((try jsCast(jsArg(__a, 0), View.self)))
836
+ }
837
+ return try __f(
838
+ (try jsCast(jsArg(__a, 0), View.self)), (try jsConvertedBool(jsArg(__a, 1))))
839
+ }
840
+ }
841
+ }(self.bringToFront)
824
842
  default: break
825
843
  }
826
844
  case 13:
@@ -835,13 +853,27 @@ open class RootLayoutBase: GridLayout {
835
853
  switch key {
836
854
  case "initNativeView": return FunctionCell_none_to_Void.script("initNativeView", 0, self.initNativeView)
837
855
  case "openShadeCover":
838
- return FunctionCell_AnyOpt_to_JSPromise_Void_Opt.script("openShadeCover", 0, self.openShadeCover)
856
+ return { (__f: @escaping (Any?) throws -> JSPromise<Void>?) -> JSFunctionObject in
857
+ jsBoxedFunction(FunctionCell_AnyOpt_to_JSPromise_Void_Opt(f: __f)) {
858
+ jsFunction("openShadeCover", 0) { (__a: [Any?]) throws -> Any? in
859
+ if __a.count <= 0 { return try self.openShadeCover() }
860
+ return try __f(jsArg(__a, 0))
861
+ }
862
+ }
863
+ }(self.openShadeCover)
839
864
  default: break
840
865
  }
841
866
  case 15:
842
867
  switch key {
843
868
  case "closeShadeCover":
844
- return FunctionCell_AnyOpt_to_JSPromise_Void_Opt.script("closeShadeCover", 0, self.closeShadeCover)
869
+ return { (__f: @escaping (Any?) throws -> JSPromise<Void>?) -> JSFunctionObject in
870
+ jsBoxedFunction(FunctionCell_AnyOpt_to_JSPromise_Void_Opt(f: __f)) {
871
+ jsFunction("closeShadeCover", 0) { (__a: [Any?]) throws -> Any? in
872
+ if __a.count <= 0 { return try self.closeShadeCover() }
873
+ return try __f(jsArg(__a, 0))
874
+ }
875
+ }
876
+ }(self.closeShadeCover)
845
877
  case "_initShadeCover":
846
878
  return FunctionCell_ViewOpt_AnyOpt_to_Void.script("_initShadeCover", 2, self._initShadeCover)
847
879
  default: break
@@ -856,8 +888,16 @@ open class RootLayoutBase: GridLayout {
856
888
  case "createShadeCover":
857
889
  return FunctionCell_none_to_ViewOpt.script("createShadeCover", 0, self.createShadeCover)
858
890
  case "updateShadeCover":
859
- return FunctionCell_ViewOpt_AnyOpt_to_JSPromise_Void_Opt.script(
860
- "updateShadeCover", 1, self.updateShadeCover)
891
+ return { (__f: @escaping (View?, Any?) throws -> JSPromise<Void>?) -> JSFunctionObject in
892
+ jsBoxedFunction(FunctionCell_ViewOpt_AnyOpt_to_JSPromise_Void_Opt(f: __f)) {
893
+ jsFunction("updateShadeCover", 1) { (__a: [Any?]) throws -> Any? in
894
+ if __a.count <= 1 {
895
+ return try self.updateShadeCover((try jsCast(jsArg(__a, 0), View.self)))
896
+ }
897
+ return try __f((try jsCast(jsArg(__a, 0), View.self)), jsArg(__a, 1))
898
+ }
899
+ }
900
+ }(self.updateShadeCover)
861
901
  case "_closeShadeCover":
862
902
  return FunctionCell_ViewOpt_AnyOpt_to_JSPromise_Void_Opt.script(
863
903
  "_closeShadeCover", 2, self._closeShadeCover)
@@ -2276,9 +2276,32 @@ open class ListView: ListViewBase {
2276
2276
  case "_delegate":
2277
2277
  if !(jsMadeBits2 & (1 << 9) != 0) { return nil }
2278
2278
  return self._delegate
2279
- case "getHeight": return FunctionCell_Double_Double_to_Double.script("getHeight", 1, self.getHeight)
2279
+ case "getHeight":
2280
+ return { (__f: @escaping (Double, Double) throws -> Double) -> JSFunctionObject in
2281
+ jsBoxedFunction(FunctionCell_Double_Double_to_Double(f: __f)) {
2282
+ jsFunction("getHeight", 1) { (__a: [Any?]) throws -> Any? in
2283
+ if __a.count <= 1 { return try self.getHeight((try jsConvertedNumber(jsArg(__a, 0)))) }
2284
+ return try __f(
2285
+ (try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedNumber(jsArg(__a, 1))))
2286
+ }
2287
+ }
2288
+ }(self.getHeight)
2280
2289
  case "setHeight":
2281
- return FunctionCell_Double_Double_Double_to_Void.script("setHeight", 2, self.setHeight)
2290
+ return { (__f: @escaping (Double, Double, Double) throws -> Void) -> JSFunctionObject in
2291
+ jsBoxedFunction(FunctionCell_Double_Double_Double_to_Void(f: __f)) {
2292
+ jsFunction("setHeight", 2) { (__a: [Any?]) throws -> Any? in
2293
+ if __a.count <= 2 {
2294
+ try self.setHeight(
2295
+ (try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedNumber(jsArg(__a, 1))))
2296
+ return nil
2297
+ }
2298
+ try __f(
2299
+ (try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedNumber(jsArg(__a, 1))),
2300
+ (try jsConvertedNumber(jsArg(__a, 2))))
2301
+ return nil
2302
+ }
2303
+ }
2304
+ }(self.setHeight)
2282
2305
  case "onMeasure": return FunctionCell_Double_Double_to_Void.script("onMeasure", 2, self.onMeasure)
2283
2306
  default: break
2284
2307
  }
@@ -2325,7 +2348,18 @@ open class ListView: ListViewBase {
2325
2348
  return self._preparingCell
2326
2349
  case "initNativeView": return FunctionCell_none_to_Void.script("initNativeView", 0, self.initNativeView)
2327
2350
  case "_scrollToIndex":
2328
- return FunctionCell_Double_Bool_to_Void.script("_scrollToIndex", 1, self._scrollToIndex)
2351
+ return { (__f: @escaping (Double, Bool) throws -> Void) -> JSFunctionObject in
2352
+ jsBoxedFunction(FunctionCell_Double_Bool_to_Void(f: __f)) {
2353
+ jsFunction("_scrollToIndex", 1) { (__a: [Any?]) throws -> Any? in
2354
+ if __a.count <= 1 {
2355
+ try self._scrollToIndex((try jsConvertedNumber(jsArg(__a, 0))))
2356
+ return nil
2357
+ }
2358
+ try __f((try jsConvertedNumber(jsArg(__a, 0))), (try jsConvertedBool(jsArg(__a, 1))))
2359
+ return nil
2360
+ }
2361
+ }
2362
+ }(self._scrollToIndex)
2329
2363
  case "_prepareHeader":
2330
2364
  return FunctionCell_ListViewHeaderCellOpt_Double_to_DoubleOpt.script(
2331
2365
  "_prepareHeader", 2, self._prepareHeader)
@@ -203,7 +203,18 @@ open class SplitViewBase: LayoutBase {
203
203
  case 22:
204
204
  switch key {
205
205
  case "invalidateChildLayouts":
206
- return FunctionCell_Double_to_Void.script("invalidateChildLayouts", 0, self.invalidateChildLayouts)
206
+ return { (__f: @escaping (Double) throws -> Void) -> JSFunctionObject in
207
+ jsBoxedFunction(FunctionCell_Double_to_Void(f: __f)) {
208
+ jsFunction("invalidateChildLayouts", 0) { (__a: [Any?]) throws -> Any? in
209
+ if __a.count <= 0 {
210
+ try self.invalidateChildLayouts()
211
+ return nil
212
+ }
213
+ try __f((try jsConvertedNumber(jsArg(__a, 0))))
214
+ return nil
215
+ }
216
+ }
217
+ }(self.invalidateChildLayouts)
207
218
  default: break
208
219
  }
209
220
  default: break
@@ -2814,8 +2814,22 @@ open class SelectorScope: JSDynamic, JSExpando, JSKeysMade, JSStaticKeyed {
2814
2814
  case 21:
2815
2815
  switch key {
2816
2816
  case "getSelectorCandidates":
2817
- return FunctionCell_AnyOpt_JSArray_SelectorCore_Opt_to_JSArray_SelectorCore_Opt.script(
2818
- "getSelectorCandidates", 1, self.getSelectorCandidates)
2817
+ return {
2818
+ (__f: @escaping (Any?, JSArray<SelectorCore>?) throws -> JSArray<SelectorCore>?)
2819
+ -> JSFunctionObject in
2820
+ jsBoxedFunction(
2821
+ FunctionCell_AnyOpt_JSArray_SelectorCore_Opt_to_JSArray_SelectorCore_Opt(f: __f)
2822
+ ) {
2823
+ jsFunction("getSelectorCandidates", 1) { (__a: [Any?]) throws -> Any? in
2824
+ if __a.count <= 1 { return try self.getSelectorCandidates(jsArg(__a, 0)) }
2825
+ return try __f(
2826
+ jsArg(__a, 0),
2827
+ try jsArrayOrNil(
2828
+ jsArg(__a, 1), as: JSArray<SelectorCore>.self,
2829
+ { try (jsCastPresent($0) as SelectorCore) }))
2830
+ }
2831
+ }
2832
+ }(self.getSelectorCandidates)
2819
2833
  default: break
2820
2834
  }
2821
2835
  case 29:
@@ -3122,15 +3136,45 @@ open class StyleSheetSelectorScope: SelectorScope {
3122
3136
  return FunctionCell_JSArray_RuleSet_Opt_Double_to_Void.script(
3123
3137
  "appendRulesets", 2, self.appendRulesets)
3124
3138
  case "lookupRulesets":
3125
- return FunctionCell_JSArray_RuleSet_Opt_Double_to_Void.script(
3126
- "lookupRulesets", 1, self.lookupRulesets)
3139
+ return { (__f: @escaping (JSArray<RuleSet>?, Double) throws -> Void) -> JSFunctionObject in
3140
+ jsBoxedFunction(FunctionCell_JSArray_RuleSet_Opt_Double_to_Void(f: __f)) {
3141
+ jsFunction("lookupRulesets", 1) { (__a: [Any?]) throws -> Any? in
3142
+ if __a.count <= 1 {
3143
+ try self.lookupRulesets(
3144
+ try jsArrayOrNil(
3145
+ jsArg(__a, 0), as: JSArray<RuleSet>.self,
3146
+ { try (jsCastPresent($0) as RuleSet) }))
3147
+ return nil
3148
+ }
3149
+ try __f(
3150
+ try jsArrayOrNil(
3151
+ jsArg(__a, 0), as: JSArray<RuleSet>.self, { try (jsCastPresent($0) as RuleSet) }
3152
+ ), (try jsConvertedNumber(jsArg(__a, 1))))
3153
+ return nil
3154
+ }
3155
+ }
3156
+ }(self.lookupRulesets)
3127
3157
  default: break
3128
3158
  }
3129
3159
  case 17:
3130
3160
  switch key {
3131
3161
  case "collectCandidates":
3132
- return FunctionCell_AnyOpt_JSArray_SelectorCore_Opt_to_JSArray_SelectorCore_Opt.script(
3133
- "collectCandidates", 1, self.collectCandidates)
3162
+ return {
3163
+ (__f: @escaping (Any?, JSArray<SelectorCore>?) throws -> JSArray<SelectorCore>?)
3164
+ -> JSFunctionObject in
3165
+ jsBoxedFunction(
3166
+ FunctionCell_AnyOpt_JSArray_SelectorCore_Opt_to_JSArray_SelectorCore_Opt(f: __f)
3167
+ ) {
3168
+ jsFunction("collectCandidates", 1) { (__a: [Any?]) throws -> Any? in
3169
+ if __a.count <= 1 { return try self.collectCandidates(jsArg(__a, 0)) }
3170
+ return try __f(
3171
+ jsArg(__a, 0),
3172
+ try jsArrayOrNil(
3173
+ jsArg(__a, 1), as: JSArray<SelectorCore>.self,
3174
+ { try (jsCastPresent($0) as SelectorCore) }))
3175
+ }
3176
+ }
3177
+ }(self.collectCandidates)
3134
3178
  default: break
3135
3179
  }
3136
3180
  case 24:
@@ -473,7 +473,19 @@ open class TextBaseCommon: View {
473
473
  }
474
474
  case 14:
475
475
  switch key {
476
- case "_setNativeText": return FunctionCell_Bool_to_Void.script("_setNativeText", 0, self._setNativeText)
476
+ case "_setNativeText":
477
+ return { (__f: @escaping (Bool) throws -> Void) -> JSFunctionObject in
478
+ jsBoxedFunction(FunctionCell_Bool_to_Void(f: __f)) {
479
+ jsFunction("_setNativeText", 0) { (__a: [Any?]) throws -> Any? in
480
+ if __a.count <= 0 {
481
+ try self._setNativeText()
482
+ return nil
483
+ }
484
+ try __f((try jsConvertedBool(jsArg(__a, 0))))
485
+ return nil
486
+ }
487
+ }
488
+ }(self._setNativeText)
477
489
  default: break
478
490
  }
479
491
  case 20:
@@ -38,6 +38,7 @@ enum JSCollectionKey: Equatable {
38
38
  case unique(Int)
39
39
 
40
40
  private static var uniqueCounter = 0
41
+ private static let uniqueLock = JSUnfairLock()
41
42
 
42
43
  @inlinable static func number(_ d: Double) -> JSCollectionKey {
43
44
  .number(d.isNaN ? Double.nan.bitPattern : (d == 0 ? 0 : d.bitPattern))
@@ -63,8 +64,11 @@ enum JSCollectionKey: Equatable {
63
64
  case let v?:
64
65
  if let n = jsNumeric(v) { return number(n) }
65
66
  if jsIsObject(v) { return .object(ObjectIdentifier(jsIdentity(v)! as AnyObject)) }
67
+ uniqueLock.lock()
66
68
  uniqueCounter += 1
67
- return .unique(uniqueCounter)
69
+ let id = uniqueCounter
70
+ uniqueLock.unlock()
71
+ return .unique(id)
68
72
  }
69
73
  }
70
74
 
@@ -319,6 +319,7 @@ public func jsOwnPropertyNames(_ value: Any?) -> JSArray<String> {
319
319
  }
320
320
 
321
321
  private var jsRestricted: [ObjectIdentifier: JSRestriction] = [:]
322
+ private let jsRestrictedLock = JSUnfairLock()
322
323
 
323
324
  /// How far `Object.preventExtensions`, `seal` or `freeze` closed an object other than a plain one.
324
325
  private final class JSRestriction {
@@ -330,6 +331,8 @@ private final class JSRestriction {
330
331
 
331
332
  /// 0: open; 1: not extensible; 2: sealed; 3: frozen.
332
333
  func jsRestriction(_ object: AnyObject) -> Int {
334
+ jsRestrictedLock.lock()
335
+ defer { jsRestrictedLock.unlock() }
333
336
  guard !jsRestricted.isEmpty, let r = jsRestricted[ObjectIdentifier(object)], r.object === object else { return 0 }
334
337
  return r.level
335
338
  }
@@ -339,7 +342,10 @@ private func jsRestrict(object v: Any?, level: Int) {
339
342
  case let o as JSObject: o.restrict(sealed: level >= 2, frozen: level >= 3)
340
343
  case let v? where jsIsObject(v) && !(v is JSNull):
341
344
  let object = v as AnyObject
342
- jsRestricted[ObjectIdentifier(object)] = JSRestriction(object, max(level, jsRestriction(object)))
345
+ jsRestrictedLock.lock()
346
+ let current = (jsRestricted[ObjectIdentifier(object)].flatMap { $0.object === object ? $0.level : nil }) ?? 0
347
+ jsRestricted[ObjectIdentifier(object)] = JSRestriction(object, max(level, current))
348
+ jsRestrictedLock.unlock()
343
349
  default: break
344
350
  }
345
351
  }
@@ -454,15 +460,20 @@ public func jsIn(_ key: String, _ object: Any?) -> Bool {
454
460
  /// A tagged template's strings array; translated code makes one per call site.
455
461
  public func jsTemplateObject(_ cooked: [String], raw: [String]) -> JSArray<String> {
456
462
  let strings = JSArray(cooked)
463
+ jsTemplateRawsLock.lock()
457
464
  jsTemplateRaws[ObjectIdentifier(strings)] = JSArray(raw)
465
+ jsTemplateRawsLock.unlock()
458
466
  return strings
459
467
  }
460
468
 
461
469
  /// `strings.raw`.
462
470
  public func jsTemplateRaw(_ strings: JSArray<String>) -> JSArray<String> {
463
- jsTemplateRaws[ObjectIdentifier(strings)] ?? strings
471
+ jsTemplateRawsLock.lock()
472
+ defer { jsTemplateRawsLock.unlock() }
473
+ return jsTemplateRaws[ObjectIdentifier(strings)] ?? strings
464
474
  }
465
475
  private var jsTemplateRaws: [ObjectIdentifier: JSArray<String>] = [:]
476
+ private let jsTemplateRawsLock = JSUnfairLock()
466
477
 
467
478
  /// The key order of an object literal with spreads (`{ ...a, b: 1 }`): each spread source's keys as it holds
468
479
  /// them, then the literal's own, a key keeping its first position; integer keys first; only the `fields` it has.
@@ -6,7 +6,12 @@ public struct JSException: Error, @unchecked Sendable, CustomStringConvertible {
6
6
  public let value: Any?
7
7
  public init(_ value: Any?) { self.value = value }
8
8
  public init(value: Any?) { self.value = value }
9
- public var description: String { MainActor.assumeIsolated { "Uncaught " + jsToString(value) } }
9
+ public var description: String {
10
+ if pthread_main_np() != 0 {
11
+ return MainActor.assumeIsolated { "Uncaught " + jsToString(value) }
12
+ }
13
+ return jsRunInWorker { "Uncaught " + jsToString(self.value) }
14
+ }
10
15
  }
11
16
 
12
17
  /// JavaScript `Error`. TypeScript classes extending `Error` subclass it and set `name` in their initializer.
@@ -297,7 +302,10 @@ public final class JSThrownValue: JSError {
297
302
  }
298
303
 
299
304
  /// A dynamic write (`obj[key] = v`, a binding's set) a typed field refused, or a defined field's setter threw: what `jsSet` throws after the write.
300
- var jsRefusedWrite: JSException?
305
+ var jsRefusedWrite: JSException? {
306
+ get { JSRealm.current().refusedWrite }
307
+ set { JSRealm.current().refusedWrite = newValue }
308
+ }
301
309
 
302
310
  /// A dynamic write whose value converting throws (an array holding undefined where its elements are objects): refused, the TypeError `jsSet` throws.
303
311
  public func jsStoring(_ body: () throws -> Void) {
@@ -60,7 +60,11 @@ public final class JSFunctionObject: JSDynamic, CustomStringConvertible {
60
60
  if let own { return own }
61
61
  let made = JSObject()
62
62
  own = made
63
- if let identityKey { JSFunctionIdentity.table[identityKey]?.kept = self }
63
+ if let identityKey {
64
+ JSFunctionIdentity.lock.lock()
65
+ JSFunctionIdentity.table[identityKey]?.kept = self
66
+ JSFunctionIdentity.lock.unlock()
67
+ }
64
68
  return made
65
69
  }
66
70
 
@@ -221,15 +225,18 @@ enum JSFunctionIdentity {
221
225
  }
222
226
  }
223
227
 
228
+ static let lock = JSUnfairLock()
224
229
  static var table: [JSFunctionKey: Slot] = [:]
225
230
 
226
231
  static func forget(_ key: JSFunctionKey) {
232
+ lock.lock()
227
233
  if let slot = table[key], slot.alias == nil, slot.box == nil { table[key] = nil }
234
+ lock.unlock()
228
235
  }
229
236
 
230
237
  /// The function a closure key stands for: an object (a function object, or a class's method), or
231
- /// the key itself for a closure made from nothing else.
232
- static func root(_ key: JSFunctionKey) -> Root {
238
+ /// the key itself for a closure made from nothing else. Caller must hold `lock`.
239
+ static func rootLocked(_ key: JSFunctionKey) -> Root {
233
240
  var k = key
234
241
  while let slot = table[k] {
235
242
  if let alias = slot.alias {
@@ -244,20 +251,38 @@ enum JSFunctionIdentity {
244
251
  }
245
252
  return .key(k)
246
253
  }
254
+
255
+ static func root(_ key: JSFunctionKey) -> Root {
256
+ lock.lock()
257
+ defer { lock.unlock() }
258
+ return rootLocked(key)
259
+ }
247
260
  }
248
261
 
249
262
  /// A typed closure given to script untyped: one function object per function, so that the same
250
263
  /// closure boxed twice (or a closure made from a function object) is the same value to `===`.
251
264
  public func jsBoxedFunction<Cell>(_ cell: Cell, _ make: () -> JSFunctionObject) -> JSFunctionObject {
252
265
  let key = jsFunctionKey(cell)
253
- if let box = JSFunctionIdentity.table[key]?.box { return box }
254
- let root = JSFunctionIdentity.root(key)
266
+ JSFunctionIdentity.lock.lock()
267
+ if let box = JSFunctionIdentity.table[key]?.box {
268
+ JSFunctionIdentity.lock.unlock()
269
+ return box
270
+ }
271
+ let root = JSFunctionIdentity.rootLocked(key)
255
272
  if case .object(let o) = root {
256
- if let box = o as? JSFunctionObject { return box }
257
- if let box = (o as? JSFunctionDeclaration)?.box { return box }
273
+ if let box = o as? JSFunctionObject {
274
+ JSFunctionIdentity.lock.unlock()
275
+ return box
276
+ }
277
+ if let box = (o as? JSFunctionDeclaration)?.box {
278
+ JSFunctionIdentity.lock.unlock()
279
+ return box
280
+ }
258
281
  }
282
+ JSFunctionIdentity.lock.unlock()
259
283
  let box = make()
260
284
  // Kept under the key the closure stands for (an adapter's, the function it adapts), which the box keeps alive through it.
285
+ JSFunctionIdentity.lock.lock()
261
286
  let at: JSFunctionKey
262
287
  switch root {
263
288
  case .key(let k): at = k
@@ -265,6 +290,7 @@ public func jsBoxedFunction<Cell>(_ cell: Cell, _ make: () -> JSFunctionObject)
265
290
  }
266
291
  box.identityKey = at
267
292
  JSFunctionIdentity.table[at, default: .init()].box = box
293
+ JSFunctionIdentity.lock.unlock()
268
294
  return box
269
295
  }
270
296
 
@@ -274,7 +300,9 @@ public func jsIdentified<Cell>(_ cell: Cell, _ alias: JSFunctionAlias) -> Cell {
274
300
  if case .none = alias.target { return cell }
275
301
  let key = jsFunctionKey(cell)
276
302
  alias.key = key
303
+ JSFunctionIdentity.lock.lock()
277
304
  JSFunctionIdentity.table[key] = .init(alias: alias)
305
+ JSFunctionIdentity.lock.unlock()
278
306
  return cell
279
307
  }
280
308
 
@@ -291,12 +319,18 @@ public final class JSFunctionDeclaration {
291
319
  /// A module's or namespace's function declaration as a value: the first closure read of it, kept for
292
320
  /// good as the function itself is, so that every read is the same closure. `id` names the declaration.
293
321
  public func jsDeclaredFunction<Cell>(_ id: String, _ cell: Cell) -> Cell {
294
- if let found = JSDeclaredFunctions.table[id] as? Cell { return found }
322
+ JSDeclaredFunctions.lock.lock()
323
+ if let found = JSDeclaredFunctions.table[id] as? Cell {
324
+ JSDeclaredFunctions.lock.unlock()
325
+ return found
326
+ }
295
327
  JSDeclaredFunctions.table[id] = cell
328
+ JSDeclaredFunctions.lock.unlock()
296
329
  return cell
297
330
  }
298
331
 
299
332
  enum JSDeclaredFunctions {
333
+ static let lock = JSUnfairLock()
300
334
  static var table: [String: Any] = [:]
301
335
  }
302
336
 
@@ -313,7 +347,12 @@ public func jsSameFunction<A, B>(_ a: A?, _ b: B?) -> Bool {
313
347
  /// storing it on the receiver or in this cache keeps nothing alive. `make` captures the alias it is given.
314
348
  public func jsMethodValue<Receiver: AnyObject, Cell>(_ receiver: Receiver, _ name: String, _ make: (Receiver, JSFunctionAlias) -> Cell) -> Cell {
315
349
  let key = JSMethodValues.Key(receiver: ObjectIdentifier(receiver), name: name, cell: ObjectIdentifier(Cell.self))
316
- if let entry = JSMethodValues.table[key], entry.receiver === receiver, let cell = entry.cell as? Cell { return cell }
350
+ JSMethodValues.lock.lock()
351
+ if let entry = JSMethodValues.table[key], entry.receiver === receiver, let cell = entry.cell as? Cell {
352
+ JSMethodValues.lock.unlock()
353
+ return cell
354
+ }
355
+ JSMethodValues.lock.unlock()
317
356
  let alias = JSFunctionAlias(method: JSMethodValues.identity(type(of: receiver), name))
318
357
  let cell = jsIdentified(make(receiver, alias), alias)
319
358
  JSMethodValues.store(key, .init(receiver: receiver, cell: cell))
@@ -344,6 +383,7 @@ enum JSMethodValues {
344
383
  weak var receiver: AnyObject?
345
384
  let cell: Any
346
385
  }
386
+ static let lock = JSUnfairLock()
347
387
  static var table: [Key: Entry] = [:]
348
388
  private static var pruneAt = 64
349
389
 
@@ -357,6 +397,8 @@ enum JSMethodValues {
357
397
 
358
398
  static func identity(_ type: AnyClass, _ name: String) -> Identity {
359
399
  let key = IdentityKey(type: ObjectIdentifier(type), name: name)
400
+ lock.lock()
401
+ defer { lock.unlock() }
360
402
  if let found = identities[key] { return found }
361
403
  let made = Identity()
362
404
  identities[key] = made
@@ -364,9 +406,12 @@ enum JSMethodValues {
364
406
  }
365
407
 
366
408
  static func store(_ key: Key, _ entry: Entry) {
409
+ lock.lock()
367
410
  table[key] = entry
368
- guard table.count >= pruneAt else { return }
369
- table = table.filter { $0.value.receiver != nil }
370
- pruneAt = max(64, table.count * 2)
411
+ if table.count >= pruneAt {
412
+ table = table.filter { $0.value.receiver != nil }
413
+ pruneAt = max(64, table.count * 2)
414
+ }
415
+ lock.unlock()
371
416
  }
372
417
  }
@@ -50,7 +50,13 @@ func jsReportedToScript(_ value: Any?) -> Bool {
50
50
  return true
51
51
  }
52
52
 
53
- public func jsReportUncaught(_ value: Any?) { jsUncaughtHandler(value) }
53
+ public func jsReportUncaught(_ value: Any?) {
54
+ if let handler = JSRealm.current().uncaught {
55
+ handler(value)
56
+ return
57
+ }
58
+ jsUncaughtHandler(value)
59
+ }
54
60
 
55
61
  /// A framework's own handling of what no script code caught, which hears it before the app's (`UncaughtErrors`): true
56
62
  /// when it took it.
@@ -452,11 +458,14 @@ public func jsIsSafeInteger(_ x: Double) -> Bool { jsIsInteger(x) && abs(x) <= 9
452
458
  /// `n.toString(radix)`; nil radix is 10.
453
459
  public func jsNumberToString(_ x: Double, radix: Double?) throws -> String { try radix.map { try jsNumberToRadixString(x, $0) } ?? jsNumberToString(x) }
454
460
 
455
- /// An untyped value read as a dictionary-typed object: a record already, or a record of an object's keys.
461
+ /// An untyped value read as a dictionary-typed object: a record already, or a record of an object's keys
462
+ /// (keeping a class instance's dynamic lookup as a fallback for methods and getters).
456
463
  public func jsRecordOf<T>(_ value: Any?, _ element: (Any?) throws -> T) rethrows -> JSRecord<T> {
457
464
  if let record = jsFlat(value) as? JSRecord<T> { return record }
458
465
  guard let object = jsFlat(value) as? JSDynamic else { return JSRecord<T>() }
459
- return JSRecord(try object.jsKeys.map { ($0, try element(object[jsKey: $0])) })
466
+ let record = JSRecord(try object.jsKeys.map { ($0, try element(object[jsKey: $0])) })
467
+ if !(object is JSObject) { record.backing = object }
468
+ return record
460
469
  }
461
470
 
462
471
  /// The RegExp match, matchAll and search make of a pattern that is not one.