@triniwiz/nativescript-masonkit 1.0.0-alpha.12 → 1.0.0-alpha.14

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 (323) hide show
  1. package/common.js.map +1 -1
  2. package/helpers.d.ts +5 -5
  3. package/helpers.js +0 -3
  4. package/helpers.js.map +1 -1
  5. package/index.android.js +2 -2
  6. package/index.android.js.map +1 -1
  7. package/index.ios.js +2 -2
  8. package/index.ios.js.map +1 -1
  9. package/package.json +2 -2
  10. package/platforms/android/masonkit-release.aar +0 -0
  11. package/platforms/ios/Mason.xcframework/ios-arm64/Mason.framework/Mason +0 -0
  12. package/platforms/ios/Mason.xcframework/ios-arm64/Mason.framework/Modules/Mason.swiftmodule/arm64-apple-ios.abi.json +4559 -1456
  13. package/platforms/ios/Mason.xcframework/ios-arm64/dSYMs/Mason.framework.dSYM/Contents/Resources/DWARF/Mason +0 -0
  14. package/platforms/ios/Mason.xcframework/ios-arm64/dSYMs/Mason.framework.dSYM/Contents/Resources/Relocations/aarch64/Mason.yml +1932 -1932
  15. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/Mason.framework/Mason +0 -0
  16. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/Mason.framework/Modules/Mason.swiftmodule/arm64-apple-ios-simulator.abi.json +4559 -1456
  17. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/Mason.framework/Modules/Mason.swiftmodule/x86_64-apple-ios-simulator.abi.json +4559 -1456
  18. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/dSYMs/Mason.framework.dSYM/Contents/Resources/DWARF/Mason +0 -0
  19. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/dSYMs/Mason.framework.dSYM/Contents/Resources/Relocations/aarch64/Mason.yml +1932 -1932
  20. package/platforms/ios/Mason.xcframework/ios-arm64_x86_64-simulator/dSYMs/Mason.framework.dSYM/Contents/Resources/Relocations/x86_64/Mason.yml +1883 -1883
  21. package/style.d.ts +1 -1
  22. package/style.js +0 -1
  23. package/style.js.map +1 -1
  24. package/node.d.ts +0 -2
  25. package/node.js +0 -3
  26. package/node.js.map +0 -1
  27. package/platforms/ios/Podfile +0 -1
  28. package/platforms/ios/build.xcconfig +0 -5
  29. package/platforms/ios/prebuild.sh +0 -101
  30. package/platforms/new_native_src/cpp/Caches.cpp +0 -36
  31. package/platforms/new_native_src/cpp/Caches.h +0 -42
  32. package/platforms/new_native_src/cpp/Common.h +0 -34
  33. package/platforms/new_native_src/cpp/ConcurrentMap.h +0 -57
  34. package/platforms/new_native_src/cpp/Helpers.cpp +0 -101
  35. package/platforms/new_native_src/cpp/Helpers.h +0 -364
  36. package/platforms/new_native_src/cpp/MasonImpl.cpp +0 -68
  37. package/platforms/new_native_src/cpp/MasonImpl.h +0 -40
  38. package/platforms/new_native_src/cpp/MasonNodeImpl.cpp +0 -89
  39. package/platforms/new_native_src/cpp/MasonNodeImpl.h +0 -47
  40. package/platforms/new_native_src/cpp/MasonStyleImpl.cpp +0 -2181
  41. package/platforms/new_native_src/cpp/MasonStyleImpl.h +0 -420
  42. package/platforms/new_native_src/cpp/include/mason_native.h +0 -972
  43. package/platforms/new_native_src/cpp/include/robin_hood.h +0 -2544
  44. package/src-native/pods/Headers/include/APIDesign.md +0 -72
  45. package/src-native/pods/Headers/include/DEPS +0 -10
  46. package/src-native/pods/Headers/include/DIR_METADATA +0 -11
  47. package/src-native/pods/Headers/include/OWNERS +0 -23
  48. package/src-native/pods/Headers/include/cppgc/DEPS +0 -8
  49. package/src-native/pods/Headers/include/cppgc/OWNERS +0 -2
  50. package/src-native/pods/Headers/include/cppgc/README.md +0 -133
  51. package/src-native/pods/Headers/include/cppgc/allocation.h +0 -310
  52. package/src-native/pods/Headers/include/cppgc/common.h +0 -29
  53. package/src-native/pods/Headers/include/cppgc/cross-thread-persistent.h +0 -465
  54. package/src-native/pods/Headers/include/cppgc/custom-space.h +0 -97
  55. package/src-native/pods/Headers/include/cppgc/default-platform.h +0 -67
  56. package/src-native/pods/Headers/include/cppgc/ephemeron-pair.h +0 -30
  57. package/src-native/pods/Headers/include/cppgc/explicit-management.h +0 -100
  58. package/src-native/pods/Headers/include/cppgc/garbage-collected.h +0 -106
  59. package/src-native/pods/Headers/include/cppgc/heap-consistency.h +0 -266
  60. package/src-native/pods/Headers/include/cppgc/heap-state.h +0 -82
  61. package/src-native/pods/Headers/include/cppgc/heap-statistics.h +0 -120
  62. package/src-native/pods/Headers/include/cppgc/heap.h +0 -206
  63. package/src-native/pods/Headers/include/cppgc/internal/api-constants.h +0 -55
  64. package/src-native/pods/Headers/include/cppgc/internal/atomic-entry-flag.h +0 -48
  65. package/src-native/pods/Headers/include/cppgc/internal/caged-heap-local-data.h +0 -79
  66. package/src-native/pods/Headers/include/cppgc/internal/compiler-specific.h +0 -38
  67. package/src-native/pods/Headers/include/cppgc/internal/finalizer-trait.h +0 -93
  68. package/src-native/pods/Headers/include/cppgc/internal/gc-info.h +0 -156
  69. package/src-native/pods/Headers/include/cppgc/internal/logging.h +0 -50
  70. package/src-native/pods/Headers/include/cppgc/internal/name-trait.h +0 -122
  71. package/src-native/pods/Headers/include/cppgc/internal/persistent-node.h +0 -216
  72. package/src-native/pods/Headers/include/cppgc/internal/pointer-policies.h +0 -186
  73. package/src-native/pods/Headers/include/cppgc/internal/write-barrier.h +0 -435
  74. package/src-native/pods/Headers/include/cppgc/liveness-broker.h +0 -77
  75. package/src-native/pods/Headers/include/cppgc/macros.h +0 -26
  76. package/src-native/pods/Headers/include/cppgc/member.h +0 -291
  77. package/src-native/pods/Headers/include/cppgc/name-provider.h +0 -65
  78. package/src-native/pods/Headers/include/cppgc/object-size-trait.h +0 -58
  79. package/src-native/pods/Headers/include/cppgc/persistent.h +0 -370
  80. package/src-native/pods/Headers/include/cppgc/platform.h +0 -156
  81. package/src-native/pods/Headers/include/cppgc/prefinalizer.h +0 -75
  82. package/src-native/pods/Headers/include/cppgc/process-heap-statistics.h +0 -36
  83. package/src-native/pods/Headers/include/cppgc/sentinel-pointer.h +0 -32
  84. package/src-native/pods/Headers/include/cppgc/source-location.h +0 -92
  85. package/src-native/pods/Headers/include/cppgc/testing.h +0 -106
  86. package/src-native/pods/Headers/include/cppgc/trace-trait.h +0 -116
  87. package/src-native/pods/Headers/include/cppgc/type-traits.h +0 -240
  88. package/src-native/pods/Headers/include/cppgc/visitor.h +0 -379
  89. package/src-native/pods/Headers/include/js_protocol-1.2.json +0 -936
  90. package/src-native/pods/Headers/include/js_protocol-1.3.json +0 -1112
  91. package/src-native/pods/Headers/include/js_protocol.pdl +0 -1709
  92. package/src-native/pods/Headers/include/libffi/arm64/ffi.h +0 -524
  93. package/src-native/pods/Headers/include/libffi/arm64/ffitarget.h +0 -92
  94. package/src-native/pods/Headers/include/libffi/x86_64/ffi.h +0 -524
  95. package/src-native/pods/Headers/include/libffi/x86_64/ffitarget.h +0 -147
  96. package/src-native/pods/Headers/include/libffi.h +0 -12
  97. package/src-native/pods/Headers/include/libplatform/DEPS +0 -9
  98. package/src-native/pods/Headers/include/libplatform/libplatform-export.h +0 -29
  99. package/src-native/pods/Headers/include/libplatform/libplatform.h +0 -106
  100. package/src-native/pods/Headers/include/libplatform/v8-tracing.h +0 -333
  101. package/src-native/pods/Headers/include/v8-array-buffer.h +0 -433
  102. package/src-native/pods/Headers/include/v8-callbacks.h +0 -397
  103. package/src-native/pods/Headers/include/v8-container.h +0 -129
  104. package/src-native/pods/Headers/include/v8-context.h +0 -407
  105. package/src-native/pods/Headers/include/v8-cppgc.h +0 -215
  106. package/src-native/pods/Headers/include/v8-data.h +0 -80
  107. package/src-native/pods/Headers/include/v8-date.h +0 -43
  108. package/src-native/pods/Headers/include/v8-debug.h +0 -168
  109. package/src-native/pods/Headers/include/v8-embedder-heap.h +0 -218
  110. package/src-native/pods/Headers/include/v8-embedder-state-scope.h +0 -51
  111. package/src-native/pods/Headers/include/v8-exception.h +0 -217
  112. package/src-native/pods/Headers/include/v8-extension.h +0 -62
  113. package/src-native/pods/Headers/include/v8-external.h +0 -37
  114. package/src-native/pods/Headers/include/v8-fast-api-calls.h +0 -939
  115. package/src-native/pods/Headers/include/v8-forward.h +0 -81
  116. package/src-native/pods/Headers/include/v8-function-callback.h +0 -475
  117. package/src-native/pods/Headers/include/v8-function.h +0 -125
  118. package/src-native/pods/Headers/include/v8-initialization.h +0 -315
  119. package/src-native/pods/Headers/include/v8-inspector-protocol.h +0 -13
  120. package/src-native/pods/Headers/include/v8-inspector.h +0 -376
  121. package/src-native/pods/Headers/include/v8-internal.h +0 -661
  122. package/src-native/pods/Headers/include/v8-isolate.h +0 -1709
  123. package/src-native/pods/Headers/include/v8-json.h +0 -47
  124. package/src-native/pods/Headers/include/v8-local-handle.h +0 -455
  125. package/src-native/pods/Headers/include/v8-locker.h +0 -149
  126. package/src-native/pods/Headers/include/v8-maybe.h +0 -137
  127. package/src-native/pods/Headers/include/v8-memory-span.h +0 -43
  128. package/src-native/pods/Headers/include/v8-message.h +0 -216
  129. package/src-native/pods/Headers/include/v8-metrics.h +0 -255
  130. package/src-native/pods/Headers/include/v8-microtask-queue.h +0 -152
  131. package/src-native/pods/Headers/include/v8-microtask.h +0 -28
  132. package/src-native/pods/Headers/include/v8-object.h +0 -775
  133. package/src-native/pods/Headers/include/v8-persistent-handle.h +0 -590
  134. package/src-native/pods/Headers/include/v8-platform.h +0 -1092
  135. package/src-native/pods/Headers/include/v8-primitive-object.h +0 -118
  136. package/src-native/pods/Headers/include/v8-primitive.h +0 -866
  137. package/src-native/pods/Headers/include/v8-profiler.h +0 -1198
  138. package/src-native/pods/Headers/include/v8-promise.h +0 -174
  139. package/src-native/pods/Headers/include/v8-proxy.h +0 -50
  140. package/src-native/pods/Headers/include/v8-regexp.h +0 -105
  141. package/src-native/pods/Headers/include/v8-script.h +0 -748
  142. package/src-native/pods/Headers/include/v8-snapshot.h +0 -196
  143. package/src-native/pods/Headers/include/v8-statistics.h +0 -217
  144. package/src-native/pods/Headers/include/v8-template.h +0 -1079
  145. package/src-native/pods/Headers/include/v8-traced-handle.h +0 -420
  146. package/src-native/pods/Headers/include/v8-typed-array.h +0 -282
  147. package/src-native/pods/Headers/include/v8-unwinder-state.h +0 -31
  148. package/src-native/pods/Headers/include/v8-unwinder.h +0 -132
  149. package/src-native/pods/Headers/include/v8-util.h +0 -658
  150. package/src-native/pods/Headers/include/v8-value-serializer-version.h +0 -24
  151. package/src-native/pods/Headers/include/v8-value-serializer.h +0 -279
  152. package/src-native/pods/Headers/include/v8-value.h +0 -526
  153. package/src-native/pods/Headers/include/v8-version-string.h +0 -38
  154. package/src-native/pods/Headers/include/v8-version.h +0 -20
  155. package/src-native/pods/Headers/include/v8-wasm-trap-handler-posix.h +0 -31
  156. package/src-native/pods/Headers/include/v8-wasm-trap-handler-win.h +0 -28
  157. package/src-native/pods/Headers/include/v8-wasm.h +0 -257
  158. package/src-native/pods/Headers/include/v8-weak-callback-info.h +0 -86
  159. package/src-native/pods/Headers/include/v8.h +0 -88
  160. package/src-native/pods/Headers/include/v8config.h +0 -605
  161. package/src-native/pods/Headers/inspector/InspectorServer.h +0 -20
  162. package/src-native/pods/Headers/inspector/JsV8InspectorClient.h +0 -66
  163. package/src-native/pods/Headers/inspector/base/trace_event/common/trace_event_common.h +0 -1123
  164. package/src-native/pods/Headers/inspector/base64.h +0 -9
  165. package/src-native/pods/Headers/inspector/src/base/address-region.h +0 -95
  166. package/src-native/pods/Headers/inspector/src/base/atomic-utils.h +0 -219
  167. package/src-native/pods/Headers/inspector/src/base/atomicops.h +0 -332
  168. package/src-native/pods/Headers/inspector/src/base/atomicops_internals_atomicword_compat.h +0 -89
  169. package/src-native/pods/Headers/inspector/src/base/base-export.h +0 -31
  170. package/src-native/pods/Headers/inspector/src/base/bits.h +0 -343
  171. package/src-native/pods/Headers/inspector/src/base/build_config.h +0 -234
  172. package/src-native/pods/Headers/inspector/src/base/compiler-specific.h +0 -136
  173. package/src-native/pods/Headers/inspector/src/base/export-template.h +0 -163
  174. package/src-native/pods/Headers/inspector/src/base/flags.h +0 -130
  175. package/src-native/pods/Headers/inspector/src/base/immediate-crash.h +0 -162
  176. package/src-native/pods/Headers/inspector/src/base/lazy-instance.h +0 -258
  177. package/src-native/pods/Headers/inspector/src/base/logging.h +0 -417
  178. package/src-native/pods/Headers/inspector/src/base/macros.h +0 -423
  179. package/src-native/pods/Headers/inspector/src/base/memory.h +0 -89
  180. package/src-native/pods/Headers/inspector/src/base/once.h +0 -108
  181. package/src-native/pods/Headers/inspector/src/base/optional.h +0 -882
  182. package/src-native/pods/Headers/inspector/src/base/platform/mutex.h +0 -370
  183. package/src-native/pods/Headers/inspector/src/base/platform/platform.h +0 -476
  184. package/src-native/pods/Headers/inspector/src/base/platform/semaphore.h +0 -108
  185. package/src-native/pods/Headers/inspector/src/base/platform/v8-time.h +0 -513
  186. package/src-native/pods/Headers/inspector/src/base/platform/wrappers.h +0 -73
  187. package/src-native/pods/Headers/inspector/src/base/safe_conversions.h +0 -389
  188. package/src-native/pods/Headers/inspector/src/base/safe_conversions_impl.h +0 -822
  189. package/src-native/pods/Headers/inspector/src/base/template-utils.h +0 -113
  190. package/src-native/pods/Headers/inspector/src/base/v8-fallthrough.h +0 -21
  191. package/src-native/pods/Headers/inspector/src/common/checks.h +0 -38
  192. package/src-native/pods/Headers/inspector/src/common/globals.h +0 -1842
  193. package/src-native/pods/Headers/inspector/src/debug/debug-interface.h +0 -667
  194. package/src-native/pods/Headers/inspector/src/debug/interface-types.h +0 -175
  195. package/src-native/pods/Headers/inspector/src/init/v8.h +0 -52
  196. package/src-native/pods/Headers/inspector/src/inspector/custom-preview.h +0 -24
  197. package/src-native/pods/Headers/inspector/src/inspector/injected-script.h +0 -251
  198. package/src-native/pods/Headers/inspector/src/inspector/inspected-context.h +0 -79
  199. package/src-native/pods/Headers/inspector/src/inspector/protocol/CSS.h +0 -2148
  200. package/src-native/pods/Headers/inspector/src/inspector/protocol/Console.h +0 -211
  201. package/src-native/pods/Headers/inspector/src/inspector/protocol/DOM.h +0 -1008
  202. package/src-native/pods/Headers/inspector/src/inspector/protocol/Debugger.h +0 -892
  203. package/src-native/pods/Headers/inspector/src/inspector/protocol/Forward.h +0 -75
  204. package/src-native/pods/Headers/inspector/src/inspector/protocol/HeapProfiler.h +0 -346
  205. package/src-native/pods/Headers/inspector/src/inspector/protocol/Log.h +0 -342
  206. package/src-native/pods/Headers/inspector/src/inspector/protocol/Network.h +0 -2528
  207. package/src-native/pods/Headers/inspector/src/inspector/protocol/Overlay.h +0 -281
  208. package/src-native/pods/Headers/inspector/src/inspector/protocol/Page.h +0 -1189
  209. package/src-native/pods/Headers/inspector/src/inspector/protocol/Profiler.h +0 -1001
  210. package/src-native/pods/Headers/inspector/src/inspector/protocol/Protocol.h +0 -617
  211. package/src-native/pods/Headers/inspector/src/inspector/protocol/Runtime.h +0 -1696
  212. package/src-native/pods/Headers/inspector/src/inspector/protocol/Schema.h +0 -146
  213. package/src-native/pods/Headers/inspector/src/inspector/protocol/Security.h +0 -793
  214. package/src-native/pods/Headers/inspector/src/inspector/remote-object-id.h +0 -54
  215. package/src-native/pods/Headers/inspector/src/inspector/search-util.h +0 -26
  216. package/src-native/pods/Headers/inspector/src/inspector/string-16.h +0 -180
  217. package/src-native/pods/Headers/inspector/src/inspector/string-util.h +0 -128
  218. package/src-native/pods/Headers/inspector/src/inspector/v8-console-agent-impl.h +0 -48
  219. package/src-native/pods/Headers/inspector/src/inspector/v8-console-message.h +0 -147
  220. package/src-native/pods/Headers/inspector/src/inspector/v8-console.h +0 -173
  221. package/src-native/pods/Headers/inspector/src/inspector/v8-css-agent-impl.h +0 -62
  222. package/src-native/pods/Headers/inspector/src/inspector/v8-debugger-agent-impl.h +0 -248
  223. package/src-native/pods/Headers/inspector/src/inspector/v8-debugger-id.h +0 -44
  224. package/src-native/pods/Headers/inspector/src/inspector/v8-debugger-script.h +0 -123
  225. package/src-native/pods/Headers/inspector/src/inspector/v8-debugger.h +0 -257
  226. package/src-native/pods/Headers/inspector/src/inspector/v8-dom-agent-impl.h +0 -91
  227. package/src-native/pods/Headers/inspector/src/inspector/v8-heap-profiler-agent-impl.h +0 -80
  228. package/src-native/pods/Headers/inspector/src/inspector/v8-inspector-impl.h +0 -191
  229. package/src-native/pods/Headers/inspector/src/inspector/v8-inspector-session-impl.h +0 -156
  230. package/src-native/pods/Headers/inspector/src/inspector/v8-log-agent-impl.h +0 -34
  231. package/src-native/pods/Headers/inspector/src/inspector/v8-network-agent-impl.h +0 -71
  232. package/src-native/pods/Headers/inspector/src/inspector/v8-ns-debugger-agent-impl.h +0 -24
  233. package/src-native/pods/Headers/inspector/src/inspector/v8-overlay-agent-impl.h +0 -70
  234. package/src-native/pods/Headers/inspector/src/inspector/v8-page-agent-impl.h +0 -88
  235. package/src-native/pods/Headers/inspector/src/inspector/v8-profiler-agent-impl.h +0 -104
  236. package/src-native/pods/Headers/inspector/src/inspector/v8-regex.h +0 -38
  237. package/src-native/pods/Headers/inspector/src/inspector/v8-runtime-agent-impl.h +0 -157
  238. package/src-native/pods/Headers/inspector/src/inspector/v8-schema-agent-impl.h +0 -38
  239. package/src-native/pods/Headers/inspector/src/inspector/v8-stack-trace-impl.h +0 -164
  240. package/src-native/pods/Headers/inspector/src/inspector/v8-string-conversions.h +0 -17
  241. package/src-native/pods/Headers/inspector/src/inspector/v8-value-utils.h +0 -23
  242. package/src-native/pods/Headers/inspector/src/inspector/value-mirror.h +0 -87
  243. package/src-native/pods/Headers/inspector/src/libplatform/default-platform.h +0 -92
  244. package/src-native/pods/Headers/inspector/src/logging/tracing-flags.h +0 -50
  245. package/src-native/pods/Headers/inspector/src/numbers/conversions.h +0 -183
  246. package/src-native/pods/Headers/inspector/src/tracing/trace-event.h +0 -664
  247. package/src-native/pods/Headers/inspector/src/utils/allocation.h +0 -367
  248. package/src-native/pods/Headers/inspector/src/utils/vector.h +0 -324
  249. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/cbor.h +0 -305
  250. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/dispatch.h +0 -314
  251. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/error_support.h +0 -62
  252. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/export.h +0 -6
  253. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/find_by_first.h +0 -58
  254. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/frontend_channel.h +0 -47
  255. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/glue.h +0 -80
  256. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/json.h +0 -52
  257. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/json_platform.h +0 -26
  258. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/maybe.h +0 -104
  259. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/parser_handler.h +0 -39
  260. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/protocol_core.h +0 -406
  261. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/serializable.h +0 -32
  262. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/serializer_traits.h +0 -158
  263. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/span.h +0 -99
  264. package/src-native/pods/Headers/inspector/third_party/inspector_protocol/crdtp/status.h +0 -139
  265. package/src-native/pods/Headers/inspector/utils.h +0 -32
  266. package/src-native/pods/Headers/inspector/v8-inspector-platform.h +0 -44
  267. package/src-native/pods/Headers/jsi/decorator.h +0 -762
  268. package/src-native/pods/Headers/jsi/instrumentation.h +0 -117
  269. package/src-native/pods/Headers/jsi/jsi-inl.h +0 -322
  270. package/src-native/pods/Headers/jsi/jsi.h +0 -1387
  271. package/src-native/pods/Headers/jsi/jsilib.h +0 -59
  272. package/src-native/pods/Headers/jsi/threadsafe.h +0 -79
  273. package/src-native/pods/Headers/runtime/ArgConverter.h +0 -61
  274. package/src-native/pods/Headers/runtime/ArrayAdapter.h +0 -13
  275. package/src-native/pods/Headers/runtime/Caches.h +0 -98
  276. package/src-native/pods/Headers/runtime/ClassBuilder.h +0 -61
  277. package/src-native/pods/Headers/runtime/Common.h +0 -9
  278. package/src-native/pods/Headers/runtime/ConcurrentMap.h +0 -55
  279. package/src-native/pods/Headers/runtime/ConcurrentQueue.h +0 -28
  280. package/src-native/pods/Headers/runtime/Console.h +0 -27
  281. package/src-native/pods/Headers/runtime/Constants.h +0 -15
  282. package/src-native/pods/Headers/runtime/DataWrapper.h +0 -671
  283. package/src-native/pods/Headers/runtime/DictionaryAdapter.h +0 -13
  284. package/src-native/pods/Headers/runtime/ExtVector.h +0 -21
  285. package/src-native/pods/Headers/runtime/FFICall.h +0 -105
  286. package/src-native/pods/Headers/runtime/FastEnumerationAdapter.h +0 -13
  287. package/src-native/pods/Headers/runtime/FunctionReference.h +0 -18
  288. package/src-native/pods/Headers/runtime/Helpers.h +0 -84
  289. package/src-native/pods/Headers/runtime/InlineFunctions.h +0 -16
  290. package/src-native/pods/Headers/runtime/Interop.h +0 -202
  291. package/src-native/pods/Headers/runtime/KnownUnknownClassPair.h +0 -35
  292. package/src-native/pods/Headers/runtime/Metadata.h +0 -981
  293. package/src-native/pods/Headers/runtime/MetadataBuilder.h +0 -72
  294. package/src-native/pods/Headers/runtime/MetadataInlines.h +0 -157
  295. package/src-native/pods/Headers/runtime/ModuleInternal.h +0 -59
  296. package/src-native/pods/Headers/runtime/NSDataAdapter.h +0 -13
  297. package/src-native/pods/Headers/runtime/NativeScriptException.h +0 -27
  298. package/src-native/pods/Headers/runtime/ObjectManager.h +0 -31
  299. package/src-native/pods/Headers/runtime/OneByteStringResource.h +0 -21
  300. package/src-native/pods/Headers/runtime/Pointer.h +0 -26
  301. package/src-native/pods/Headers/runtime/PromiseProxy.h +0 -15
  302. package/src-native/pods/Headers/runtime/Reference.h +0 -38
  303. package/src-native/pods/Headers/runtime/Runtime.h +0 -67
  304. package/src-native/pods/Headers/runtime/RuntimeConfig.h +0 -17
  305. package/src-native/pods/Headers/runtime/SetTimeout.h +0 -34
  306. package/src-native/pods/Headers/runtime/SimpleAllocator.h +0 -23
  307. package/src-native/pods/Headers/runtime/StringHasher.h +0 -315
  308. package/src-native/pods/Headers/runtime/SymbolIterator.h +0 -18
  309. package/src-native/pods/Headers/runtime/SymbolLoader.h +0 -27
  310. package/src-native/pods/Headers/runtime/TNSDerivedClass.h +0 -8
  311. package/src-native/pods/Headers/runtime/TSHelpers.h +0 -15
  312. package/src-native/pods/Headers/runtime/Tasks.h +0 -19
  313. package/src-native/pods/Headers/runtime/UnmanagedType.h +0 -21
  314. package/src-native/pods/Headers/runtime/WeakRef.h +0 -15
  315. package/src-native/pods/Headers/runtime/Worker.h +0 -26
  316. package/src-native/pods/Headers/runtime/robin_hood.h +0 -2184
  317. package/src-native/pods/Headers/v8runtime/HostProxy.h +0 -71
  318. package/src-native/pods/Headers/v8runtime/JSIV8ValueConverter.h +0 -70
  319. package/src-native/pods/Headers/v8runtime/V8PointerValue.h +0 -44
  320. package/src-native/pods/Headers/v8runtime/V8Runtime.h +0 -215
  321. package/src-native/pods/Headers/v8runtime/V8RuntimeConfig.h +0 -26
  322. package/src-native/pods/Headers/v8runtime/V8RuntimeFactory.h +0 -21
  323. package/src-native/pods/NativeScript.podspec +0 -68
@@ -1,1387 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #pragma once
9
-
10
- #include <cassert>
11
- #include <cstring>
12
- #include <exception>
13
- #include <functional>
14
- #include <memory>
15
- #include <string>
16
- #include <vector>
17
-
18
- #ifndef JSI_EXPORT
19
- #ifdef _MSC_VER
20
- #ifdef CREATE_SHARED_LIBRARY
21
- #define JSI_EXPORT __declspec(dllexport)
22
- #else
23
- #define JSI_EXPORT
24
- #endif // CREATE_SHARED_LIBRARY
25
- #else // _MSC_VER
26
- #define JSI_EXPORT __attribute__((visibility("default")))
27
- #endif // _MSC_VER
28
- #endif // !defined(JSI_EXPORT)
29
-
30
- class FBJSRuntime;
31
- namespace facebook {
32
- namespace jsi {
33
-
34
- class JSI_EXPORT Buffer {
35
- public:
36
- virtual ~Buffer();
37
- virtual size_t size() const = 0;
38
- virtual const uint8_t* data() const = 0;
39
- };
40
-
41
- class JSI_EXPORT StringBuffer : public Buffer {
42
- public:
43
- StringBuffer(std::string s) : s_(std::move(s)) {}
44
- size_t size() const override {
45
- return s_.size();
46
- }
47
- const uint8_t* data() const override {
48
- return reinterpret_cast<const uint8_t*>(s_.data());
49
- }
50
-
51
- private:
52
- std::string s_;
53
- };
54
-
55
- /// PreparedJavaScript is a base class representing JavaScript which is in a
56
- /// form optimized for execution, in a runtime-specific way. Construct one via
57
- /// jsi::Runtime::prepareJavaScript().
58
- /// ** This is an experimental API that is subject to change. **
59
- class JSI_EXPORT PreparedJavaScript {
60
- protected:
61
- PreparedJavaScript() = default;
62
-
63
- public:
64
- virtual ~PreparedJavaScript() = 0;
65
- };
66
-
67
- class Runtime;
68
- class Pointer;
69
- class PropNameID;
70
- class Symbol;
71
- class BigInt;
72
- class String;
73
- class Object;
74
- class WeakObject;
75
- class Array;
76
- class ArrayBuffer;
77
- class Function;
78
- class Value;
79
- class Instrumentation;
80
- class Scope;
81
- class JSIException;
82
- class JSError;
83
-
84
- /// A function which has this type can be registered as a function
85
- /// callable from JavaScript using Function::createFromHostFunction().
86
- /// When the function is called, args will point to the arguments, and
87
- /// count will indicate how many arguments are passed. The function
88
- /// can return a Value to the caller, or throw an exception. If a C++
89
- /// exception is thrown, a JS Error will be created and thrown into
90
- /// JS; if the C++ exception extends std::exception, the Error's
91
- /// message will be whatever what() returns. Note that it is undefined whether
92
- /// HostFunctions may or may not be called in strict mode; that is `thisVal`
93
- /// can be any value - it will not necessarily be coerced to an object or
94
- /// or set to the global object.
95
- using HostFunctionType = std::function<
96
- Value(Runtime& rt, const Value& thisVal, const Value* args, size_t count)>;
97
-
98
- /// An object which implements this interface can be registered as an
99
- /// Object with the JS runtime.
100
- class JSI_EXPORT HostObject {
101
- public:
102
- // The C++ object's dtor will be called when the GC finalizes this
103
- // object. (This may be as late as when the Runtime is shut down.)
104
- // You have no control over which thread it is called on. This will
105
- // be called from inside the GC, so it is unsafe to do any VM
106
- // operations which require a Runtime&. Derived classes' dtors
107
- // should also avoid doing anything expensive. Calling the dtor on
108
- // a jsi object is explicitly ok. If you want to do JS operations,
109
- // or any nontrivial work, you should add it to a work queue, and
110
- // manage it externally.
111
- virtual ~HostObject();
112
-
113
- // When JS wants a property with a given name from the HostObject,
114
- // it will call this method. If it throws an exception, the call
115
- // will throw a JS \c Error object. By default this returns undefined.
116
- // \return the value for the property.
117
- virtual Value get(Runtime&, const PropNameID& name);
118
-
119
- // When JS wants to set a property with a given name on the HostObject,
120
- // it will call this method. If it throws an exception, the call will
121
- // throw a JS \c Error object. By default this throws a type error exception
122
- // mimicking the behavior of a frozen object in strict mode.
123
- virtual void set(Runtime&, const PropNameID& name, const Value& value);
124
-
125
- // When JS wants a list of property names for the HostObject, it will
126
- // call this method. If it throws an exception, the call will throw a
127
- // JS \c Error object. The default implementation returns empty vector.
128
- virtual std::vector<PropNameID> getPropertyNames(Runtime& rt);
129
- };
130
-
131
- /// Represents a JS runtime. Movable, but not copyable. Note that
132
- /// this object may not be thread-aware, but cannot be used safely from
133
- /// multiple threads at once. The application is responsible for
134
- /// ensuring that it is used safely. This could mean using the
135
- /// Runtime from a single thread, using a mutex, doing all work on a
136
- /// serial queue, etc. This restriction applies to the methods of
137
- /// this class, and any method in the API which take a Runtime& as an
138
- /// argument. Destructors (all but ~Scope), operators, or other methods
139
- /// which do not take Runtime& as an argument are safe to call from any
140
- /// thread, but it is still forbidden to make write operations on a single
141
- /// instance of any class from more than one thread. In addition, to
142
- /// make shutdown safe, destruction of objects associated with the Runtime
143
- /// must be destroyed before the Runtime is destroyed, or from the
144
- /// destructor of a managed HostObject or HostFunction. Informally, this
145
- /// means that the main source of unsafe behavior is to hold a jsi object
146
- /// in a non-Runtime-managed object, and not clean it up before the Runtime
147
- /// is shut down. If your lifecycle is such that avoiding this is hard,
148
- /// you will probably need to do use your own locks.
149
- class JSI_EXPORT Runtime {
150
- public:
151
- virtual ~Runtime();
152
-
153
- /// Evaluates the given JavaScript \c buffer. \c sourceURL is used
154
- /// to annotate the stack trace if there is an exception. The
155
- /// contents may be utf8-encoded JS source code, or binary bytecode
156
- /// whose format is specific to the implementation. If the input
157
- /// format is unknown, or evaluation causes an error, a JSIException
158
- /// will be thrown.
159
- /// Note this function should ONLY be used when there isn't another means
160
- /// through the JSI API. For example, it will be much slower to use this to
161
- /// call a global function than using the JSI APIs to read the function
162
- /// property from the global object and then calling it explicitly.
163
- virtual Value evaluateJavaScript(
164
- const std::shared_ptr<const Buffer>& buffer,
165
- const std::string& sourceURL) = 0;
166
-
167
- /// Prepares to evaluate the given JavaScript \c buffer by processing it into
168
- /// a form optimized for execution. This may include pre-parsing, compiling,
169
- /// etc. If the input is invalid (for example, cannot be parsed), a
170
- /// JSIException will be thrown. The resulting object is tied to the
171
- /// particular concrete type of Runtime from which it was created. It may be
172
- /// used (via evaluatePreparedJavaScript) in any Runtime of the same concrete
173
- /// type.
174
- /// The PreparedJavaScript object may be passed to multiple VM instances, so
175
- /// they can all share and benefit from the prepared script.
176
- /// As with evaluateJavaScript(), using JavaScript code should be avoided
177
- /// when the JSI API is sufficient.
178
- virtual std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
179
- const std::shared_ptr<const Buffer>& buffer,
180
- std::string sourceURL) = 0;
181
-
182
- /// Evaluates a PreparedJavaScript. If evaluation causes an error, a
183
- /// JSIException will be thrown.
184
- /// As with evaluateJavaScript(), using JavaScript code should be avoided
185
- /// when the JSI API is sufficient.
186
- virtual Value evaluatePreparedJavaScript(
187
- const std::shared_ptr<const PreparedJavaScript>& js) = 0;
188
-
189
- /// Drain the JavaScript VM internal Microtask (a.k.a. Job in ECMA262) queue.
190
- ///
191
- /// \param maxMicrotasksHint a hint to tell an implementation that it should
192
- /// make a best effort not execute more than the given number. It's default
193
- /// to -1 for infinity (unbounded execution).
194
- /// \return true if the queue is drained or false if there is more work to do.
195
- ///
196
- /// When there were exceptions thrown from the execution of microtasks,
197
- /// implementations shall discard the exceptional jobs. An implementation may
198
- /// \throw a \c JSError object to signal the hosts to handle. In that case, an
199
- /// implementation may or may not suspend the draining.
200
- ///
201
- /// Hosts may call this function again to resume the draining if it was
202
- /// suspended due to either exceptions or the \p maxMicrotasksHint bound.
203
- /// E.g. a host may repetitively invoke this function until the queue is
204
- /// drained to implement the "microtask checkpoint" defined in WHATWG HTML
205
- /// event loop: https://html.spec.whatwg.org/C#perform-a-microtask-checkpoint.
206
- ///
207
- /// Note that error propagation is only a concern if a host needs to implement
208
- /// `queueMicrotask`, a recent API that allows enqueueing arbitrary functions
209
- /// (hence may throw) as microtasks. Exceptions from ECMA-262 Promise Jobs are
210
- /// handled internally to VMs and are never propagated to hosts.
211
- ///
212
- /// This API offers some queue management to hosts at its best effort due to
213
- /// different behaviors and limitations imposed by different VMs and APIs. By
214
- /// the time this is written, An implementation may swallow exceptions (JSC),
215
- /// may not pause (V8), and may not support bounded executions.
216
- virtual bool drainMicrotasks(int maxMicrotasksHint = -1) = 0;
217
-
218
- /// \return the global object
219
- virtual Object global() = 0;
220
-
221
- /// \return a short printable description of the instance. It should
222
- /// at least include some human-readable indication of the runtime
223
- /// implementation. This should only be used by logging, debugging,
224
- /// and other developer-facing callers.
225
- virtual std::string description() = 0;
226
-
227
- /// \return whether or not the underlying runtime supports debugging via the
228
- /// Chrome remote debugging protocol.
229
- ///
230
- /// NOTE: the API for determining whether a runtime is debuggable and
231
- /// registering a runtime with the debugger is still in flux, so please don't
232
- /// use this API unless you know what you're doing.
233
- virtual bool isInspectable() = 0;
234
-
235
- /// \return an interface to extract metrics from this \c Runtime. The default
236
- /// implementation of this function returns an \c Instrumentation instance
237
- /// which returns no metrics.
238
- virtual Instrumentation& instrumentation();
239
-
240
- protected:
241
- friend class Pointer;
242
- friend class PropNameID;
243
- friend class Symbol;
244
- friend class BigInt;
245
- friend class String;
246
- friend class Object;
247
- friend class WeakObject;
248
- friend class Array;
249
- friend class ArrayBuffer;
250
- friend class Function;
251
- friend class Value;
252
- friend class Scope;
253
- friend class JSError;
254
-
255
- // Potential optimization: avoid the cloneFoo() virtual dispatch,
256
- // and instead just fix the number of fields, and copy them, since
257
- // in practice they are trivially copyable. Sufficient use of
258
- // rvalue arguments/methods would also reduce the number of clones.
259
-
260
- struct PointerValue {
261
- virtual void invalidate() = 0;
262
-
263
- protected:
264
- virtual ~PointerValue() = default;
265
- };
266
-
267
- virtual PointerValue* cloneSymbol(const Runtime::PointerValue* pv) = 0;
268
- virtual PointerValue* cloneBigInt(const Runtime::PointerValue* pv) = 0;
269
- virtual PointerValue* cloneString(const Runtime::PointerValue* pv) = 0;
270
- virtual PointerValue* cloneObject(const Runtime::PointerValue* pv) = 0;
271
- virtual PointerValue* clonePropNameID(const Runtime::PointerValue* pv) = 0;
272
-
273
- virtual PropNameID createPropNameIDFromAscii(
274
- const char* str,
275
- size_t length) = 0;
276
- virtual PropNameID createPropNameIDFromUtf8(
277
- const uint8_t* utf8,
278
- size_t length) = 0;
279
- virtual PropNameID createPropNameIDFromString(const String& str) = 0;
280
- virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0;
281
- virtual std::string utf8(const PropNameID&) = 0;
282
- virtual bool compare(const PropNameID&, const PropNameID&) = 0;
283
-
284
- virtual std::string symbolToString(const Symbol&) = 0;
285
-
286
- virtual String createStringFromAscii(const char* str, size_t length) = 0;
287
- virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0;
288
- virtual std::string utf8(const String&) = 0;
289
-
290
- // \return a \c Value created from a utf8-encoded JSON string. The default
291
- // implementation creates a \c String and invokes JSON.parse.
292
- virtual Value createValueFromJsonUtf8(const uint8_t* json, size_t length);
293
-
294
- virtual Object createObject() = 0;
295
- virtual Object createObject(std::shared_ptr<HostObject> ho) = 0;
296
- virtual std::shared_ptr<HostObject> getHostObject(const jsi::Object&) = 0;
297
- virtual HostFunctionType& getHostFunction(const jsi::Function&) = 0;
298
-
299
- virtual Value getProperty(const Object&, const PropNameID& name) = 0;
300
- virtual Value getProperty(const Object&, const String& name) = 0;
301
- virtual bool hasProperty(const Object&, const PropNameID& name) = 0;
302
- virtual bool hasProperty(const Object&, const String& name) = 0;
303
- virtual void
304
- setPropertyValue(Object&, const PropNameID& name, const Value& value) = 0;
305
- virtual void
306
- setPropertyValue(Object&, const String& name, const Value& value) = 0;
307
-
308
- virtual bool isArray(const Object&) const = 0;
309
- virtual bool isArrayBuffer(const Object&) const = 0;
310
- virtual bool isFunction(const Object&) const = 0;
311
- virtual bool isHostObject(const jsi::Object&) const = 0;
312
- virtual bool isHostFunction(const jsi::Function&) const = 0;
313
- virtual Array getPropertyNames(const Object&) = 0;
314
-
315
- virtual WeakObject createWeakObject(const Object&) = 0;
316
- virtual Value lockWeakObject(WeakObject&) = 0;
317
-
318
- virtual Array createArray(size_t length) = 0;
319
- virtual size_t size(const Array&) = 0;
320
- virtual size_t size(const ArrayBuffer&) = 0;
321
- virtual uint8_t* data(const ArrayBuffer&) = 0;
322
- virtual Value getValueAtIndex(const Array&, size_t i) = 0;
323
- virtual void setValueAtIndexImpl(Array&, size_t i, const Value& value) = 0;
324
-
325
- virtual Function createFunctionFromHostFunction(
326
- const PropNameID& name,
327
- unsigned int paramCount,
328
- HostFunctionType func) = 0;
329
- virtual Value call(
330
- const Function&,
331
- const Value& jsThis,
332
- const Value* args,
333
- size_t count) = 0;
334
- virtual Value
335
- callAsConstructor(const Function&, const Value* args, size_t count) = 0;
336
-
337
- // Private data for managing scopes.
338
- struct ScopeState;
339
- virtual ScopeState* pushScope();
340
- virtual void popScope(ScopeState*);
341
-
342
- virtual bool strictEquals(const Symbol& a, const Symbol& b) const = 0;
343
- virtual bool strictEquals(const BigInt& a, const BigInt& b) const = 0;
344
- virtual bool strictEquals(const String& a, const String& b) const = 0;
345
- virtual bool strictEquals(const Object& a, const Object& b) const = 0;
346
-
347
- virtual bool instanceOf(const Object& o, const Function& f) = 0;
348
-
349
- // These exist so derived classes can access the private parts of
350
- // Value, Symbol, String, and Object, which are all friends of Runtime.
351
- template <typename T>
352
- static T make(PointerValue* pv);
353
- static PointerValue* getPointerValue(Pointer& pointer);
354
- static const PointerValue* getPointerValue(const Pointer& pointer);
355
- static const PointerValue* getPointerValue(const Value& value);
356
-
357
- friend class ::FBJSRuntime;
358
- template <typename Plain, typename Base>
359
- friend class RuntimeDecorator;
360
- };
361
-
362
- // Base class for pointer-storing types.
363
- class JSI_EXPORT Pointer {
364
- protected:
365
- explicit Pointer(Pointer&& other) : ptr_(other.ptr_) {
366
- other.ptr_ = nullptr;
367
- }
368
-
369
- ~Pointer() {
370
- if (ptr_) {
371
- ptr_->invalidate();
372
- }
373
- }
374
-
375
- Pointer& operator=(Pointer&& other);
376
-
377
- friend class Runtime;
378
- friend class Value;
379
-
380
- explicit Pointer(Runtime::PointerValue* ptr) : ptr_(ptr) {}
381
-
382
- typename Runtime::PointerValue* ptr_;
383
- };
384
-
385
- /// Represents something that can be a JS property key. Movable, not copyable.
386
- class JSI_EXPORT PropNameID : public Pointer {
387
- public:
388
- using Pointer::Pointer;
389
-
390
- PropNameID(Runtime& runtime, const PropNameID& other)
391
- : Pointer(runtime.clonePropNameID(other.ptr_)) {}
392
-
393
- PropNameID(PropNameID&& other) = default;
394
- PropNameID& operator=(PropNameID&& other) = default;
395
-
396
- /// Create a JS property name id from ascii values. The data is
397
- /// copied.
398
- static PropNameID forAscii(Runtime& runtime, const char* str, size_t length) {
399
- return runtime.createPropNameIDFromAscii(str, length);
400
- }
401
-
402
- /// Create a property name id from a nul-terminated C ascii name. The data is
403
- /// copied.
404
- static PropNameID forAscii(Runtime& runtime, const char* str) {
405
- return forAscii(runtime, str, strlen(str));
406
- }
407
-
408
- /// Create a PropNameID from a C++ string. The string is copied.
409
- static PropNameID forAscii(Runtime& runtime, const std::string& str) {
410
- return forAscii(runtime, str.c_str(), str.size());
411
- }
412
-
413
- /// Create a PropNameID from utf8 values. The data is copied.
414
- /// Results are undefined if \p utf8 contains invalid code points.
415
- static PropNameID
416
- forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
417
- return runtime.createPropNameIDFromUtf8(utf8, length);
418
- }
419
-
420
- /// Create a PropNameID from utf8-encoded octets stored in a
421
- /// std::string. The string data is transformed and copied.
422
- /// Results are undefined if \p utf8 contains invalid code points.
423
- static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) {
424
- return runtime.createPropNameIDFromUtf8(
425
- reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
426
- }
427
-
428
- /// Create a PropNameID from a JS string.
429
- static PropNameID forString(Runtime& runtime, const jsi::String& str) {
430
- return runtime.createPropNameIDFromString(str);
431
- }
432
-
433
- /// Create a PropNameID from a JS symbol.
434
- static PropNameID forSymbol(Runtime& runtime, const jsi::Symbol& sym) {
435
- return runtime.createPropNameIDFromSymbol(sym);
436
- }
437
-
438
- // Creates a vector of PropNameIDs constructed from given arguments.
439
- template <typename... Args>
440
- static std::vector<PropNameID> names(Runtime& runtime, Args&&... args);
441
-
442
- // Creates a vector of given PropNameIDs.
443
- template <size_t N>
444
- static std::vector<PropNameID> names(PropNameID(&&propertyNames)[N]);
445
-
446
- /// Copies the data in a PropNameID as utf8 into a C++ string.
447
- std::string utf8(Runtime& runtime) const {
448
- return runtime.utf8(*this);
449
- }
450
-
451
- static bool compare(
452
- Runtime& runtime,
453
- const jsi::PropNameID& a,
454
- const jsi::PropNameID& b) {
455
- return runtime.compare(a, b);
456
- }
457
-
458
- friend class Runtime;
459
- friend class Value;
460
- };
461
-
462
- /// Represents a JS Symbol (es6). Movable, not copyable.
463
- /// TODO T40778724: this is a limited implementation sufficient for
464
- /// the debugger not to crash when a Symbol is a property in an Object
465
- /// or element in an array. Complete support for creating will come
466
- /// later.
467
- class JSI_EXPORT Symbol : public Pointer {
468
- public:
469
- using Pointer::Pointer;
470
-
471
- Symbol(Symbol&& other) = default;
472
- Symbol& operator=(Symbol&& other) = default;
473
-
474
- /// \return whether a and b refer to the same symbol.
475
- static bool strictEquals(Runtime& runtime, const Symbol& a, const Symbol& b) {
476
- return runtime.strictEquals(a, b);
477
- }
478
-
479
- /// Converts a Symbol into a C++ string as JS .toString would. The output
480
- /// will look like \c Symbol(description) .
481
- std::string toString(Runtime& runtime) const {
482
- return runtime.symbolToString(*this);
483
- }
484
-
485
- friend class Runtime;
486
- friend class Value;
487
- };
488
-
489
- /// Represents a JS BigInt. Movable, not copyable.
490
- class JSI_EXPORT BigInt : public Pointer {
491
- public:
492
- using Pointer::Pointer;
493
-
494
- BigInt(BigInt&& other) = default;
495
- BigInt& operator=(BigInt&& other) = default;
496
-
497
- friend class Runtime;
498
- friend class Value;
499
- };
500
-
501
- /// Represents a JS String. Movable, not copyable.
502
- class JSI_EXPORT String : public Pointer {
503
- public:
504
- using Pointer::Pointer;
505
-
506
- String(String&& other) = default;
507
- String& operator=(String&& other) = default;
508
-
509
- /// Create a JS string from ascii values. The string data is
510
- /// copied.
511
- static String
512
- createFromAscii(Runtime& runtime, const char* str, size_t length) {
513
- return runtime.createStringFromAscii(str, length);
514
- }
515
-
516
- /// Create a JS string from a nul-terminated C ascii string. The
517
- /// string data is copied.
518
- static String createFromAscii(Runtime& runtime, const char* str) {
519
- return createFromAscii(runtime, str, strlen(str));
520
- }
521
-
522
- /// Create a JS string from a C++ string. The string data is
523
- /// copied.
524
- static String createFromAscii(Runtime& runtime, const std::string& str) {
525
- return createFromAscii(runtime, str.c_str(), str.size());
526
- }
527
-
528
- /// Create a JS string from utf8-encoded octets. The string data is
529
- /// transformed and copied. Results are undefined if \p utf8 contains invalid
530
- /// code points.
531
- static String
532
- createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
533
- return runtime.createStringFromUtf8(utf8, length);
534
- }
535
-
536
- /// Create a JS string from utf8-encoded octets stored in a
537
- /// std::string. The string data is transformed and copied. Results are
538
- /// undefined if \p utf8 contains invalid code points.
539
- static String createFromUtf8(Runtime& runtime, const std::string& utf8) {
540
- return runtime.createStringFromUtf8(
541
- reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
542
- }
543
-
544
- /// \return whether a and b contain the same characters.
545
- static bool strictEquals(Runtime& runtime, const String& a, const String& b) {
546
- return runtime.strictEquals(a, b);
547
- }
548
-
549
- /// Copies the data in a JS string as utf8 into a C++ string.
550
- std::string utf8(Runtime& runtime) const {
551
- return runtime.utf8(*this);
552
- }
553
-
554
- friend class Runtime;
555
- friend class Value;
556
- };
557
-
558
- class Array;
559
- class Function;
560
-
561
- /// Represents a JS Object. Movable, not copyable.
562
- class JSI_EXPORT Object : public Pointer {
563
- public:
564
- using Pointer::Pointer;
565
-
566
- Object(Object&& other) = default;
567
- Object& operator=(Object&& other) = default;
568
-
569
- /// Creates a new Object instance, like '{}' in JS.
570
- Object(Runtime& runtime) : Object(runtime.createObject()) {}
571
-
572
- static Object createFromHostObject(
573
- Runtime& runtime,
574
- std::shared_ptr<HostObject> ho) {
575
- return runtime.createObject(ho);
576
- }
577
-
578
- /// \return whether this and \c obj are the same JSObject or not.
579
- static bool strictEquals(Runtime& runtime, const Object& a, const Object& b) {
580
- return runtime.strictEquals(a, b);
581
- }
582
-
583
- /// \return the result of `this instanceOf ctor` in JS.
584
- bool instanceOf(Runtime& rt, const Function& ctor) {
585
- return rt.instanceOf(*this, ctor);
586
- }
587
-
588
- /// \return the property of the object with the given ascii name.
589
- /// If the name isn't a property on the object, returns the
590
- /// undefined value.
591
- Value getProperty(Runtime& runtime, const char* name) const;
592
-
593
- /// \return the property of the object with the String name.
594
- /// If the name isn't a property on the object, returns the
595
- /// undefined value.
596
- Value getProperty(Runtime& runtime, const String& name) const;
597
-
598
- /// \return the property of the object with the given JS PropNameID
599
- /// name. If the name isn't a property on the object, returns the
600
- /// undefined value.
601
- Value getProperty(Runtime& runtime, const PropNameID& name) const;
602
-
603
- /// \return true if and only if the object has a property with the
604
- /// given ascii name.
605
- bool hasProperty(Runtime& runtime, const char* name) const;
606
-
607
- /// \return true if and only if the object has a property with the
608
- /// given String name.
609
- bool hasProperty(Runtime& runtime, const String& name) const;
610
-
611
- /// \return true if and only if the object has a property with the
612
- /// given PropNameID name.
613
- bool hasProperty(Runtime& runtime, const PropNameID& name) const;
614
-
615
- /// Sets the property value from a Value or anything which can be
616
- /// used to make one: nullptr_t, bool, double, int, const char*,
617
- /// String, or Object.
618
- template <typename T>
619
- void setProperty(Runtime& runtime, const char* name, T&& value);
620
-
621
- /// Sets the property value from a Value or anything which can be
622
- /// used to make one: nullptr_t, bool, double, int, const char*,
623
- /// String, or Object.
624
- template <typename T>
625
- void setProperty(Runtime& runtime, const String& name, T&& value);
626
-
627
- /// Sets the property value from a Value or anything which can be
628
- /// used to make one: nullptr_t, bool, double, int, const char*,
629
- /// String, or Object.
630
- template <typename T>
631
- void setProperty(Runtime& runtime, const PropNameID& name, T&& value);
632
-
633
- /// \return true iff JS \c Array.isArray() would return \c true. If
634
- /// so, then \c getArray() will succeed.
635
- bool isArray(Runtime& runtime) const {
636
- return runtime.isArray(*this);
637
- }
638
-
639
- /// \return true iff the Object is an ArrayBuffer. If so, then \c
640
- /// getArrayBuffer() will succeed.
641
- bool isArrayBuffer(Runtime& runtime) const {
642
- return runtime.isArrayBuffer(*this);
643
- }
644
-
645
- /// \return true iff the Object is callable. If so, then \c
646
- /// getFunction will succeed.
647
- bool isFunction(Runtime& runtime) const {
648
- return runtime.isFunction(*this);
649
- }
650
-
651
- /// \return true iff the Object was initialized with \c createFromHostObject
652
- /// and the HostObject passed is of type \c T. If returns \c true then
653
- /// \c getHostObject<T> will succeed.
654
- template <typename T = HostObject>
655
- bool isHostObject(Runtime& runtime) const;
656
-
657
- /// \return an Array instance which refers to the same underlying
658
- /// object. If \c isArray() would return false, this will assert.
659
- Array getArray(Runtime& runtime) const&;
660
-
661
- /// \return an Array instance which refers to the same underlying
662
- /// object. If \c isArray() would return false, this will assert.
663
- Array getArray(Runtime& runtime) &&;
664
-
665
- /// \return an Array instance which refers to the same underlying
666
- /// object. If \c isArray() would return false, this will throw
667
- /// JSIException.
668
- Array asArray(Runtime& runtime) const&;
669
-
670
- /// \return an Array instance which refers to the same underlying
671
- /// object. If \c isArray() would return false, this will throw
672
- /// JSIException.
673
- Array asArray(Runtime& runtime) &&;
674
-
675
- /// \return an ArrayBuffer instance which refers to the same underlying
676
- /// object. If \c isArrayBuffer() would return false, this will assert.
677
- ArrayBuffer getArrayBuffer(Runtime& runtime) const&;
678
-
679
- /// \return an ArrayBuffer instance which refers to the same underlying
680
- /// object. If \c isArrayBuffer() would return false, this will assert.
681
- ArrayBuffer getArrayBuffer(Runtime& runtime) &&;
682
-
683
- /// \return a Function instance which refers to the same underlying
684
- /// object. If \c isFunction() would return false, this will assert.
685
- Function getFunction(Runtime& runtime) const&;
686
-
687
- /// \return a Function instance which refers to the same underlying
688
- /// object. If \c isFunction() would return false, this will assert.
689
- Function getFunction(Runtime& runtime) &&;
690
-
691
- /// \return a Function instance which refers to the same underlying
692
- /// object. If \c isFunction() would return false, this will throw
693
- /// JSIException.
694
- Function asFunction(Runtime& runtime) const&;
695
-
696
- /// \return a Function instance which refers to the same underlying
697
- /// object. If \c isFunction() would return false, this will throw
698
- /// JSIException.
699
- Function asFunction(Runtime& runtime) &&;
700
-
701
- /// \return a shared_ptr<T> which refers to the same underlying
702
- /// \c HostObject that was used to create this object. If \c isHostObject<T>
703
- /// is false, this will assert. Note that this does a type check and will
704
- /// assert if the underlying HostObject isn't of type \c T
705
- template <typename T = HostObject>
706
- std::shared_ptr<T> getHostObject(Runtime& runtime) const;
707
-
708
- /// \return a shared_ptr<T> which refers to the same underlying
709
- /// \c HostObject that was used to create this object. If \c isHostObject<T>
710
- /// is false, this will throw.
711
- template <typename T = HostObject>
712
- std::shared_ptr<T> asHostObject(Runtime& runtime) const;
713
-
714
- /// \return same as \c getProperty(name).asObject(), except with
715
- /// a better exception message.
716
- Object getPropertyAsObject(Runtime& runtime, const char* name) const;
717
-
718
- /// \return similar to \c
719
- /// getProperty(name).getObject().getFunction(), except it will
720
- /// throw JSIException instead of asserting if the property is
721
- /// not an object, or the object is not callable.
722
- Function getPropertyAsFunction(Runtime& runtime, const char* name) const;
723
-
724
- /// \return an Array consisting of all enumerable property names in
725
- /// the object and its prototype chain. All values in the return
726
- /// will be isString(). (This is probably not optimal, but it
727
- /// works. I only need it in one place.)
728
- Array getPropertyNames(Runtime& runtime) const;
729
-
730
- protected:
731
- void
732
- setPropertyValue(Runtime& runtime, const String& name, const Value& value) {
733
- return runtime.setPropertyValue(*this, name, value);
734
- }
735
-
736
- void setPropertyValue(
737
- Runtime& runtime,
738
- const PropNameID& name,
739
- const Value& value) {
740
- return runtime.setPropertyValue(*this, name, value);
741
- }
742
-
743
- friend class Runtime;
744
- friend class Value;
745
- };
746
-
747
- /// Represents a weak reference to a JS Object. If the only reference
748
- /// to an Object are these, the object is eligible for GC. Method
749
- /// names are inspired by C++ weak_ptr. Movable, not copyable.
750
- class JSI_EXPORT WeakObject : public Pointer {
751
- public:
752
- using Pointer::Pointer;
753
-
754
- WeakObject(WeakObject&& other) = default;
755
- WeakObject& operator=(WeakObject&& other) = default;
756
-
757
- /// Create a WeakObject from an Object.
758
- WeakObject(Runtime& runtime, const Object& o)
759
- : WeakObject(runtime.createWeakObject(o)) {}
760
-
761
- /// \return a Value representing the underlying Object if it is still valid;
762
- /// otherwise returns \c undefined. Note that this method has nothing to do
763
- /// with threads or concurrency. The name is based on std::weak_ptr::lock()
764
- /// which serves a similar purpose.
765
- Value lock(Runtime& runtime);
766
-
767
- friend class Runtime;
768
- };
769
-
770
- /// Represents a JS Object which can be efficiently used as an array
771
- /// with integral indices.
772
- class JSI_EXPORT Array : public Object {
773
- public:
774
- Array(Array&&) = default;
775
- /// Creates a new Array instance, with \c length undefined elements.
776
- Array(Runtime& runtime, size_t length) : Array(runtime.createArray(length)) {}
777
-
778
- Array& operator=(Array&&) = default;
779
-
780
- /// \return the size of the Array, according to its length property.
781
- /// (C++ naming convention)
782
- size_t size(Runtime& runtime) const {
783
- return runtime.size(*this);
784
- }
785
-
786
- /// \return the size of the Array, according to its length property.
787
- /// (JS naming convention)
788
- size_t length(Runtime& runtime) const {
789
- return size(runtime);
790
- }
791
-
792
- /// \return the property of the array at index \c i. If there is no
793
- /// such property, returns the undefined value. If \c i is out of
794
- /// range [ 0..\c length ] throws a JSIException.
795
- Value getValueAtIndex(Runtime& runtime, size_t i) const;
796
-
797
- /// Sets the property of the array at index \c i. The argument
798
- /// value behaves as with Object::setProperty(). If \c i is out of
799
- /// range [ 0..\c length ] throws a JSIException.
800
- template <typename T>
801
- void setValueAtIndex(Runtime& runtime, size_t i, T&& value);
802
-
803
- /// There is no current API for changing the size of an array once
804
- /// created. We'll probably need that eventually.
805
-
806
- /// Creates a new Array instance from provided values
807
- template <typename... Args>
808
- static Array createWithElements(Runtime&, Args&&... args);
809
-
810
- /// Creates a new Array instance from initializer list.
811
- static Array createWithElements(
812
- Runtime& runtime,
813
- std::initializer_list<Value> elements);
814
-
815
- private:
816
- friend class Object;
817
- friend class Value;
818
-
819
- void setValueAtIndexImpl(Runtime& runtime, size_t i, const Value& value) {
820
- return runtime.setValueAtIndexImpl(*this, i, value);
821
- }
822
-
823
- Array(Runtime::PointerValue* value) : Object(value) {}
824
- };
825
-
826
- /// Represents a JSArrayBuffer
827
- class JSI_EXPORT ArrayBuffer : public Object {
828
- public:
829
- ArrayBuffer(ArrayBuffer&&) = default;
830
- ArrayBuffer& operator=(ArrayBuffer&&) = default;
831
-
832
- /// \return the size of the ArrayBuffer, according to its byteLength property.
833
- /// (C++ naming convention)
834
- size_t size(Runtime& runtime) const {
835
- return runtime.size(*this);
836
- }
837
-
838
- size_t length(Runtime& runtime) const {
839
- return runtime.size(*this);
840
- }
841
-
842
- uint8_t* data(Runtime& runtime) {
843
- return runtime.data(*this);
844
- }
845
-
846
- private:
847
- friend class Object;
848
- friend class Value;
849
-
850
- ArrayBuffer(Runtime::PointerValue* value) : Object(value) {}
851
- };
852
-
853
- /// Represents a JS Object which is guaranteed to be Callable.
854
- class JSI_EXPORT Function : public Object {
855
- public:
856
- Function(Function&&) = default;
857
- Function& operator=(Function&&) = default;
858
-
859
- /// Create a function which, when invoked, calls C++ code. If the
860
- /// function throws an exception, a JS Error will be created and
861
- /// thrown.
862
- /// \param name the name property for the function.
863
- /// \param paramCount the length property for the function, which
864
- /// may not be the number of arguments the function is passed.
865
- static Function createFromHostFunction(
866
- Runtime& runtime,
867
- const jsi::PropNameID& name,
868
- unsigned int paramCount,
869
- jsi::HostFunctionType func);
870
-
871
- /// Calls the function with \c count \c args. The \c this value of the JS
872
- /// function will not be set by the C++ caller, similar to calling
873
- /// Function.prototype.apply(undefined, args) in JS.
874
- /// \b Note: as with Function.prototype.apply, \c this may not always be
875
- /// \c undefined in the function itself. If the function is non-strict,
876
- /// \c this will be set to the global object.
877
- Value call(Runtime& runtime, const Value* args, size_t count) const;
878
-
879
- /// Calls the function with a \c std::initializer_list of Value
880
- /// arguments. The \c this value of the JS function will not be set by the
881
- /// C++ caller, similar to calling Function.prototype.apply(undefined, args)
882
- /// in JS.
883
- /// \b Note: as with Function.prototype.apply, \c this may not always be
884
- /// \c undefined in the function itself. If the function is non-strict,
885
- /// \c this will be set to the global object.
886
- Value call(Runtime& runtime, std::initializer_list<Value> args) const;
887
-
888
- /// Calls the function with any number of arguments similarly to
889
- /// Object::setProperty(). The \c this value of the JS function will not be
890
- /// set by the C++ caller, similar to calling
891
- /// Function.prototype.call(undefined, ...args) in JS.
892
- /// \b Note: as with Function.prototype.call, \c this may not always be
893
- /// \c undefined in the function itself. If the function is non-strict,
894
- /// \c this will be set to the global object.
895
- template <typename... Args>
896
- Value call(Runtime& runtime, Args&&... args) const;
897
-
898
- /// Calls the function with \c count \c args and \c jsThis value passed
899
- /// as the \c this value.
900
- Value callWithThis(
901
- Runtime& Runtime,
902
- const Object& jsThis,
903
- const Value* args,
904
- size_t count) const;
905
-
906
- /// Calls the function with a \c std::initializer_list of Value
907
- /// arguments and \c jsThis passed as the \c this value.
908
- Value callWithThis(
909
- Runtime& runtime,
910
- const Object& jsThis,
911
- std::initializer_list<Value> args) const;
912
-
913
- /// Calls the function with any number of arguments similarly to
914
- /// Object::setProperty(), and with \c jsThis passed as the \c this value.
915
- template <typename... Args>
916
- Value callWithThis(Runtime& runtime, const Object& jsThis, Args&&... args)
917
- const;
918
-
919
- /// Calls the function as a constructor with \c count \c args. Equivalent
920
- /// to calling `new Func` where `Func` is the js function reqresented by
921
- /// this.
922
- Value callAsConstructor(Runtime& runtime, const Value* args, size_t count)
923
- const;
924
-
925
- /// Same as above `callAsConstructor`, except use an initializer_list to
926
- /// supply the arguments.
927
- Value callAsConstructor(Runtime& runtime, std::initializer_list<Value> args)
928
- const;
929
-
930
- /// Same as above `callAsConstructor`, but automatically converts/wraps
931
- /// any argument with a jsi Value.
932
- template <typename... Args>
933
- Value callAsConstructor(Runtime& runtime, Args&&... args) const;
934
-
935
- /// Returns whether this was created with Function::createFromHostFunction.
936
- /// If true then you can use getHostFunction to get the underlying
937
- /// HostFunctionType.
938
- bool isHostFunction(Runtime& runtime) const {
939
- return runtime.isHostFunction(*this);
940
- }
941
-
942
- /// Returns the underlying HostFunctionType iff isHostFunction returns true
943
- /// and asserts otherwise. You can use this to use std::function<>::target
944
- /// to get the object that was passed to create the HostFunctionType.
945
- ///
946
- /// Note: The reference returned is borrowed from the JS object underlying
947
- /// \c this, and thus only lasts as long as the object underlying
948
- /// \c this does.
949
- HostFunctionType& getHostFunction(Runtime& runtime) const {
950
- assert(isHostFunction(runtime));
951
- return runtime.getHostFunction(*this);
952
- }
953
-
954
- private:
955
- friend class Object;
956
- friend class Value;
957
-
958
- Function(Runtime::PointerValue* value) : Object(value) {}
959
- };
960
-
961
- /// Represents any JS Value (undefined, null, boolean, number, symbol,
962
- /// string, or object). Movable, or explicitly copyable (has no copy
963
- /// ctor).
964
- class JSI_EXPORT Value {
965
- public:
966
- /// Default ctor creates an \c undefined JS value.
967
- Value() : Value(UndefinedKind) {}
968
-
969
- /// Creates a \c null JS value.
970
- /* implicit */ Value(std::nullptr_t) : kind_(NullKind) {}
971
-
972
- /// Creates a boolean JS value.
973
- /* implicit */ Value(bool b) : Value(BooleanKind) {
974
- data_.boolean = b;
975
- }
976
-
977
- /// Creates a number JS value.
978
- /* implicit */ Value(double d) : Value(NumberKind) {
979
- data_.number = d;
980
- }
981
-
982
- /// Creates a number JS value.
983
- /* implicit */ Value(int i) : Value(NumberKind) {
984
- data_.number = i;
985
- }
986
-
987
- /// Moves a Symbol, String, or Object rvalue into a new JS value.
988
- template <typename T>
989
- /* implicit */ Value(T&& other) : Value(kindOf(other)) {
990
- static_assert(
991
- std::is_base_of<Symbol, T>::value ||
992
- std::is_base_of<BigInt, T>::value ||
993
- std::is_base_of<String, T>::value ||
994
- std::is_base_of<Object, T>::value,
995
- "Value cannot be implicitly move-constructed from this type");
996
- new (&data_.pointer) T(std::move(other));
997
- }
998
-
999
- /// Value("foo") will treat foo as a bool. This makes doing that a
1000
- /// compile error.
1001
- template <typename T = void>
1002
- Value(const char*) {
1003
- static_assert(
1004
- !std::is_same<void, T>::value,
1005
- "Value cannot be constructed directly from const char*");
1006
- }
1007
-
1008
- Value(Value&& value);
1009
-
1010
- /// Copies a Symbol lvalue into a new JS value.
1011
- Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) {
1012
- new (&data_.pointer) Symbol(runtime.cloneSymbol(sym.ptr_));
1013
- }
1014
-
1015
- /// Copies a BigInt lvalue into a new JS value.
1016
- Value(Runtime& runtime, const BigInt& bigint) : Value(BigIntKind) {
1017
- new (&data_.pointer) BigInt(runtime.cloneBigInt(bigint.ptr_));
1018
- }
1019
-
1020
- /// Copies a String lvalue into a new JS value.
1021
- Value(Runtime& runtime, const String& str) : Value(StringKind) {
1022
- new (&data_.pointer) String(runtime.cloneString(str.ptr_));
1023
- }
1024
-
1025
- /// Copies a Object lvalue into a new JS value.
1026
- Value(Runtime& runtime, const Object& obj) : Value(ObjectKind) {
1027
- new (&data_.pointer) Object(runtime.cloneObject(obj.ptr_));
1028
- }
1029
-
1030
- /// Creates a JS value from another Value lvalue.
1031
- Value(Runtime& runtime, const Value& value);
1032
-
1033
- /// Value(rt, "foo") will treat foo as a bool. This makes doing
1034
- /// that a compile error.
1035
- template <typename T = void>
1036
- Value(Runtime&, const char*) {
1037
- static_assert(
1038
- !std::is_same<T, void>::value,
1039
- "Value cannot be constructed directly from const char*");
1040
- }
1041
-
1042
- ~Value();
1043
- // \return the undefined \c Value.
1044
- static Value undefined() {
1045
- return Value();
1046
- }
1047
-
1048
- // \return the null \c Value.
1049
- static Value null() {
1050
- return Value(nullptr);
1051
- }
1052
-
1053
- // \return a \c Value created from a utf8-encoded JSON string.
1054
- static Value
1055
- createFromJsonUtf8(Runtime& runtime, const uint8_t* json, size_t length) {
1056
- return runtime.createValueFromJsonUtf8(json, length);
1057
- }
1058
-
1059
- /// \return according to the Strict Equality Comparison algorithm, see:
1060
- /// https://262.ecma-international.org/11.0/#sec-strict-equality-comparison
1061
- static bool strictEquals(Runtime& runtime, const Value& a, const Value& b);
1062
-
1063
- Value& operator=(Value&& other) {
1064
- this->~Value();
1065
- new (this) Value(std::move(other));
1066
- return *this;
1067
- }
1068
-
1069
- bool isUndefined() const {
1070
- return kind_ == UndefinedKind;
1071
- }
1072
-
1073
- bool isNull() const {
1074
- return kind_ == NullKind;
1075
- }
1076
-
1077
- bool isBool() const {
1078
- return kind_ == BooleanKind;
1079
- }
1080
-
1081
- bool isNumber() const {
1082
- return kind_ == NumberKind;
1083
- }
1084
-
1085
- bool isString() const {
1086
- return kind_ == StringKind;
1087
- }
1088
-
1089
- bool isBigInt() const {
1090
- return kind_ == BigIntKind;
1091
- }
1092
-
1093
- bool isSymbol() const {
1094
- return kind_ == SymbolKind;
1095
- }
1096
-
1097
- bool isObject() const {
1098
- return kind_ == ObjectKind;
1099
- }
1100
-
1101
- /// \return the boolean value, or asserts if not a boolean.
1102
- bool getBool() const {
1103
- assert(isBool());
1104
- return data_.boolean;
1105
- }
1106
-
1107
- /// \return the boolean value, or throws JSIException if not a
1108
- /// boolean.
1109
- bool asBool() const;
1110
-
1111
- /// \return the number value, or asserts if not a number.
1112
- double getNumber() const {
1113
- assert(isNumber());
1114
- return data_.number;
1115
- }
1116
-
1117
- /// \return the number value, or throws JSIException if not a
1118
- /// number.
1119
- double asNumber() const;
1120
-
1121
- /// \return the Symbol value, or asserts if not a symbol.
1122
- Symbol getSymbol(Runtime& runtime) const& {
1123
- assert(isSymbol());
1124
- return Symbol(runtime.cloneSymbol(data_.pointer.ptr_));
1125
- }
1126
-
1127
- /// \return the Symbol value, or asserts if not a symbol.
1128
- /// Can be used on rvalue references to avoid cloning more symbols.
1129
- Symbol getSymbol(Runtime&) && {
1130
- assert(isSymbol());
1131
- auto ptr = data_.pointer.ptr_;
1132
- data_.pointer.ptr_ = nullptr;
1133
- return static_cast<Symbol>(ptr);
1134
- }
1135
-
1136
- /// \return the Symbol value, or throws JSIException if not a
1137
- /// symbol
1138
- Symbol asSymbol(Runtime& runtime) const&;
1139
- Symbol asSymbol(Runtime& runtime) &&;
1140
-
1141
- /// \return the BigInt value, or asserts if not a bigint.
1142
- BigInt getBigInt(Runtime& runtime) const& {
1143
- assert(isBigInt());
1144
- return BigInt(runtime.cloneBigInt(data_.pointer.ptr_));
1145
- }
1146
-
1147
- /// \return the BigInt value, or asserts if not a bigint.
1148
- /// Can be used on rvalue references to avoid cloning more bigints.
1149
- BigInt getBigInt(Runtime&) && {
1150
- assert(isBigInt());
1151
- auto ptr = data_.pointer.ptr_;
1152
- data_.pointer.ptr_ = nullptr;
1153
- return static_cast<BigInt>(ptr);
1154
- }
1155
-
1156
- /// \return the BigInt value, or throws JSIException if not a
1157
- /// bigint
1158
- BigInt asBigInt(Runtime& runtime) const&;
1159
- BigInt asBigInt(Runtime& runtime) &&;
1160
-
1161
- /// \return the String value, or asserts if not a string.
1162
- String getString(Runtime& runtime) const& {
1163
- assert(isString());
1164
- return String(runtime.cloneString(data_.pointer.ptr_));
1165
- }
1166
-
1167
- /// \return the String value, or asserts if not a string.
1168
- /// Can be used on rvalue references to avoid cloning more strings.
1169
- String getString(Runtime&) && {
1170
- assert(isString());
1171
- auto ptr = data_.pointer.ptr_;
1172
- data_.pointer.ptr_ = nullptr;
1173
- return static_cast<String>(ptr);
1174
- }
1175
-
1176
- /// \return the String value, or throws JSIException if not a
1177
- /// string.
1178
- String asString(Runtime& runtime) const&;
1179
- String asString(Runtime& runtime) &&;
1180
-
1181
- /// \return the Object value, or asserts if not an object.
1182
- Object getObject(Runtime& runtime) const& {
1183
- assert(isObject());
1184
- return Object(runtime.cloneObject(data_.pointer.ptr_));
1185
- }
1186
-
1187
- /// \return the Object value, or asserts if not an object.
1188
- /// Can be used on rvalue references to avoid cloning more objects.
1189
- Object getObject(Runtime&) && {
1190
- assert(isObject());
1191
- auto ptr = data_.pointer.ptr_;
1192
- data_.pointer.ptr_ = nullptr;
1193
- return static_cast<Object>(ptr);
1194
- }
1195
-
1196
- /// \return the Object value, or throws JSIException if not an
1197
- /// object.
1198
- Object asObject(Runtime& runtime) const&;
1199
- Object asObject(Runtime& runtime) &&;
1200
-
1201
- // \return a String like JS .toString() would do.
1202
- String toString(Runtime& runtime) const;
1203
-
1204
- private:
1205
- friend class Runtime;
1206
-
1207
- enum ValueKind {
1208
- UndefinedKind,
1209
- NullKind,
1210
- BooleanKind,
1211
- NumberKind,
1212
- SymbolKind,
1213
- BigIntKind,
1214
- StringKind,
1215
- ObjectKind,
1216
- PointerKind = SymbolKind,
1217
- };
1218
-
1219
- union Data {
1220
- // Value's ctor and dtor will manage the lifecycle of the contained Data.
1221
- Data() {
1222
- static_assert(
1223
- sizeof(Data) == sizeof(uint64_t),
1224
- "Value data should fit in a 64-bit register");
1225
- }
1226
- ~Data() {}
1227
-
1228
- // scalars
1229
- bool boolean;
1230
- double number;
1231
- // pointers
1232
- Pointer pointer; // Symbol, String, Object, Array, Function
1233
- };
1234
-
1235
- Value(ValueKind kind) : kind_(kind) {}
1236
-
1237
- constexpr static ValueKind kindOf(const Symbol&) {
1238
- return SymbolKind;
1239
- }
1240
- constexpr static ValueKind kindOf(const BigInt&) {
1241
- return BigIntKind;
1242
- }
1243
- constexpr static ValueKind kindOf(const String&) {
1244
- return StringKind;
1245
- }
1246
- constexpr static ValueKind kindOf(const Object&) {
1247
- return ObjectKind;
1248
- }
1249
-
1250
- ValueKind kind_;
1251
- Data data_;
1252
-
1253
- // In the future: Value becomes NaN-boxed. See T40538354.
1254
- };
1255
-
1256
- /// Not movable and not copyable RAII marker advising the underlying
1257
- /// JavaScript VM to track resources allocated since creation until
1258
- /// destruction so that they can be recycled eagerly when the Scope
1259
- /// goes out of scope instead of floating in the air until the next
1260
- /// garbage collection or any other delayed release occurs.
1261
- ///
1262
- /// This API should be treated only as advice, implementations can
1263
- /// choose to ignore the fact that Scopes are created or destroyed.
1264
- ///
1265
- /// This class is an exception to the rule allowing destructors to be
1266
- /// called without proper synchronization (see Runtime documentation).
1267
- /// The whole point of this class is to enable all sorts of clean ups
1268
- /// when the destructor is called and this proper synchronization is
1269
- /// required at that time.
1270
- ///
1271
- /// Instances of this class are intended to be created as automatic stack
1272
- /// variables in which case destructor calls don't require any additional
1273
- /// locking, provided that the lock (if any) is managed with RAII helpers.
1274
- class JSI_EXPORT Scope {
1275
- public:
1276
- explicit Scope(Runtime& rt) : rt_(rt), prv_(rt.pushScope()) {}
1277
- ~Scope() {
1278
- rt_.popScope(prv_);
1279
- };
1280
-
1281
- Scope(const Scope&) = delete;
1282
- Scope(Scope&&) = delete;
1283
-
1284
- Scope& operator=(const Scope&) = delete;
1285
- Scope& operator=(Scope&&) = delete;
1286
-
1287
- template <typename F>
1288
- static auto callInNewScope(Runtime& rt, F f) -> decltype(f()) {
1289
- Scope s(rt);
1290
- return f();
1291
- }
1292
-
1293
- private:
1294
- Runtime& rt_;
1295
- Runtime::ScopeState* prv_;
1296
- };
1297
-
1298
- /// Base class for jsi exceptions
1299
- class JSI_EXPORT JSIException : public std::exception {
1300
- protected:
1301
- JSIException(){};
1302
- JSIException(std::string what) : what_(std::move(what)){};
1303
-
1304
- public:
1305
- JSIException(const JSIException&) = default;
1306
-
1307
- virtual const char* what() const noexcept override {
1308
- return what_.c_str();
1309
- }
1310
-
1311
- virtual ~JSIException() override;
1312
-
1313
- protected:
1314
- std::string what_;
1315
- };
1316
-
1317
- /// This exception will be thrown by API functions on errors not related to
1318
- /// JavaScript execution.
1319
- class JSI_EXPORT JSINativeException : public JSIException {
1320
- public:
1321
- JSINativeException(std::string what) : JSIException(std::move(what)) {}
1322
-
1323
- JSINativeException(const JSINativeException&) = default;
1324
-
1325
- virtual ~JSINativeException();
1326
- };
1327
-
1328
- /// This exception will be thrown by API functions whenever a JS
1329
- /// operation causes an exception as described by the spec, or as
1330
- /// otherwise described.
1331
- class JSI_EXPORT JSError : public JSIException {
1332
- public:
1333
- /// Creates a JSError referring to provided \c value
1334
- JSError(Runtime& r, Value&& value);
1335
-
1336
- /// Creates a JSError referring to new \c Error instance capturing current
1337
- /// JavaScript stack. The error message property is set to given \c message.
1338
- JSError(Runtime& rt, std::string message);
1339
-
1340
- /// Creates a JSError referring to new \c Error instance capturing current
1341
- /// JavaScript stack. The error message property is set to given \c message.
1342
- JSError(Runtime& rt, const char* message)
1343
- : JSError(rt, std::string(message)){};
1344
-
1345
- /// Creates a JSError referring to a JavaScript Object having message and
1346
- /// stack properties set to provided values.
1347
- JSError(Runtime& rt, std::string message, std::string stack);
1348
-
1349
- /// Creates a JSError referring to provided value and what string
1350
- /// set to provided message. This argument order is a bit weird,
1351
- /// but necessary to avoid ambiguity with the above.
1352
- JSError(std::string what, Runtime& rt, Value&& value);
1353
-
1354
- JSError(const JSError&) = default;
1355
-
1356
- virtual ~JSError();
1357
-
1358
- const std::string& getStack() const {
1359
- return stack_;
1360
- }
1361
-
1362
- const std::string& getMessage() const {
1363
- return message_;
1364
- }
1365
-
1366
- const jsi::Value& value() const {
1367
- assert(value_);
1368
- return *value_;
1369
- }
1370
-
1371
- private:
1372
- // This initializes the value_ member and does some other
1373
- // validation, so it must be called by every branch through the
1374
- // constructors.
1375
- void setValue(Runtime& rt, Value&& value);
1376
-
1377
- // This needs to be on the heap, because throw requires the object
1378
- // be copyable, and Value is not.
1379
- std::shared_ptr<jsi::Value> value_;
1380
- std::string message_;
1381
- std::string stack_;
1382
- };
1383
-
1384
- } // namespace jsi
1385
- } // namespace facebook
1386
-
1387
- #include "jsi/jsi-inl.h"