react-native-windows 0.76.3 → 0.77.0-preview.1

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 (369) hide show
  1. package/.flowconfig +5 -1
  2. package/Libraries/ActionSheetIOS/ActionSheetIOS.d.ts +1 -0
  3. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +13 -0
  4. package/Libraries/Animated/AnimatedEvent.js +1 -1
  5. package/Libraries/Animated/AnimatedImplementation.js +2 -2
  6. package/Libraries/Animated/NativeAnimatedAllowlist.js +20 -9
  7. package/Libraries/Animated/NativeAnimatedAllowlist.windows.js +122 -0
  8. package/Libraries/Animated/animations/Animation.js +60 -25
  9. package/Libraries/Animated/animations/DecayAnimation.js +26 -38
  10. package/Libraries/Animated/animations/SpringAnimation.js +33 -39
  11. package/Libraries/Animated/animations/TimingAnimation.js +34 -42
  12. package/Libraries/Animated/components/AnimatedFlatList.js +1 -1
  13. package/Libraries/Animated/components/AnimatedSectionList.js +3 -1
  14. package/Libraries/Animated/createAnimatedComponent.js +60 -33
  15. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  16. package/Libraries/Animated/nodes/AnimatedInterpolation.js +1 -1
  17. package/Libraries/Animated/nodes/AnimatedNode.js +39 -45
  18. package/Libraries/Animated/nodes/AnimatedObject.js +13 -3
  19. package/Libraries/Animated/nodes/AnimatedProps.js +96 -46
  20. package/Libraries/Animated/nodes/AnimatedProps.windows.js +281 -0
  21. package/Libraries/Animated/nodes/AnimatedStyle.js +108 -39
  22. package/Libraries/Animated/nodes/AnimatedStyle.windows.js +251 -0
  23. package/Libraries/Animated/nodes/AnimatedTransform.js +56 -23
  24. package/Libraries/Animated/nodes/AnimatedValue.js +1 -1
  25. package/Libraries/Animated/nodes/AnimatedWithChildren.js +1 -3
  26. package/Libraries/Animated/useAnimatedProps.js +41 -35
  27. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +19 -3
  28. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +77 -5
  29. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.windows.js +82 -5
  30. package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +4 -4
  31. package/Libraries/Components/Button.js +9 -4
  32. package/Libraries/Components/Button.windows.js +19 -5
  33. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +3 -1
  34. package/Libraries/Components/Glyph/Glyph.js +2 -1
  35. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +7 -0
  36. package/Libraries/Components/Popup/PopupNativeComponent.js +0 -1
  37. package/Libraries/Components/Pressable/Pressable.js +4 -4
  38. package/Libraries/Components/Pressable/Pressable.windows.js +10 -4
  39. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +13 -7
  40. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +3 -2
  41. package/Libraries/Components/SafeAreaView/SafeAreaView.js +4 -4
  42. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +0 -1
  43. package/Libraries/Components/ScrollView/ScrollView.js +49 -88
  44. package/Libraries/Components/ScrollView/ScrollViewCommands.js +1 -1
  45. package/Libraries/Components/ScrollView/ScrollViewContext.js +2 -0
  46. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +0 -2
  47. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.windows.js +0 -5
  48. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +8 -9
  49. package/Libraries/Components/Switch/Switch.js +8 -6
  50. package/Libraries/Components/Switch/Switch.windows.js +8 -6
  51. package/Libraries/Components/TextInput/InputAccessoryView.js +1 -1
  52. package/Libraries/Components/TextInput/RCTMultilineTextInputNativeComponent.js +4 -4
  53. package/Libraries/Components/TextInput/RCTSingelineTextInputNativeComponent.js +6 -4
  54. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +2 -1
  55. package/Libraries/Components/TextInput/TextInput.d.ts +27 -4
  56. package/Libraries/Components/TextInput/TextInput.flow.js +36 -19
  57. package/Libraries/Components/TextInput/TextInput.js +37 -13
  58. package/Libraries/Components/TextInput/TextInput.windows.js +47 -16
  59. package/Libraries/Components/TextInput/TextInputState.js +11 -13
  60. package/Libraries/Components/TextInput/TextInputState.windows.js +11 -13
  61. package/Libraries/Components/Touchable/BoundingDimensions.js +11 -3
  62. package/Libraries/Components/Touchable/Position.js +7 -2
  63. package/Libraries/Components/Touchable/Touchable.js +4 -0
  64. package/Libraries/Components/Touchable/Touchable.windows.js +4 -0
  65. package/Libraries/Components/Touchable/TouchableBounce.js +6 -2
  66. package/Libraries/Components/Touchable/TouchableBounce.windows.js +227 -0
  67. package/Libraries/Components/Touchable/TouchableHighlight.js +5 -5
  68. package/Libraries/Components/Touchable/TouchableHighlight.windows.js +5 -5
  69. package/Libraries/Components/Touchable/TouchableNativeFeedback.windows.js +371 -0
  70. package/Libraries/Components/Touchable/TouchableOpacity.js +6 -5
  71. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +11 -5
  72. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +1 -2
  73. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +9 -3
  74. package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -1
  75. package/Libraries/Components/View/View.js +4 -4
  76. package/Libraries/Components/View/View.windows.js +12 -5
  77. package/Libraries/Components/View/ViewAccessibility.d.ts +10 -0
  78. package/Libraries/Components/View/ViewAccessibility.windows.js +2 -0
  79. package/Libraries/Components/View/ViewNativeComponent.js +6 -98
  80. package/Libraries/Components/View/ViewPropTypes.d.ts +7 -0
  81. package/Libraries/Components/View/ViewPropTypes.js +0 -3
  82. package/Libraries/Components/View/ViewPropTypes.windows.js +2 -3
  83. package/Libraries/Core/ExceptionsManager.js +50 -29
  84. package/Libraries/Core/ReactNativeVersion.js +3 -3
  85. package/Libraries/Core/__mocks__/NativeExceptionsManager.js +0 -1
  86. package/Libraries/Core/setUpBatchedBridge.js +1 -10
  87. package/Libraries/Core/setUpDeveloperTools.js +1 -5
  88. package/Libraries/Core/setUpErrorHandling.js +20 -18
  89. package/Libraries/Core/setUpReactDevTools.js +107 -8
  90. package/Libraries/Core/setUpSegmentFetcher.js +1 -0
  91. package/Libraries/Core/setUpTimers.js +21 -18
  92. package/Libraries/Debugging/DebuggingOverlay.js +4 -5
  93. package/Libraries/Image/AssetSourceResolver.js +12 -1
  94. package/Libraries/Image/AssetSourceResolver.windows.js +12 -1
  95. package/Libraries/Image/Image.android.js +1 -5
  96. package/Libraries/Image/Image.d.ts +20 -29
  97. package/Libraries/Image/Image.ios.js +0 -2
  98. package/Libraries/Image/Image.windows.js +5 -1
  99. package/Libraries/Image/ImageBackground.js +2 -5
  100. package/Libraries/Image/ImageProps.js +7 -6
  101. package/Libraries/Image/ImageResizeMode.d.ts +8 -1
  102. package/Libraries/Image/ImageResizeMode.js +4 -1
  103. package/Libraries/Image/ImageSource.d.ts +0 -2
  104. package/Libraries/Image/ImageSource.js +0 -2
  105. package/Libraries/Image/ImageTypes.flow.js +11 -9
  106. package/Libraries/Image/ImageUtils.js +6 -3
  107. package/Libraries/Image/ImageViewNativeComponent.js +5 -3
  108. package/Libraries/Inspector/Inspector.js +1 -0
  109. package/Libraries/Inspector/NetworkOverlay.js +4 -0
  110. package/Libraries/Inspector/ReactDevToolsOverlay.js +8 -14
  111. package/Libraries/Inspector/getInspectorDataForViewAtPoint.js +3 -5
  112. package/Libraries/Interaction/InteractionManager.js +6 -1
  113. package/Libraries/Interaction/InteractionManagerStub.js +176 -0
  114. package/Libraries/Interaction/TouchHistoryMath.js +22 -19
  115. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  116. package/Libraries/Lists/FlatList.d.ts +1 -2
  117. package/Libraries/Lists/FlatList.js +2 -2
  118. package/Libraries/Lists/SectionListModern.js +7 -7
  119. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +2 -2
  120. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
  121. package/Libraries/LogBox/Data/LogBoxData.js +3 -3
  122. package/Libraries/LogBox/LogBox.js +18 -5
  123. package/Libraries/LogBox/LogBoxInspectorContainer.js +1 -1
  124. package/Libraries/LogBox/LogBoxNotificationContainer.js +2 -2
  125. package/Libraries/LogBox/UI/AnsiHighlight.js +26 -17
  126. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.js +6 -1
  127. package/Libraries/LogBox/UI/LogBoxInspectorCodeFrame.windows.js +6 -1
  128. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +1 -1
  129. package/Libraries/LogBox/UI/LogBoxInspectorHeader.windows.js +1 -1
  130. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +1 -1
  131. package/Libraries/LogBox/UI/LogBoxMessage.js +2 -2
  132. package/Libraries/Modal/Modal.d.ts +12 -0
  133. package/Libraries/Modal/Modal.js +31 -4
  134. package/Libraries/Modal/Modal.windows.js +18 -0
  135. package/Libraries/NativeComponent/BaseViewConfig.android.js +72 -1
  136. package/Libraries/NativeComponent/BaseViewConfig.ios.js +2 -1
  137. package/Libraries/NativeComponent/BaseViewConfig.windows.js +3 -11
  138. package/Libraries/NativeComponent/NativeComponentRegistry.js +3 -3
  139. package/Libraries/NativeComponent/StaticViewConfigValidator.js +0 -1
  140. package/Libraries/Network/XHRInterceptor.js +63 -14
  141. package/Libraries/Network/XMLHttpRequest.js +26 -1
  142. package/Libraries/NewAppScreen/components/HermesBadge.js +1 -1
  143. package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +49 -2
  144. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +4 -4
  145. package/Libraries/Pressability/HoverState.js +2 -0
  146. package/Libraries/Pressability/Pressability.js +2 -3
  147. package/Libraries/Pressability/Pressability.windows.js +2 -3
  148. package/Libraries/Pressability/usePressability.js +4 -1
  149. package/Libraries/ReactNative/AppContainer.js +1 -1
  150. package/Libraries/ReactNative/AppRegistry.js +1 -11
  151. package/Libraries/ReactNative/DisplayMode.js +1 -1
  152. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -3
  153. package/Libraries/ReactNative/RendererImplementation.js +18 -17
  154. package/Libraries/ReactNative/getCachedComponentWithDebugName.js +1 -3
  155. package/Libraries/ReactNative/renderApplication.js +9 -8
  156. package/Libraries/ReactNative/requireNativeComponent.js +5 -2
  157. package/Libraries/Renderer/shims/ReactFabric.js +3 -3
  158. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -2
  159. package/Libraries/Renderer/shims/ReactNative.js +3 -3
  160. package/Libraries/Renderer/shims/ReactNativeTypes.js +22 -35
  161. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +5 -6
  162. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  163. package/Libraries/StyleSheet/StyleSheet.js +7 -1
  164. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +13 -2
  165. package/Libraries/StyleSheet/StyleSheetTypes.js +24 -6
  166. package/Libraries/StyleSheet/processBackgroundImage.js +87 -110
  167. package/Libraries/StyleSheet/processTransform.js +3 -34
  168. package/Libraries/Text/Text.js +248 -249
  169. package/Libraries/Text/Text.windows.js +298 -292
  170. package/Libraries/Text/TextNativeComponent.js +0 -1
  171. package/Libraries/Text/TextProps.windows.js +2 -0
  172. package/Libraries/TurboModule/TurboModuleRegistry.js +5 -5
  173. package/Libraries/Types/CoreEventTypes.d.ts +3 -10
  174. package/Libraries/Types/CoreEventTypes.js +4 -6
  175. package/Libraries/Types/CoreEventTypes.windows.js +4 -6
  176. package/Libraries/Utilities/Appearance.js +3 -1
  177. package/Libraries/Utilities/BackHandler.android.js +6 -18
  178. package/Libraries/Utilities/BackHandler.d.ts +0 -4
  179. package/Libraries/Utilities/BackHandler.ios.js +0 -7
  180. package/Libraries/Utilities/BackHandler.windows.js +6 -18
  181. package/Libraries/Utilities/HMRClient.js +3 -4
  182. package/Libraries/Utilities/Platform.flow.js +2 -2
  183. package/Libraries/Utilities/Platform.flow.windows.js +3 -2
  184. package/Libraries/Utilities/__mocks__/BackHandler.js +3 -8
  185. package/Libraries/Utilities/codegenNativeComponent.js +1 -1
  186. package/Libraries/Utilities/useMergeRefs.js +26 -7
  187. package/Libraries/WebSocket/WebSocketEvent.js +4 -1
  188. package/Libraries/WebSocket/WebSocketInterceptor.js +31 -13
  189. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +6 -5
  190. package/Libraries/promiseRejectionTrackingOptions.js +1 -1
  191. package/Microsoft.ReactNative/AsynchronousEventBeat.cpp +9 -8
  192. package/Microsoft.ReactNative/AsynchronousEventBeat.h +5 -5
  193. package/Microsoft.ReactNative/FBReactNativeSpec/FBReactNativeSpecJSI.h +5 -0
  194. package/Microsoft.ReactNative/Fabric/AbiComponentDescriptor.cpp +2 -2
  195. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +197 -18
  196. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +19 -1
  197. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +13 -0
  198. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +1 -1
  199. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +6 -8
  200. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +2 -2
  201. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +3 -2
  202. package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +1 -1
  203. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +24 -0
  204. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +5 -0
  205. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +12 -12
  206. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +4 -4
  207. package/Microsoft.ReactNative/Fabric/ImageRequest.cpp +4 -8
  208. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +16 -15
  209. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +15 -0
  210. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.h +9 -0
  211. package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +20 -1
  212. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +11 -6
  213. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
  214. package/Microsoft.ReactNative/SynchronousEventBeat.cpp +14 -4
  215. package/Microsoft.ReactNative/SynchronousEventBeat.h +4 -2
  216. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.cpp +78 -0
  217. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.h +51 -0
  218. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.inc +48 -0
  219. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.cpp +41 -0
  220. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.h +127 -0
  221. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi.inc +125 -0
  222. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_posix.cpp +16 -0
  223. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_win.cpp +23 -0
  224. package/Microsoft.ReactNative.Cxx/JSI/decorator.h +834 -0
  225. package/Microsoft.ReactNative.Cxx/JSI/instrumentation.h +117 -0
  226. package/Microsoft.ReactNative.Cxx/JSI/jsi-inl.h +366 -0
  227. package/Microsoft.ReactNative.Cxx/JSI/jsi.cpp +560 -0
  228. package/Microsoft.ReactNative.Cxx/JSI/jsi.h +1611 -0
  229. package/Microsoft.ReactNative.Cxx/JSI/threadsafe.h +79 -0
  230. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +7 -11
  231. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +1 -1
  232. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.cpp +2878 -0
  233. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.h +36 -0
  234. package/Microsoft.ReactNative.Cxx/ReactCommon/CallInvoker.h +64 -0
  235. package/Microsoft.ReactNative.Cxx/ReactCommon/SchedulerPriority.h +22 -0
  236. package/{ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core → Microsoft.ReactNative.Cxx}/ReactCommon/TurboModule.cpp +63 -63
  237. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModule.h +165 -0
  238. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModuleUtils.cpp +105 -0
  239. package/{ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core → Microsoft.ReactNative.Cxx}/ReactCommon/TurboModuleUtils.h +57 -58
  240. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/AString.h +42 -0
  241. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Array.h +151 -0
  242. package/{ReactCommon/TEMP_UntilReactCommonUpdate → Microsoft.ReactNative.Cxx/ReactCommon}/react/bridging/Base.h +177 -154
  243. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Bool.h +25 -0
  244. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Bridging.h +21 -0
  245. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/CallbackWrapper.h +67 -0
  246. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Class.h +90 -0
  247. package/{ReactCommon/TEMP_UntilReactCommonUpdate → Microsoft.ReactNative.Cxx/ReactCommon}/react/bridging/Convert.h +170 -172
  248. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Error.h +51 -0
  249. package/{ReactCommon/TEMP_UntilReactCommonUpdate → Microsoft.ReactNative.Cxx/ReactCommon}/react/bridging/EventEmitter.h +134 -136
  250. package/{ReactCommon/TEMP_UntilReactCommonUpdate → Microsoft.ReactNative.Cxx/ReactCommon}/react/bridging/Function.h +283 -283
  251. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/LongLivedObject.cpp +63 -0
  252. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/LongLivedObject.h +61 -0
  253. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Object.h +93 -0
  254. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Promise.h +104 -0
  255. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Value.h +107 -0
  256. package/Microsoft.ReactNative.Cxx/ReactCommon/react/debug/flags.h +22 -0
  257. package/Microsoft.ReactNative.Cxx/ReactCommon/react/debug/react_native_assert.h +72 -0
  258. package/Microsoft.ReactNative.Cxx/node-api/js_native_api.h +553 -0
  259. package/Microsoft.ReactNative.Cxx/node-api/js_native_api_types.h +167 -0
  260. package/Microsoft.ReactNative.Cxx/node-api/js_runtime_api.h +186 -0
  261. package/Microsoft.ReactNative.Cxx/stubs/glog/logging.h +82 -0
  262. package/PropertySheets/Bundle.Common.targets +1 -1
  263. package/PropertySheets/Bundle.props +3 -0
  264. package/PropertySheets/Generated/PackageVersion.g.props +4 -4
  265. package/PropertySheets/ManagedCodeGen/Microsoft.ReactNative.Managed.CodeGen.targets +1 -1
  266. package/PropertySheets/OutputMSBuildProperties.targets +3 -1
  267. package/ReactCommon/ReactCommon.vcxproj +5 -0
  268. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +2 -3
  269. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +61 -0
  270. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +26 -23
  271. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +150 -0
  272. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +252 -0
  273. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +795 -0
  274. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/runtimescheduler/SchedulerPriorityUtils.h +59 -0
  275. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +188 -39
  276. package/Scripts/Microsoft.ReactNative.Managed.CodeGen.targets +1 -1
  277. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +97 -62
  278. package/Shared/InspectorPackagerConnection.cpp +3 -6
  279. package/Shared/InspectorPackagerConnection.h +2 -2
  280. package/Shared/InstanceManager.h +1 -1
  281. package/Shared/OInstance.h +1 -1
  282. package/Shared/Shared.vcxitems +17 -2
  283. package/Shared/Shared.vcxitems.filters +3 -1
  284. package/Shared/TurboModuleManager.cpp +29 -4
  285. package/codegen/NativeAccessibilityInfoSpec.g.h +27 -9
  286. package/codegen/NativeAccessibilityManagerSpec.g.h +19 -13
  287. package/codegen/NativeActionSheetManagerSpec.g.h +4 -0
  288. package/codegen/NativeExceptionsManagerSpec.g.h +1 -7
  289. package/codegen/NativeIntersectionObserverSpec.g.h +2 -0
  290. package/codegen/NativePerformanceSpec.g.h +127 -3
  291. package/codegen/NativeReactDevToolsRuntimeSettingsModuleSpec.g.h +67 -0
  292. package/codegen/NativeReactDevToolsSettingsManagerSpec.g.h +41 -0
  293. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +125 -137
  294. package/codegen/react/components/rnwcore/ComponentDescriptors.h +0 -1
  295. package/codegen/react/components/rnwcore/Props.cpp +1 -0
  296. package/codegen/react/components/rnwcore/Props.h +1 -0
  297. package/codegen/react/components/rnwcore/ShadowNodes.cpp +0 -1
  298. package/codegen/react/components/rnwcore/ShadowNodes.h +0 -11
  299. package/codegen/react/components/rnwcore/States.h +0 -12
  300. package/codegen/rnwcoreJSI-generated.cpp +219 -186
  301. package/codegen/rnwcoreJSI.h +942 -511
  302. package/index.js +10 -3
  303. package/index.windows.js +10 -3
  304. package/jest/setup.js +36 -1
  305. package/just-task.js +15 -0
  306. package/package.json +22 -22
  307. package/src/private/animated/NativeAnimatedHelper.js +18 -16
  308. package/src/private/animated/useAnimatedPropsMemo.js +348 -0
  309. package/src/private/animated/useAnimatedPropsMemo.windows.js +356 -0
  310. package/src/private/components/HScrollViewNativeComponents.js +1 -27
  311. package/src/private/components/SafeAreaView_INTERNAL_DO_NOT_USE.js +11 -8
  312. package/src/private/components/VScrollViewNativeComponents.js +2 -25
  313. package/src/private/debugging/ReactDevToolsSettingsManager.android.js +20 -0
  314. package/src/private/debugging/ReactDevToolsSettingsManager.ios.js +30 -0
  315. package/src/private/debugging/ReactDevToolsSettingsManager.windows.js +20 -0
  316. package/src/private/{fusebox → debugging}/setUpFuseboxReactDevToolsDispatcher.js +6 -0
  317. package/src/private/devmenu/DevMenu.d.ts +20 -0
  318. package/src/private/devmenu/DevMenu.js +31 -0
  319. package/src/private/featureflags/ReactNativeFeatureFlags.js +95 -86
  320. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +8 -2
  321. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +17 -19
  322. package/src/private/fusebox/specs/NativeReactDevToolsRuntimeSettingsModule.js +34 -0
  323. package/src/private/setup/setUpDOM.js +14 -6
  324. package/src/private/setup/setUpMutationObserver.js +5 -0
  325. package/src/private/specs/components/AndroidHorizontalScrollContentViewNativeComponent.js +1 -0
  326. package/src/private/specs/components/RCTModalHostViewNativeComponent.js +8 -0
  327. package/src/private/specs/modules/NativeAccessibilityInfo.js +9 -0
  328. package/src/private/specs/modules/NativeAccessibilityManager.js +4 -0
  329. package/src/private/specs/modules/NativeActionSheetManager.js +2 -0
  330. package/src/private/specs/modules/NativeAppearance.js +4 -10
  331. package/src/private/specs/modules/NativeExceptionsManager.js +0 -12
  332. package/src/private/specs/modules/{NativeDevToolsSettingsManager.js → NativeReactDevToolsSettingsManager.js} +3 -5
  333. package/src/private/webapis/dom/geometry/DOMRect.js +2 -2
  334. package/src/private/webapis/dom/geometry/DOMRectReadOnly.js +2 -2
  335. package/src/private/webapis/dom/nodes/ReactNativeElement.js +2 -3
  336. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +102 -11
  337. package/src/private/webapis/intersectionobserver/IntersectionObserverEntry.js +26 -0
  338. package/src/private/webapis/intersectionobserver/IntersectionObserverManager.js +1 -0
  339. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
  340. package/src/private/webapis/intersectionobserver/specs/__mocks__/NativeIntersectionObserver.js +9 -0
  341. package/src/private/webapis/performance/EventTiming.js +13 -8
  342. package/src/private/webapis/performance/Performance.js +66 -73
  343. package/src/private/webapis/performance/PerformanceEntry.js +2 -5
  344. package/src/private/webapis/performance/PerformanceObserver.js +65 -164
  345. package/src/private/webapis/performance/RawPerformanceEntry.js +1 -1
  346. package/src/private/webapis/performance/UserTiming.js +11 -7
  347. package/src/private/webapis/performance/Utilities.js +18 -0
  348. package/src/private/webapis/performance/specs/NativePerformance.js +71 -2
  349. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +267 -0
  350. package/templates/cpp-lib/template.config.js +13 -7
  351. package/templates/templateUtils.js +10 -0
  352. package/types/index.d.ts +1 -1
  353. package/types/public/ReactNativeTypes.d.ts +4 -8
  354. package/Libraries/DevToolsSettings/DevToolsSettingsManager.android.js +0 -35
  355. package/Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts +0 -20
  356. package/Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js +0 -49
  357. package/Libraries/DevToolsSettings/DevToolsSettingsManager.windows.js +0 -35
  358. package/Libraries/DevToolsSettings/NativeDevToolsSettingsManager.js +0 -13
  359. package/Libraries/ReactNative/ReactFabricInternals.js +0 -17
  360. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/CallbackWrapper.h +0 -101
  361. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/scrollview/ScrollViewProps.cpp +0 -569
  362. package/codegen/NativeDevToolsSettingsManagerSpec.g.h +0 -53
  363. package/codegen/NativePerformanceObserverSpec.g.h +0 -131
  364. package/src/private/components/useSyncOnScroll.js +0 -48
  365. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +0 -61
  366. package/src/private/webapis/performance/specs/__mocks__/NativePerformance.js +0 -67
  367. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceObserver.js +0 -127
  368. package/types/experimental.d.ts +0 -59
  369. /package/src/private/{fusebox → debugging}/FuseboxSessionObserver.js +0 -0
@@ -0,0 +1,1611 @@
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
+ // JSI version defines set of features available in the API.
31
+ // Each significant API change must be under a new version.
32
+ #ifndef JSI_VERSION
33
+ #define JSI_VERSION 11
34
+ #endif
35
+
36
+ #if JSI_VERSION >= 3
37
+ #define JSI_NO_CONST_3
38
+ #else
39
+ #define JSI_NO_CONST_3 const
40
+ #endif
41
+
42
+ #if JSI_VERSION >= 10
43
+ #define JSI_CONST_10 const
44
+ #else
45
+ #define JSI_CONST_10
46
+ #endif
47
+
48
+ class FBJSRuntime;
49
+ namespace facebook {
50
+ namespace jsi {
51
+
52
+ /// Base class for buffers of data or bytecode that need to be passed to the
53
+ /// runtime. The buffer is expected to be fully immutable, so the result of
54
+ /// size(), data(), and the contents of the pointer returned by data() must not
55
+ /// change after construction.
56
+ class JSI_EXPORT Buffer {
57
+ public:
58
+ virtual ~Buffer();
59
+ virtual size_t size() const = 0;
60
+ virtual const uint8_t* data() const = 0;
61
+ };
62
+
63
+ class JSI_EXPORT StringBuffer : public Buffer {
64
+ public:
65
+ StringBuffer(std::string s) : s_(std::move(s)) {}
66
+ size_t size() const override {
67
+ return s_.size();
68
+ }
69
+ const uint8_t* data() const override {
70
+ return reinterpret_cast<const uint8_t*>(s_.data());
71
+ }
72
+
73
+ private:
74
+ std::string s_;
75
+ };
76
+
77
+ #if JSI_VERSION >= 9
78
+ /// Base class for buffers of data that need to be passed to the runtime. The
79
+ /// result of size() and data() must not change after construction. However, the
80
+ /// region pointed to by data() may be modified by the user or the runtime. The
81
+ /// user must ensure that access to the contents of the buffer is properly
82
+ /// synchronised.
83
+ class JSI_EXPORT MutableBuffer {
84
+ public:
85
+ virtual ~MutableBuffer();
86
+ virtual size_t size() const = 0;
87
+ virtual uint8_t* data() = 0;
88
+ };
89
+ #endif
90
+
91
+ /// PreparedJavaScript is a base class representing JavaScript which is in a
92
+ /// form optimized for execution, in a runtime-specific way. Construct one via
93
+ /// jsi::Runtime::prepareJavaScript().
94
+ /// ** This is an experimental API that is subject to change. **
95
+ class JSI_EXPORT PreparedJavaScript {
96
+ protected:
97
+ PreparedJavaScript() = default;
98
+
99
+ public:
100
+ virtual ~PreparedJavaScript() = 0;
101
+ };
102
+
103
+ class Runtime;
104
+ class Pointer;
105
+ class PropNameID;
106
+ class Symbol;
107
+ #if JSI_VERSION >= 6
108
+ class BigInt;
109
+ #endif
110
+ class String;
111
+ class Object;
112
+ class WeakObject;
113
+ class Array;
114
+ class ArrayBuffer;
115
+ class Function;
116
+ class Value;
117
+ class Instrumentation;
118
+ class Scope;
119
+ class JSIException;
120
+ class JSError;
121
+
122
+ /// A function which has this type can be registered as a function
123
+ /// callable from JavaScript using Function::createFromHostFunction().
124
+ /// When the function is called, args will point to the arguments, and
125
+ /// count will indicate how many arguments are passed. The function
126
+ /// can return a Value to the caller, or throw an exception. If a C++
127
+ /// exception is thrown, a JS Error will be created and thrown into
128
+ /// JS; if the C++ exception extends std::exception, the Error's
129
+ /// message will be whatever what() returns. Note that it is undefined whether
130
+ /// HostFunctions may or may not be called in strict mode; that is `thisVal`
131
+ /// can be any value - it will not necessarily be coerced to an object or
132
+ /// or set to the global object.
133
+ using HostFunctionType = std::function<
134
+ Value(Runtime& rt, const Value& thisVal, const Value* args, size_t count)>;
135
+
136
+ /// An object which implements this interface can be registered as an
137
+ /// Object with the JS runtime.
138
+ class JSI_EXPORT HostObject {
139
+ public:
140
+ // The C++ object's dtor will be called when the GC finalizes this
141
+ // object. (This may be as late as when the Runtime is shut down.)
142
+ // You have no control over which thread it is called on. This will
143
+ // be called from inside the GC, so it is unsafe to do any VM
144
+ // operations which require a Runtime&. Derived classes' dtors
145
+ // should also avoid doing anything expensive. Calling the dtor on
146
+ // a jsi object is explicitly ok. If you want to do JS operations,
147
+ // or any nontrivial work, you should add it to a work queue, and
148
+ // manage it externally.
149
+ virtual ~HostObject();
150
+
151
+ // When JS wants a property with a given name from the HostObject,
152
+ // it will call this method. If it throws an exception, the call
153
+ // will throw a JS \c Error object. By default this returns undefined.
154
+ // \return the value for the property.
155
+ virtual Value get(Runtime&, const PropNameID& name);
156
+
157
+ // When JS wants to set a property with a given name on the HostObject,
158
+ // it will call this method. If it throws an exception, the call will
159
+ // throw a JS \c Error object. By default this throws a type error exception
160
+ // mimicking the behavior of a frozen object in strict mode.
161
+ virtual void set(Runtime&, const PropNameID& name, const Value& value);
162
+
163
+ // When JS wants a list of property names for the HostObject, it will
164
+ // call this method. If it throws an exception, the call will throw a
165
+ // JS \c Error object. The default implementation returns empty vector.
166
+ virtual std::vector<PropNameID> getPropertyNames(Runtime& rt);
167
+ };
168
+
169
+ #if JSI_VERSION >= 7
170
+ /// Native state (and destructor) that can be attached to any JS object
171
+ /// using setNativeState.
172
+ class JSI_EXPORT NativeState {
173
+ public:
174
+ virtual ~NativeState();
175
+ };
176
+ #endif
177
+
178
+ /// Represents a JS runtime. Movable, but not copyable. Note that
179
+ /// this object may not be thread-aware, but cannot be used safely from
180
+ /// multiple threads at once. The application is responsible for
181
+ /// ensuring that it is used safely. This could mean using the
182
+ /// Runtime from a single thread, using a mutex, doing all work on a
183
+ /// serial queue, etc. This restriction applies to the methods of
184
+ /// this class, and any method in the API which take a Runtime& as an
185
+ /// argument. Destructors (all but ~Scope), operators, or other methods
186
+ /// which do not take Runtime& as an argument are safe to call from any
187
+ /// thread, but it is still forbidden to make write operations on a single
188
+ /// instance of any class from more than one thread. In addition, to
189
+ /// make shutdown safe, destruction of objects associated with the Runtime
190
+ /// must be destroyed before the Runtime is destroyed, or from the
191
+ /// destructor of a managed HostObject or HostFunction. Informally, this
192
+ /// means that the main source of unsafe behavior is to hold a jsi object
193
+ /// in a non-Runtime-managed object, and not clean it up before the Runtime
194
+ /// is shut down. If your lifecycle is such that avoiding this is hard,
195
+ /// you will probably need to do use your own locks.
196
+ class JSI_EXPORT Runtime {
197
+ public:
198
+ virtual ~Runtime();
199
+
200
+ /// Evaluates the given JavaScript \c buffer. \c sourceURL is used
201
+ /// to annotate the stack trace if there is an exception. The
202
+ /// contents may be utf8-encoded JS source code, or binary bytecode
203
+ /// whose format is specific to the implementation. If the input
204
+ /// format is unknown, or evaluation causes an error, a JSIException
205
+ /// will be thrown.
206
+ /// Note this function should ONLY be used when there isn't another means
207
+ /// through the JSI API. For example, it will be much slower to use this to
208
+ /// call a global function than using the JSI APIs to read the function
209
+ /// property from the global object and then calling it explicitly.
210
+ virtual Value evaluateJavaScript(
211
+ const std::shared_ptr<const Buffer>& buffer,
212
+ const std::string& sourceURL) = 0;
213
+
214
+ /// Prepares to evaluate the given JavaScript \c buffer by processing it into
215
+ /// a form optimized for execution. This may include pre-parsing, compiling,
216
+ /// etc. If the input is invalid (for example, cannot be parsed), a
217
+ /// JSIException will be thrown. The resulting object is tied to the
218
+ /// particular concrete type of Runtime from which it was created. It may be
219
+ /// used (via evaluatePreparedJavaScript) in any Runtime of the same concrete
220
+ /// type.
221
+ /// The PreparedJavaScript object may be passed to multiple VM instances, so
222
+ /// they can all share and benefit from the prepared script.
223
+ /// As with evaluateJavaScript(), using JavaScript code should be avoided
224
+ /// when the JSI API is sufficient.
225
+ virtual std::shared_ptr<const PreparedJavaScript> prepareJavaScript(
226
+ const std::shared_ptr<const Buffer>& buffer,
227
+ std::string sourceURL) = 0;
228
+
229
+ /// Evaluates a PreparedJavaScript. If evaluation causes an error, a
230
+ /// JSIException will be thrown.
231
+ /// As with evaluateJavaScript(), using JavaScript code should be avoided
232
+ /// when the JSI API is sufficient.
233
+ virtual Value evaluatePreparedJavaScript(
234
+ const std::shared_ptr<const PreparedJavaScript>& js) = 0;
235
+
236
+ #if JSI_VERSION >= 4
237
+ /// Drain the JavaScript VM internal Microtask (a.k.a. Job in ECMA262) queue.
238
+ ///
239
+ /// \param maxMicrotasksHint a hint to tell an implementation that it should
240
+ /// make a best effort not execute more than the given number. It's default
241
+ /// to -1 for infinity (unbounded execution).
242
+ /// \return true if the queue is drained or false if there is more work to do.
243
+ ///
244
+ /// When there were exceptions thrown from the execution of microtasks,
245
+ /// implementations shall discard the exceptional jobs. An implementation may
246
+ /// \throw a \c JSError object to signal the hosts to handle. In that case, an
247
+ /// implementation may or may not suspend the draining.
248
+ ///
249
+ /// Hosts may call this function again to resume the draining if it was
250
+ /// suspended due to either exceptions or the \p maxMicrotasksHint bound.
251
+ /// E.g. a host may repetitively invoke this function until the queue is
252
+ /// drained to implement the "microtask checkpoint" defined in WHATWG HTML
253
+ /// event loop: https://html.spec.whatwg.org/C#perform-a-microtask-checkpoint.
254
+ ///
255
+ /// Note that error propagation is only a concern if a host needs to implement
256
+ /// `queueMicrotask`, a recent API that allows enqueueing arbitrary functions
257
+ /// (hence may throw) as microtasks. Exceptions from ECMA-262 Promise Jobs are
258
+ /// handled internally to VMs and are never propagated to hosts.
259
+ ///
260
+ /// This API offers some queue management to hosts at its best effort due to
261
+ /// different behaviors and limitations imposed by different VMs and APIs. By
262
+ /// the time this is written, An implementation may swallow exceptions (JSC),
263
+ /// may not pause (V8), and may not support bounded executions.
264
+ virtual bool drainMicrotasks(int maxMicrotasksHint = -1) = 0;
265
+ #endif
266
+
267
+ /// \return the global object
268
+ virtual Object global() = 0;
269
+
270
+ /// \return a short printable description of the instance. It should
271
+ /// at least include some human-readable indication of the runtime
272
+ /// implementation. This should only be used by logging, debugging,
273
+ /// and other developer-facing callers.
274
+ virtual std::string description() = 0;
275
+
276
+ /// \return whether or not the underlying runtime supports debugging via the
277
+ /// Chrome remote debugging protocol.
278
+ ///
279
+ /// NOTE: the API for determining whether a runtime is debuggable and
280
+ /// registering a runtime with the debugger is still in flux, so please don't
281
+ /// use this API unless you know what you're doing.
282
+ virtual bool isInspectable() = 0;
283
+
284
+ /// \return an interface to extract metrics from this \c Runtime. The default
285
+ /// implementation of this function returns an \c Instrumentation instance
286
+ /// which returns no metrics.
287
+ virtual Instrumentation& instrumentation();
288
+
289
+ protected:
290
+ friend class Pointer;
291
+ friend class PropNameID;
292
+ friend class Symbol;
293
+ #if JSI_VERSION >= 6
294
+ friend class BigInt;
295
+ #endif
296
+ friend class String;
297
+ friend class Object;
298
+ friend class WeakObject;
299
+ friend class Array;
300
+ friend class ArrayBuffer;
301
+ friend class Function;
302
+ friend class Value;
303
+ friend class Scope;
304
+ friend class JSError;
305
+
306
+ // Potential optimization: avoid the cloneFoo() virtual dispatch,
307
+ // and instead just fix the number of fields, and copy them, since
308
+ // in practice they are trivially copyable. Sufficient use of
309
+ // rvalue arguments/methods would also reduce the number of clones.
310
+
311
+ struct PointerValue {
312
+ virtual void invalidate() = 0;
313
+
314
+ protected:
315
+ virtual ~PointerValue() = default;
316
+ };
317
+
318
+ virtual PointerValue* cloneSymbol(const Runtime::PointerValue* pv) = 0;
319
+ #if JSI_VERSION >= 6
320
+ virtual PointerValue* cloneBigInt(const Runtime::PointerValue* pv) = 0;
321
+ #endif
322
+ virtual PointerValue* cloneString(const Runtime::PointerValue* pv) = 0;
323
+ virtual PointerValue* cloneObject(const Runtime::PointerValue* pv) = 0;
324
+ virtual PointerValue* clonePropNameID(const Runtime::PointerValue* pv) = 0;
325
+
326
+ virtual PropNameID createPropNameIDFromAscii(
327
+ const char* str,
328
+ size_t length) = 0;
329
+ virtual PropNameID createPropNameIDFromUtf8(
330
+ const uint8_t* utf8,
331
+ size_t length) = 0;
332
+ virtual PropNameID createPropNameIDFromString(const String& str) = 0;
333
+ #if JSI_VERSION >= 5
334
+ virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0;
335
+ #endif
336
+ virtual std::string utf8(const PropNameID&) = 0;
337
+ virtual bool compare(const PropNameID&, const PropNameID&) = 0;
338
+
339
+ virtual std::string symbolToString(const Symbol&) = 0;
340
+
341
+ #if JSI_VERSION >= 8
342
+ virtual BigInt createBigIntFromInt64(int64_t) = 0;
343
+ virtual BigInt createBigIntFromUint64(uint64_t) = 0;
344
+ virtual bool bigintIsInt64(const BigInt&) = 0;
345
+ virtual bool bigintIsUint64(const BigInt&) = 0;
346
+ virtual uint64_t truncate(const BigInt&) = 0;
347
+ virtual String bigintToString(const BigInt&, int) = 0;
348
+ #endif
349
+
350
+ virtual String createStringFromAscii(const char* str, size_t length) = 0;
351
+ virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0;
352
+ virtual std::string utf8(const String&) = 0;
353
+
354
+ // \return a \c Value created from a utf8-encoded JSON string. The default
355
+ // implementation creates a \c String and invokes JSON.parse.
356
+ #if JSI_VERSION >= 2
357
+ virtual Value createValueFromJsonUtf8(const uint8_t* json, size_t length);
358
+ #endif
359
+
360
+ virtual Object createObject() = 0;
361
+ virtual Object createObject(std::shared_ptr<HostObject> ho) = 0;
362
+ virtual std::shared_ptr<HostObject> getHostObject(const jsi::Object&) = 0;
363
+ virtual HostFunctionType& getHostFunction(const jsi::Function&) = 0;
364
+
365
+ #if JSI_VERSION >= 7
366
+ virtual bool hasNativeState(const jsi::Object&) = 0;
367
+ virtual std::shared_ptr<NativeState> getNativeState(const jsi::Object&) = 0;
368
+ virtual void setNativeState(
369
+ const jsi::Object&,
370
+ std::shared_ptr<NativeState> state) = 0;
371
+ #endif
372
+
373
+ virtual Value getProperty(const Object&, const PropNameID& name) = 0;
374
+ virtual Value getProperty(const Object&, const String& name) = 0;
375
+ virtual bool hasProperty(const Object&, const PropNameID& name) = 0;
376
+ virtual bool hasProperty(const Object&, const String& name) = 0;
377
+ virtual void setPropertyValue(
378
+ JSI_CONST_10 Object&,
379
+ const PropNameID& name,
380
+ const Value& value) = 0;
381
+ virtual void setPropertyValue(
382
+ JSI_CONST_10 Object&,
383
+ const String& name,
384
+ const Value& value) = 0;
385
+
386
+ virtual bool isArray(const Object&) const = 0;
387
+ virtual bool isArrayBuffer(const Object&) const = 0;
388
+ virtual bool isFunction(const Object&) const = 0;
389
+ virtual bool isHostObject(const jsi::Object&) const = 0;
390
+ virtual bool isHostFunction(const jsi::Function&) const = 0;
391
+ virtual Array getPropertyNames(const Object&) = 0;
392
+
393
+ virtual WeakObject createWeakObject(const Object&) = 0;
394
+ virtual Value lockWeakObject(JSI_NO_CONST_3 JSI_CONST_10 WeakObject&) = 0;
395
+
396
+ virtual Array createArray(size_t length) = 0;
397
+ #if JSI_VERSION >= 9
398
+ virtual ArrayBuffer createArrayBuffer(
399
+ std::shared_ptr<MutableBuffer> buffer) = 0;
400
+ #endif
401
+ virtual size_t size(const Array&) = 0;
402
+ virtual size_t size(const ArrayBuffer&) = 0;
403
+ virtual uint8_t* data(const ArrayBuffer&) = 0;
404
+ virtual Value getValueAtIndex(const Array&, size_t i) = 0;
405
+ virtual void
406
+ setValueAtIndexImpl(JSI_CONST_10 Array&, size_t i, const Value& value) = 0;
407
+
408
+ virtual Function createFunctionFromHostFunction(
409
+ const PropNameID& name,
410
+ unsigned int paramCount,
411
+ HostFunctionType func) = 0;
412
+ virtual Value call(
413
+ const Function&,
414
+ const Value& jsThis,
415
+ const Value* args,
416
+ size_t count) = 0;
417
+ virtual Value
418
+ callAsConstructor(const Function&, const Value* args, size_t count) = 0;
419
+
420
+ // Private data for managing scopes.
421
+ struct ScopeState;
422
+ virtual ScopeState* pushScope();
423
+ virtual void popScope(ScopeState*);
424
+
425
+ virtual bool strictEquals(const Symbol& a, const Symbol& b) const = 0;
426
+ #if JSI_VERSION >= 6
427
+ virtual bool strictEquals(const BigInt& a, const BigInt& b) const = 0;
428
+ #endif
429
+ virtual bool strictEquals(const String& a, const String& b) const = 0;
430
+ virtual bool strictEquals(const Object& a, const Object& b) const = 0;
431
+
432
+ virtual bool instanceOf(const Object& o, const Function& f) = 0;
433
+
434
+ #if JSI_VERSION >= 11
435
+ /// See Object::setExternalMemoryPressure.
436
+ virtual void setExternalMemoryPressure(
437
+ const jsi::Object& obj,
438
+ size_t amount) = 0;
439
+ #endif
440
+
441
+ // These exist so derived classes can access the private parts of
442
+ // Value, Symbol, String, and Object, which are all friends of Runtime.
443
+ template <typename T>
444
+ static T make(PointerValue* pv);
445
+ #if JSI_VERSION >= 3
446
+ static PointerValue* getPointerValue(Pointer& pointer);
447
+ #endif
448
+ static const PointerValue* getPointerValue(const Pointer& pointer);
449
+ static const PointerValue* getPointerValue(const Value& value);
450
+
451
+ friend class ::FBJSRuntime;
452
+ template <typename Plain, typename Base>
453
+ friend class RuntimeDecorator;
454
+ };
455
+
456
+ // Base class for pointer-storing types.
457
+ class JSI_EXPORT Pointer {
458
+ protected:
459
+ explicit Pointer(Pointer&& other) : ptr_(other.ptr_) {
460
+ other.ptr_ = nullptr;
461
+ }
462
+
463
+ ~Pointer() {
464
+ if (ptr_) {
465
+ ptr_->invalidate();
466
+ }
467
+ }
468
+
469
+ Pointer& operator=(Pointer&& other);
470
+
471
+ friend class Runtime;
472
+ friend class Value;
473
+
474
+ explicit Pointer(Runtime::PointerValue* ptr) : ptr_(ptr) {}
475
+
476
+ typename Runtime::PointerValue* ptr_;
477
+ };
478
+
479
+ /// Represents something that can be a JS property key. Movable, not copyable.
480
+ class JSI_EXPORT PropNameID : public Pointer {
481
+ public:
482
+ using Pointer::Pointer;
483
+
484
+ PropNameID(Runtime& runtime, const PropNameID& other)
485
+ : Pointer(runtime.clonePropNameID(other.ptr_)) {}
486
+
487
+ PropNameID(PropNameID&& other) = default;
488
+ PropNameID& operator=(PropNameID&& other) = default;
489
+
490
+ /// Create a JS property name id from ascii values. The data is
491
+ /// copied.
492
+ static PropNameID forAscii(Runtime& runtime, const char* str, size_t length) {
493
+ return runtime.createPropNameIDFromAscii(str, length);
494
+ }
495
+
496
+ /// Create a property name id from a nul-terminated C ascii name. The data is
497
+ /// copied.
498
+ static PropNameID forAscii(Runtime& runtime, const char* str) {
499
+ return forAscii(runtime, str, strlen(str));
500
+ }
501
+
502
+ /// Create a PropNameID from a C++ string. The string is copied.
503
+ static PropNameID forAscii(Runtime& runtime, const std::string& str) {
504
+ return forAscii(runtime, str.c_str(), str.size());
505
+ }
506
+
507
+ /// Create a PropNameID from utf8 values. The data is copied.
508
+ /// Results are undefined if \p utf8 contains invalid code points.
509
+ static PropNameID
510
+ forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
511
+ return runtime.createPropNameIDFromUtf8(utf8, length);
512
+ }
513
+
514
+ /// Create a PropNameID from utf8-encoded octets stored in a
515
+ /// std::string. The string data is transformed and copied.
516
+ /// Results are undefined if \p utf8 contains invalid code points.
517
+ static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) {
518
+ return runtime.createPropNameIDFromUtf8(
519
+ reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
520
+ }
521
+
522
+ /// Create a PropNameID from a JS string.
523
+ static PropNameID forString(Runtime& runtime, const jsi::String& str) {
524
+ return runtime.createPropNameIDFromString(str);
525
+ }
526
+
527
+ #if JSI_VERSION >= 5
528
+ /// Create a PropNameID from a JS symbol.
529
+ static PropNameID forSymbol(Runtime& runtime, const jsi::Symbol& sym) {
530
+ return runtime.createPropNameIDFromSymbol(sym);
531
+ }
532
+ #endif
533
+
534
+ // Creates a vector of PropNameIDs constructed from given arguments.
535
+ template <typename... Args>
536
+ static std::vector<PropNameID> names(Runtime& runtime, Args&&... args);
537
+
538
+ // Creates a vector of given PropNameIDs.
539
+ template <size_t N>
540
+ static std::vector<PropNameID> names(PropNameID (&&propertyNames)[N]);
541
+
542
+ /// Copies the data in a PropNameID as utf8 into a C++ string.
543
+ std::string utf8(Runtime& runtime) const {
544
+ return runtime.utf8(*this);
545
+ }
546
+
547
+ static bool compare(
548
+ Runtime& runtime,
549
+ const jsi::PropNameID& a,
550
+ const jsi::PropNameID& b) {
551
+ return runtime.compare(a, b);
552
+ }
553
+
554
+ friend class Runtime;
555
+ friend class Value;
556
+ };
557
+
558
+ /// Represents a JS Symbol (es6). Movable, not copyable.
559
+ /// TODO T40778724: this is a limited implementation sufficient for
560
+ /// the debugger not to crash when a Symbol is a property in an Object
561
+ /// or element in an array. Complete support for creating will come
562
+ /// later.
563
+ class JSI_EXPORT Symbol : public Pointer {
564
+ public:
565
+ using Pointer::Pointer;
566
+
567
+ Symbol(Symbol&& other) = default;
568
+ Symbol& operator=(Symbol&& other) = default;
569
+
570
+ /// \return whether a and b refer to the same symbol.
571
+ static bool strictEquals(Runtime& runtime, const Symbol& a, const Symbol& b) {
572
+ return runtime.strictEquals(a, b);
573
+ }
574
+
575
+ /// Converts a Symbol into a C++ string as JS .toString would. The output
576
+ /// will look like \c Symbol(description) .
577
+ std::string toString(Runtime& runtime) const {
578
+ return runtime.symbolToString(*this);
579
+ }
580
+
581
+ friend class Runtime;
582
+ friend class Value;
583
+ };
584
+
585
+ #if JSI_VERSION >= 6
586
+ /// Represents a JS BigInt. Movable, not copyable.
587
+ class JSI_EXPORT BigInt : public Pointer {
588
+ public:
589
+ using Pointer::Pointer;
590
+
591
+ BigInt(BigInt&& other) = default;
592
+ BigInt& operator=(BigInt&& other) = default;
593
+
594
+ #if JSI_VERSION >= 8
595
+ /// Create a BigInt representing the signed 64-bit \p value.
596
+ static BigInt fromInt64(Runtime& runtime, int64_t value) {
597
+ return runtime.createBigIntFromInt64(value);
598
+ }
599
+
600
+ /// Create a BigInt representing the unsigned 64-bit \p value.
601
+ static BigInt fromUint64(Runtime& runtime, uint64_t value) {
602
+ return runtime.createBigIntFromUint64(value);
603
+ }
604
+
605
+ /// \return whether a === b.
606
+ static bool strictEquals(Runtime& runtime, const BigInt& a, const BigInt& b) {
607
+ return runtime.strictEquals(a, b);
608
+ }
609
+
610
+ /// \returns This bigint truncated to a signed 64-bit integer.
611
+ int64_t getInt64(Runtime& runtime) const {
612
+ return runtime.truncate(*this);
613
+ }
614
+
615
+ /// \returns Whether this bigint can be losslessly converted to int64_t.
616
+ bool isInt64(Runtime& runtime) const {
617
+ return runtime.bigintIsInt64(*this);
618
+ }
619
+
620
+ /// \returns This bigint truncated to a signed 64-bit integer. Throws a
621
+ /// JSIException if the truncation is lossy.
622
+ int64_t asInt64(Runtime& runtime) const;
623
+
624
+ /// \returns This bigint truncated to an unsigned 64-bit integer.
625
+ uint64_t getUint64(Runtime& runtime) const {
626
+ return runtime.truncate(*this);
627
+ }
628
+
629
+ /// \returns Whether this bigint can be losslessly converted to uint64_t.
630
+ bool isUint64(Runtime& runtime) const {
631
+ return runtime.bigintIsUint64(*this);
632
+ }
633
+
634
+ /// \returns This bigint truncated to an unsigned 64-bit integer. Throws a
635
+ /// JSIException if the truncation is lossy.
636
+ uint64_t asUint64(Runtime& runtime) const;
637
+
638
+ /// \returns this BigInt converted to a String in base \p radix. Throws a
639
+ /// JSIException if radix is not in the [2, 36] range.
640
+ inline String toString(Runtime& runtime, int radix = 10) const;
641
+ #endif
642
+
643
+ friend class Runtime;
644
+ friend class Value;
645
+ };
646
+ #endif
647
+
648
+ /// Represents a JS String. Movable, not copyable.
649
+ class JSI_EXPORT String : public Pointer {
650
+ public:
651
+ using Pointer::Pointer;
652
+
653
+ String(String&& other) = default;
654
+ String& operator=(String&& other) = default;
655
+
656
+ /// Create a JS string from ascii values. The string data is
657
+ /// copied.
658
+ static String
659
+ createFromAscii(Runtime& runtime, const char* str, size_t length) {
660
+ return runtime.createStringFromAscii(str, length);
661
+ }
662
+
663
+ /// Create a JS string from a nul-terminated C ascii string. The
664
+ /// string data is copied.
665
+ static String createFromAscii(Runtime& runtime, const char* str) {
666
+ return createFromAscii(runtime, str, strlen(str));
667
+ }
668
+
669
+ /// Create a JS string from a C++ string. The string data is
670
+ /// copied.
671
+ static String createFromAscii(Runtime& runtime, const std::string& str) {
672
+ return createFromAscii(runtime, str.c_str(), str.size());
673
+ }
674
+
675
+ /// Create a JS string from utf8-encoded octets. The string data is
676
+ /// transformed and copied. Results are undefined if \p utf8 contains invalid
677
+ /// code points.
678
+ static String
679
+ createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
680
+ return runtime.createStringFromUtf8(utf8, length);
681
+ }
682
+
683
+ /// Create a JS string from utf8-encoded octets stored in a
684
+ /// std::string. The string data is transformed and copied. Results are
685
+ /// undefined if \p utf8 contains invalid code points.
686
+ static String createFromUtf8(Runtime& runtime, const std::string& utf8) {
687
+ return runtime.createStringFromUtf8(
688
+ reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
689
+ }
690
+
691
+ /// \return whether a and b contain the same characters.
692
+ static bool strictEquals(Runtime& runtime, const String& a, const String& b) {
693
+ return runtime.strictEquals(a, b);
694
+ }
695
+
696
+ /// Copies the data in a JS string as utf8 into a C++ string.
697
+ std::string utf8(Runtime& runtime) const {
698
+ return runtime.utf8(*this);
699
+ }
700
+
701
+ friend class Runtime;
702
+ friend class Value;
703
+ };
704
+
705
+ class Array;
706
+ class Function;
707
+
708
+ /// Represents a JS Object. Movable, not copyable.
709
+ class JSI_EXPORT Object : public Pointer {
710
+ public:
711
+ using Pointer::Pointer;
712
+
713
+ Object(Object&& other) = default;
714
+ Object& operator=(Object&& other) = default;
715
+
716
+ /// Creates a new Object instance, like '{}' in JS.
717
+ Object(Runtime& runtime) : Object(runtime.createObject()) {}
718
+
719
+ static Object createFromHostObject(
720
+ Runtime& runtime,
721
+ std::shared_ptr<HostObject> ho) {
722
+ return runtime.createObject(ho);
723
+ }
724
+
725
+ /// \return whether this and \c obj are the same JSObject or not.
726
+ static bool strictEquals(Runtime& runtime, const Object& a, const Object& b) {
727
+ return runtime.strictEquals(a, b);
728
+ }
729
+
730
+ /// \return the result of `this instanceOf ctor` in JS.
731
+ bool instanceOf(Runtime& rt, const Function& ctor) JSI_CONST_10 {
732
+ return rt.instanceOf(*this, ctor);
733
+ }
734
+
735
+ /// \return the property of the object with the given ascii name.
736
+ /// If the name isn't a property on the object, returns the
737
+ /// undefined value.
738
+ Value getProperty(Runtime& runtime, const char* name) const;
739
+
740
+ /// \return the property of the object with the String name.
741
+ /// If the name isn't a property on the object, returns the
742
+ /// undefined value.
743
+ Value getProperty(Runtime& runtime, const String& name) const;
744
+
745
+ /// \return the property of the object with the given JS PropNameID
746
+ /// name. If the name isn't a property on the object, returns the
747
+ /// undefined value.
748
+ Value getProperty(Runtime& runtime, const PropNameID& name) const;
749
+
750
+ /// \return true if and only if the object has a property with the
751
+ /// given ascii name.
752
+ bool hasProperty(Runtime& runtime, const char* name) const;
753
+
754
+ /// \return true if and only if the object has a property with the
755
+ /// given String name.
756
+ bool hasProperty(Runtime& runtime, const String& name) const;
757
+
758
+ /// \return true if and only if the object has a property with the
759
+ /// given PropNameID name.
760
+ bool hasProperty(Runtime& runtime, const PropNameID& name) const;
761
+
762
+ /// Sets the property value from a Value or anything which can be
763
+ /// used to make one: nullptr_t, bool, double, int, const char*,
764
+ /// String, or Object.
765
+ template <typename T>
766
+ void setProperty(Runtime& runtime, const char* name, T&& value) JSI_CONST_10;
767
+
768
+ /// Sets the property value from a Value or anything which can be
769
+ /// used to make one: nullptr_t, bool, double, int, const char*,
770
+ /// String, or Object.
771
+ template <typename T>
772
+ void setProperty(Runtime& runtime, const String& name, T&& value)
773
+ JSI_CONST_10;
774
+
775
+ /// Sets the property value from a Value or anything which can be
776
+ /// used to make one: nullptr_t, bool, double, int, const char*,
777
+ /// String, or Object.
778
+ template <typename T>
779
+ void setProperty(Runtime& runtime, const PropNameID& name, T&& value)
780
+ JSI_CONST_10;
781
+
782
+ /// \return true iff JS \c Array.isArray() would return \c true. If
783
+ /// so, then \c getArray() will succeed.
784
+ bool isArray(Runtime& runtime) const {
785
+ return runtime.isArray(*this);
786
+ }
787
+
788
+ /// \return true iff the Object is an ArrayBuffer. If so, then \c
789
+ /// getArrayBuffer() will succeed.
790
+ bool isArrayBuffer(Runtime& runtime) const {
791
+ return runtime.isArrayBuffer(*this);
792
+ }
793
+
794
+ /// \return true iff the Object is callable. If so, then \c
795
+ /// getFunction will succeed.
796
+ bool isFunction(Runtime& runtime) const {
797
+ return runtime.isFunction(*this);
798
+ }
799
+
800
+ /// \return true iff the Object was initialized with \c createFromHostObject
801
+ /// and the HostObject passed is of type \c T. If returns \c true then
802
+ /// \c getHostObject<T> will succeed.
803
+ template <typename T = HostObject>
804
+ bool isHostObject(Runtime& runtime) const;
805
+
806
+ /// \return an Array instance which refers to the same underlying
807
+ /// object. If \c isArray() would return false, this will assert.
808
+ Array getArray(Runtime& runtime) const&;
809
+
810
+ /// \return an Array instance which refers to the same underlying
811
+ /// object. If \c isArray() would return false, this will assert.
812
+ Array getArray(Runtime& runtime) &&;
813
+
814
+ /// \return an Array instance which refers to the same underlying
815
+ /// object. If \c isArray() would return false, this will throw
816
+ /// JSIException.
817
+ Array asArray(Runtime& runtime) const&;
818
+
819
+ /// \return an Array instance which refers to the same underlying
820
+ /// object. If \c isArray() would return false, this will throw
821
+ /// JSIException.
822
+ Array asArray(Runtime& runtime) &&;
823
+
824
+ /// \return an ArrayBuffer instance which refers to the same underlying
825
+ /// object. If \c isArrayBuffer() would return false, this will assert.
826
+ ArrayBuffer getArrayBuffer(Runtime& runtime) const&;
827
+
828
+ /// \return an ArrayBuffer instance which refers to the same underlying
829
+ /// object. If \c isArrayBuffer() would return false, this will assert.
830
+ ArrayBuffer getArrayBuffer(Runtime& runtime) &&;
831
+
832
+ /// \return a Function instance which refers to the same underlying
833
+ /// object. If \c isFunction() would return false, this will assert.
834
+ Function getFunction(Runtime& runtime) const&;
835
+
836
+ /// \return a Function instance which refers to the same underlying
837
+ /// object. If \c isFunction() would return false, this will assert.
838
+ Function getFunction(Runtime& runtime) &&;
839
+
840
+ /// \return a Function instance which refers to the same underlying
841
+ /// object. If \c isFunction() would return false, this will throw
842
+ /// JSIException.
843
+ Function asFunction(Runtime& runtime) const&;
844
+
845
+ /// \return a Function instance which refers to the same underlying
846
+ /// object. If \c isFunction() would return false, this will throw
847
+ /// JSIException.
848
+ Function asFunction(Runtime& runtime) &&;
849
+
850
+ /// \return a shared_ptr<T> which refers to the same underlying
851
+ /// \c HostObject that was used to create this object. If \c isHostObject<T>
852
+ /// is false, this will assert. Note that this does a type check and will
853
+ /// assert if the underlying HostObject isn't of type \c T
854
+ template <typename T = HostObject>
855
+ std::shared_ptr<T> getHostObject(Runtime& runtime) const;
856
+
857
+ /// \return a shared_ptr<T> which refers to the same underlying
858
+ /// \c HostObject that was used to create this object. If \c isHostObject<T>
859
+ /// is false, this will throw.
860
+ template <typename T = HostObject>
861
+ std::shared_ptr<T> asHostObject(Runtime& runtime) const;
862
+
863
+ #if JSI_VERSION >= 7
864
+ /// \return whether this object has native state of type T previously set by
865
+ /// \c setNativeState.
866
+ template <typename T = NativeState>
867
+ bool hasNativeState(Runtime& runtime) const;
868
+
869
+ /// \return a shared_ptr to the state previously set by \c setNativeState.
870
+ /// If \c hasNativeState<T> is false, this will assert. Note that this does a
871
+ /// type check and will assert if the native state isn't of type \c T
872
+ template <typename T = NativeState>
873
+ std::shared_ptr<T> getNativeState(Runtime& runtime) const;
874
+
875
+ /// Set the internal native state property of this object, overwriting any old
876
+ /// value. Creates a new shared_ptr to the object managed by \p state, which
877
+ /// will live until the value at this property becomes unreachable.
878
+ ///
879
+ /// Throws a type error if this object is a proxy or host object.
880
+ void setNativeState(Runtime& runtime, std::shared_ptr<NativeState> state)
881
+ const;
882
+ #endif
883
+
884
+ /// \return same as \c getProperty(name).asObject(), except with
885
+ /// a better exception message.
886
+ Object getPropertyAsObject(Runtime& runtime, const char* name) const;
887
+
888
+ /// \return similar to \c
889
+ /// getProperty(name).getObject().getFunction(), except it will
890
+ /// throw JSIException instead of asserting if the property is
891
+ /// not an object, or the object is not callable.
892
+ Function getPropertyAsFunction(Runtime& runtime, const char* name) const;
893
+
894
+ /// \return an Array consisting of all enumerable property names in
895
+ /// the object and its prototype chain. All values in the return
896
+ /// will be isString(). (This is probably not optimal, but it
897
+ /// works. I only need it in one place.)
898
+ Array getPropertyNames(Runtime& runtime) const;
899
+
900
+ #if JSI_VERSION >= 11
901
+ /// Inform the runtime that there is additional memory associated with a given
902
+ /// JavaScript object that is not visible to the GC. This can be used if an
903
+ /// object is known to retain some native memory, and may be used to guide
904
+ /// decisions about when to run garbage collection.
905
+ /// This method may be invoked multiple times on an object, and subsequent
906
+ /// calls will overwrite any previously set value. Once the object is garbage
907
+ /// collected, the associated external memory will be considered freed and may
908
+ /// no longer factor into GC decisions.
909
+ void setExternalMemoryPressure(Runtime& runtime, size_t amt) const;
910
+ #endif
911
+
912
+ protected:
913
+ void setPropertyValue(
914
+ Runtime& runtime,
915
+ const String& name,
916
+ const Value& value) JSI_CONST_10 {
917
+ return runtime.setPropertyValue(*this, name, value);
918
+ }
919
+
920
+ void setPropertyValue(
921
+ Runtime& runtime,
922
+ const PropNameID& name,
923
+ const Value& value) JSI_CONST_10 {
924
+ return runtime.setPropertyValue(*this, name, value);
925
+ }
926
+
927
+ friend class Runtime;
928
+ friend class Value;
929
+ };
930
+
931
+ /// Represents a weak reference to a JS Object. If the only reference
932
+ /// to an Object are these, the object is eligible for GC. Method
933
+ /// names are inspired by C++ weak_ptr. Movable, not copyable.
934
+ class JSI_EXPORT WeakObject : public Pointer {
935
+ public:
936
+ using Pointer::Pointer;
937
+
938
+ WeakObject(WeakObject&& other) = default;
939
+ WeakObject& operator=(WeakObject&& other) = default;
940
+
941
+ /// Create a WeakObject from an Object.
942
+ WeakObject(Runtime& runtime, const Object& o)
943
+ : WeakObject(runtime.createWeakObject(o)) {}
944
+
945
+ /// \return a Value representing the underlying Object if it is still valid;
946
+ /// otherwise returns \c undefined. Note that this method has nothing to do
947
+ /// with threads or concurrency. The name is based on std::weak_ptr::lock()
948
+ /// which serves a similar purpose.
949
+ Value lock(Runtime& runtime) JSI_CONST_10;
950
+
951
+ friend class Runtime;
952
+ };
953
+
954
+ /// Represents a JS Object which can be efficiently used as an array
955
+ /// with integral indices.
956
+ class JSI_EXPORT Array : public Object {
957
+ public:
958
+ Array(Array&&) = default;
959
+ /// Creates a new Array instance, with \c length undefined elements.
960
+ Array(Runtime& runtime, size_t length) : Array(runtime.createArray(length)) {}
961
+
962
+ Array& operator=(Array&&) = default;
963
+
964
+ /// \return the size of the Array, according to its length property.
965
+ /// (C++ naming convention)
966
+ size_t size(Runtime& runtime) const {
967
+ return runtime.size(*this);
968
+ }
969
+
970
+ /// \return the size of the Array, according to its length property.
971
+ /// (JS naming convention)
972
+ size_t length(Runtime& runtime) const {
973
+ return size(runtime);
974
+ }
975
+
976
+ /// \return the property of the array at index \c i. If there is no
977
+ /// such property, returns the undefined value. If \c i is out of
978
+ /// range [ 0..\c length ] throws a JSIException.
979
+ Value getValueAtIndex(Runtime& runtime, size_t i) const;
980
+
981
+ /// Sets the property of the array at index \c i. The argument
982
+ /// value behaves as with Object::setProperty(). If \c i is out of
983
+ /// range [ 0..\c length ] throws a JSIException.
984
+ template <typename T>
985
+ void setValueAtIndex(Runtime& runtime, size_t i, T&& value) JSI_CONST_10;
986
+
987
+ /// There is no current API for changing the size of an array once
988
+ /// created. We'll probably need that eventually.
989
+
990
+ /// Creates a new Array instance from provided values
991
+ template <typename... Args>
992
+ static Array createWithElements(Runtime&, Args&&... args);
993
+
994
+ /// Creates a new Array instance from initializer list.
995
+ static Array createWithElements(
996
+ Runtime& runtime,
997
+ std::initializer_list<Value> elements);
998
+
999
+ private:
1000
+ friend class Object;
1001
+ friend class Value;
1002
+ friend class Runtime;
1003
+
1004
+ void setValueAtIndexImpl(Runtime& runtime, size_t i, const Value& value)
1005
+ JSI_CONST_10 {
1006
+ return runtime.setValueAtIndexImpl(*this, i, value);
1007
+ }
1008
+
1009
+ Array(Runtime::PointerValue* value) : Object(value) {}
1010
+ };
1011
+
1012
+ /// Represents a JSArrayBuffer
1013
+ class JSI_EXPORT ArrayBuffer : public Object {
1014
+ public:
1015
+ ArrayBuffer(ArrayBuffer&&) = default;
1016
+ ArrayBuffer& operator=(ArrayBuffer&&) = default;
1017
+
1018
+ #if JSI_VERSION >= 9
1019
+ ArrayBuffer(Runtime& runtime, std::shared_ptr<MutableBuffer> buffer)
1020
+ : ArrayBuffer(runtime.createArrayBuffer(std::move(buffer))) {}
1021
+ #endif
1022
+
1023
+ /// \return the size of the ArrayBuffer storage. This is not affected by
1024
+ /// overriding the byteLength property.
1025
+ /// (C++ naming convention)
1026
+ size_t size(Runtime& runtime) const {
1027
+ return runtime.size(*this);
1028
+ }
1029
+
1030
+ size_t length(Runtime& runtime) const {
1031
+ return runtime.size(*this);
1032
+ }
1033
+
1034
+ uint8_t* data(Runtime& runtime) JSI_CONST_10 {
1035
+ return runtime.data(*this);
1036
+ }
1037
+
1038
+ private:
1039
+ friend class Object;
1040
+ friend class Value;
1041
+ friend class Runtime;
1042
+
1043
+ ArrayBuffer(Runtime::PointerValue* value) : Object(value) {}
1044
+ };
1045
+
1046
+ /// Represents a JS Object which is guaranteed to be Callable.
1047
+ class JSI_EXPORT Function : public Object {
1048
+ public:
1049
+ Function(Function&&) = default;
1050
+ Function& operator=(Function&&) = default;
1051
+
1052
+ /// Create a function which, when invoked, calls C++ code. If the
1053
+ /// function throws an exception, a JS Error will be created and
1054
+ /// thrown.
1055
+ /// \param name the name property for the function.
1056
+ /// \param paramCount the length property for the function, which
1057
+ /// may not be the number of arguments the function is passed.
1058
+ static Function createFromHostFunction(
1059
+ Runtime& runtime,
1060
+ const jsi::PropNameID& name,
1061
+ unsigned int paramCount,
1062
+ jsi::HostFunctionType func);
1063
+
1064
+ /// Calls the function with \c count \c args. The \c this value of the JS
1065
+ /// function will not be set by the C++ caller, similar to calling
1066
+ /// Function.prototype.apply(undefined, args) in JS.
1067
+ /// \b Note: as with Function.prototype.apply, \c this may not always be
1068
+ /// \c undefined in the function itself. If the function is non-strict,
1069
+ /// \c this will be set to the global object.
1070
+ Value call(Runtime& runtime, const Value* args, size_t count) const;
1071
+
1072
+ /// Calls the function with a \c std::initializer_list of Value
1073
+ /// arguments. The \c this value of the JS function will not be set by the
1074
+ /// C++ caller, similar to calling Function.prototype.apply(undefined, args)
1075
+ /// in JS.
1076
+ /// \b Note: as with Function.prototype.apply, \c this may not always be
1077
+ /// \c undefined in the function itself. If the function is non-strict,
1078
+ /// \c this will be set to the global object.
1079
+ Value call(Runtime& runtime, std::initializer_list<Value> args) const;
1080
+
1081
+ /// Calls the function with any number of arguments similarly to
1082
+ /// Object::setProperty(). The \c this value of the JS function will not be
1083
+ /// set by the C++ caller, similar to calling
1084
+ /// Function.prototype.call(undefined, ...args) in JS.
1085
+ /// \b Note: as with Function.prototype.call, \c this may not always be
1086
+ /// \c undefined in the function itself. If the function is non-strict,
1087
+ /// \c this will be set to the global object.
1088
+ template <typename... Args>
1089
+ Value call(Runtime& runtime, Args&&... args) const;
1090
+
1091
+ /// Calls the function with \c count \c args and \c jsThis value passed
1092
+ /// as the \c this value.
1093
+ Value callWithThis(
1094
+ Runtime& Runtime,
1095
+ const Object& jsThis,
1096
+ const Value* args,
1097
+ size_t count) const;
1098
+
1099
+ /// Calls the function with a \c std::initializer_list of Value
1100
+ /// arguments and \c jsThis passed as the \c this value.
1101
+ Value callWithThis(
1102
+ Runtime& runtime,
1103
+ const Object& jsThis,
1104
+ std::initializer_list<Value> args) const;
1105
+
1106
+ /// Calls the function with any number of arguments similarly to
1107
+ /// Object::setProperty(), and with \c jsThis passed as the \c this value.
1108
+ template <typename... Args>
1109
+ Value callWithThis(Runtime& runtime, const Object& jsThis, Args&&... args)
1110
+ const;
1111
+
1112
+ /// Calls the function as a constructor with \c count \c args. Equivalent
1113
+ /// to calling `new Func` where `Func` is the js function reqresented by
1114
+ /// this.
1115
+ Value callAsConstructor(Runtime& runtime, const Value* args, size_t count)
1116
+ const;
1117
+
1118
+ /// Same as above `callAsConstructor`, except use an initializer_list to
1119
+ /// supply the arguments.
1120
+ Value callAsConstructor(Runtime& runtime, std::initializer_list<Value> args)
1121
+ const;
1122
+
1123
+ /// Same as above `callAsConstructor`, but automatically converts/wraps
1124
+ /// any argument with a jsi Value.
1125
+ template <typename... Args>
1126
+ Value callAsConstructor(Runtime& runtime, Args&&... args) const;
1127
+
1128
+ /// Returns whether this was created with Function::createFromHostFunction.
1129
+ /// If true then you can use getHostFunction to get the underlying
1130
+ /// HostFunctionType.
1131
+ bool isHostFunction(Runtime& runtime) const {
1132
+ return runtime.isHostFunction(*this);
1133
+ }
1134
+
1135
+ /// Returns the underlying HostFunctionType iff isHostFunction returns true
1136
+ /// and asserts otherwise. You can use this to use std::function<>::target
1137
+ /// to get the object that was passed to create the HostFunctionType.
1138
+ ///
1139
+ /// Note: The reference returned is borrowed from the JS object underlying
1140
+ /// \c this, and thus only lasts as long as the object underlying
1141
+ /// \c this does.
1142
+ HostFunctionType& getHostFunction(Runtime& runtime) const {
1143
+ assert(isHostFunction(runtime));
1144
+ return runtime.getHostFunction(*this);
1145
+ }
1146
+
1147
+ private:
1148
+ friend class Object;
1149
+ friend class Value;
1150
+ friend class Runtime;
1151
+
1152
+ Function(Runtime::PointerValue* value) : Object(value) {}
1153
+ };
1154
+
1155
+ /// Represents any JS Value (undefined, null, boolean, number, symbol,
1156
+ /// string, or object). Movable, or explicitly copyable (has no copy
1157
+ /// ctor).
1158
+ class JSI_EXPORT Value {
1159
+ public:
1160
+ /// Default ctor creates an \c undefined JS value.
1161
+ Value() : Value(UndefinedKind) {}
1162
+
1163
+ /// Creates a \c null JS value.
1164
+ /* implicit */ Value(std::nullptr_t) : kind_(NullKind) {}
1165
+
1166
+ /// Creates a boolean JS value.
1167
+ /* implicit */ Value(bool b) : Value(BooleanKind) {
1168
+ data_.boolean = b;
1169
+ }
1170
+
1171
+ /// Creates a number JS value.
1172
+ /* implicit */ Value(double d) : Value(NumberKind) {
1173
+ data_.number = d;
1174
+ }
1175
+
1176
+ /// Creates a number JS value.
1177
+ /* implicit */ Value(int i) : Value(NumberKind) {
1178
+ data_.number = i;
1179
+ }
1180
+
1181
+ /// Moves a Symbol, String, or Object rvalue into a new JS value.
1182
+ template <
1183
+ typename T,
1184
+ typename = std::enable_if_t<
1185
+ std::is_base_of<Symbol, T>::value ||
1186
+ #if JSI_VERSION >= 6
1187
+ std::is_base_of<BigInt, T>::value ||
1188
+ #endif
1189
+ std::is_base_of<String, T>::value ||
1190
+ std::is_base_of<Object, T>::value>>
1191
+ /* implicit */ Value(T&& other) : Value(kindOf(other)) {
1192
+ new (&data_.pointer) T(std::move(other));
1193
+ }
1194
+
1195
+ /// Value("foo") will treat foo as a bool. This makes doing that a
1196
+ /// compile error.
1197
+ template <typename T = void>
1198
+ Value(const char*) {
1199
+ static_assert(
1200
+ !std::is_same<void, T>::value,
1201
+ "Value cannot be constructed directly from const char*");
1202
+ }
1203
+
1204
+ Value(Value&& value);
1205
+
1206
+ /// Copies a Symbol lvalue into a new JS value.
1207
+ Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) {
1208
+ new (&data_.pointer) Symbol(runtime.cloneSymbol(sym.ptr_));
1209
+ }
1210
+
1211
+ #if JSI_VERSION >= 6
1212
+ /// Copies a BigInt lvalue into a new JS value.
1213
+ Value(Runtime& runtime, const BigInt& bigint) : Value(BigIntKind) {
1214
+ new (&data_.pointer) BigInt(runtime.cloneBigInt(bigint.ptr_));
1215
+ }
1216
+ #endif
1217
+
1218
+ /// Copies a String lvalue into a new JS value.
1219
+ Value(Runtime& runtime, const String& str) : Value(StringKind) {
1220
+ new (&data_.pointer) String(runtime.cloneString(str.ptr_));
1221
+ }
1222
+
1223
+ /// Copies a Object lvalue into a new JS value.
1224
+ Value(Runtime& runtime, const Object& obj) : Value(ObjectKind) {
1225
+ new (&data_.pointer) Object(runtime.cloneObject(obj.ptr_));
1226
+ }
1227
+
1228
+ /// Creates a JS value from another Value lvalue.
1229
+ Value(Runtime& runtime, const Value& value);
1230
+
1231
+ /// Value(rt, "foo") will treat foo as a bool. This makes doing
1232
+ /// that a compile error.
1233
+ template <typename T = void>
1234
+ Value(Runtime&, const char*) {
1235
+ static_assert(
1236
+ !std::is_same<T, void>::value,
1237
+ "Value cannot be constructed directly from const char*");
1238
+ }
1239
+
1240
+ ~Value();
1241
+ // \return the undefined \c Value.
1242
+ static Value undefined() {
1243
+ return Value();
1244
+ }
1245
+
1246
+ // \return the null \c Value.
1247
+ static Value null() {
1248
+ return Value(nullptr);
1249
+ }
1250
+
1251
+ // \return a \c Value created from a utf8-encoded JSON string.
1252
+ static Value
1253
+ createFromJsonUtf8(Runtime& runtime, const uint8_t* json, size_t length)
1254
+ #if JSI_VERSION >= 2
1255
+ {
1256
+ return runtime.createValueFromJsonUtf8(json, length);
1257
+ }
1258
+ #else
1259
+ ;
1260
+ #endif
1261
+
1262
+ /// \return according to the Strict Equality Comparison algorithm, see:
1263
+ /// https://262.ecma-international.org/11.0/#sec-strict-equality-comparison
1264
+ static bool strictEquals(Runtime& runtime, const Value& a, const Value& b);
1265
+
1266
+ Value& operator=(Value&& other) {
1267
+ this->~Value();
1268
+ new (this) Value(std::move(other));
1269
+ return *this;
1270
+ }
1271
+
1272
+ bool isUndefined() const {
1273
+ return kind_ == UndefinedKind;
1274
+ }
1275
+
1276
+ bool isNull() const {
1277
+ return kind_ == NullKind;
1278
+ }
1279
+
1280
+ bool isBool() const {
1281
+ return kind_ == BooleanKind;
1282
+ }
1283
+
1284
+ bool isNumber() const {
1285
+ return kind_ == NumberKind;
1286
+ }
1287
+
1288
+ bool isString() const {
1289
+ return kind_ == StringKind;
1290
+ }
1291
+
1292
+ #if JSI_VERSION >= 6
1293
+ bool isBigInt() const {
1294
+ return kind_ == BigIntKind;
1295
+ }
1296
+ #endif
1297
+
1298
+ bool isSymbol() const {
1299
+ return kind_ == SymbolKind;
1300
+ }
1301
+
1302
+ bool isObject() const {
1303
+ return kind_ == ObjectKind;
1304
+ }
1305
+
1306
+ /// \return the boolean value, or asserts if not a boolean.
1307
+ bool getBool() const {
1308
+ assert(isBool());
1309
+ return data_.boolean;
1310
+ }
1311
+
1312
+ /// \return the boolean value, or throws JSIException if not a
1313
+ /// boolean.
1314
+ bool asBool() const;
1315
+
1316
+ /// \return the number value, or asserts if not a number.
1317
+ double getNumber() const {
1318
+ assert(isNumber());
1319
+ return data_.number;
1320
+ }
1321
+
1322
+ /// \return the number value, or throws JSIException if not a
1323
+ /// number.
1324
+ double asNumber() const;
1325
+
1326
+ /// \return the Symbol value, or asserts if not a symbol.
1327
+ Symbol getSymbol(Runtime& runtime) const& {
1328
+ assert(isSymbol());
1329
+ return Symbol(runtime.cloneSymbol(data_.pointer.ptr_));
1330
+ }
1331
+
1332
+ /// \return the Symbol value, or asserts if not a symbol.
1333
+ /// Can be used on rvalue references to avoid cloning more symbols.
1334
+ Symbol getSymbol(Runtime&) && {
1335
+ assert(isSymbol());
1336
+ auto ptr = data_.pointer.ptr_;
1337
+ data_.pointer.ptr_ = nullptr;
1338
+ return static_cast<Symbol>(ptr);
1339
+ }
1340
+
1341
+ /// \return the Symbol value, or throws JSIException if not a
1342
+ /// symbol
1343
+ Symbol asSymbol(Runtime& runtime) const&;
1344
+ Symbol asSymbol(Runtime& runtime) &&;
1345
+
1346
+ #if JSI_VERSION >= 6
1347
+ /// \return the BigInt value, or asserts if not a bigint.
1348
+ BigInt getBigInt(Runtime& runtime) const& {
1349
+ assert(isBigInt());
1350
+ return BigInt(runtime.cloneBigInt(data_.pointer.ptr_));
1351
+ }
1352
+
1353
+ /// \return the BigInt value, or asserts if not a bigint.
1354
+ /// Can be used on rvalue references to avoid cloning more bigints.
1355
+ BigInt getBigInt(Runtime&) && {
1356
+ assert(isBigInt());
1357
+ auto ptr = data_.pointer.ptr_;
1358
+ data_.pointer.ptr_ = nullptr;
1359
+ return static_cast<BigInt>(ptr);
1360
+ }
1361
+
1362
+ /// \return the BigInt value, or throws JSIException if not a
1363
+ /// bigint
1364
+ BigInt asBigInt(Runtime& runtime) const&;
1365
+ BigInt asBigInt(Runtime& runtime) &&;
1366
+ #endif
1367
+
1368
+ /// \return the String value, or asserts if not a string.
1369
+ String getString(Runtime& runtime) const& {
1370
+ assert(isString());
1371
+ return String(runtime.cloneString(data_.pointer.ptr_));
1372
+ }
1373
+
1374
+ /// \return the String value, or asserts if not a string.
1375
+ /// Can be used on rvalue references to avoid cloning more strings.
1376
+ String getString(Runtime&) && {
1377
+ assert(isString());
1378
+ auto ptr = data_.pointer.ptr_;
1379
+ data_.pointer.ptr_ = nullptr;
1380
+ return static_cast<String>(ptr);
1381
+ }
1382
+
1383
+ /// \return the String value, or throws JSIException if not a
1384
+ /// string.
1385
+ String asString(Runtime& runtime) const&;
1386
+ String asString(Runtime& runtime) &&;
1387
+
1388
+ /// \return the Object value, or asserts if not an object.
1389
+ Object getObject(Runtime& runtime) const& {
1390
+ assert(isObject());
1391
+ return Object(runtime.cloneObject(data_.pointer.ptr_));
1392
+ }
1393
+
1394
+ /// \return the Object value, or asserts if not an object.
1395
+ /// Can be used on rvalue references to avoid cloning more objects.
1396
+ Object getObject(Runtime&) && {
1397
+ assert(isObject());
1398
+ auto ptr = data_.pointer.ptr_;
1399
+ data_.pointer.ptr_ = nullptr;
1400
+ return static_cast<Object>(ptr);
1401
+ }
1402
+
1403
+ /// \return the Object value, or throws JSIException if not an
1404
+ /// object.
1405
+ Object asObject(Runtime& runtime) const&;
1406
+ Object asObject(Runtime& runtime) &&;
1407
+
1408
+ // \return a String like JS .toString() would do.
1409
+ String toString(Runtime& runtime) const;
1410
+
1411
+ private:
1412
+ friend class Runtime;
1413
+
1414
+ enum ValueKind {
1415
+ UndefinedKind,
1416
+ NullKind,
1417
+ BooleanKind,
1418
+ NumberKind,
1419
+ SymbolKind,
1420
+ #if JSI_VERSION >= 6
1421
+ BigIntKind,
1422
+ #endif
1423
+ StringKind,
1424
+ ObjectKind,
1425
+ PointerKind = SymbolKind,
1426
+ };
1427
+
1428
+ union Data {
1429
+ // Value's ctor and dtor will manage the lifecycle of the contained Data.
1430
+ Data() {
1431
+ static_assert(
1432
+ sizeof(Data) == sizeof(uint64_t),
1433
+ "Value data should fit in a 64-bit register");
1434
+ }
1435
+ ~Data() {}
1436
+
1437
+ // scalars
1438
+ bool boolean;
1439
+ double number;
1440
+ // pointers
1441
+ Pointer pointer; // Symbol, String, Object, Array, Function
1442
+ };
1443
+
1444
+ Value(ValueKind kind) : kind_(kind) {}
1445
+
1446
+ constexpr static ValueKind kindOf(const Symbol&) {
1447
+ return SymbolKind;
1448
+ }
1449
+ #if JSI_VERSION >= 6
1450
+ constexpr static ValueKind kindOf(const BigInt&) {
1451
+ return BigIntKind;
1452
+ }
1453
+ #endif
1454
+ constexpr static ValueKind kindOf(const String&) {
1455
+ return StringKind;
1456
+ }
1457
+ constexpr static ValueKind kindOf(const Object&) {
1458
+ return ObjectKind;
1459
+ }
1460
+
1461
+ ValueKind kind_;
1462
+ Data data_;
1463
+
1464
+ // In the future: Value becomes NaN-boxed. See T40538354.
1465
+ };
1466
+
1467
+ /// Not movable and not copyable RAII marker advising the underlying
1468
+ /// JavaScript VM to track resources allocated since creation until
1469
+ /// destruction so that they can be recycled eagerly when the Scope
1470
+ /// goes out of scope instead of floating in the air until the next
1471
+ /// garbage collection or any other delayed release occurs.
1472
+ ///
1473
+ /// This API should be treated only as advice, implementations can
1474
+ /// choose to ignore the fact that Scopes are created or destroyed.
1475
+ ///
1476
+ /// This class is an exception to the rule allowing destructors to be
1477
+ /// called without proper synchronization (see Runtime documentation).
1478
+ /// The whole point of this class is to enable all sorts of clean ups
1479
+ /// when the destructor is called and this proper synchronization is
1480
+ /// required at that time.
1481
+ ///
1482
+ /// Instances of this class are intended to be created as automatic stack
1483
+ /// variables in which case destructor calls don't require any additional
1484
+ /// locking, provided that the lock (if any) is managed with RAII helpers.
1485
+ class JSI_EXPORT Scope {
1486
+ public:
1487
+ explicit Scope(Runtime& rt) : rt_(rt), prv_(rt.pushScope()) {}
1488
+ ~Scope() {
1489
+ rt_.popScope(prv_);
1490
+ }
1491
+
1492
+ Scope(const Scope&) = delete;
1493
+ Scope(Scope&&) = delete;
1494
+
1495
+ Scope& operator=(const Scope&) = delete;
1496
+ Scope& operator=(Scope&&) = delete;
1497
+
1498
+ template <typename F>
1499
+ static auto callInNewScope(Runtime& rt, F f) -> decltype(f()) {
1500
+ Scope s(rt);
1501
+ return f();
1502
+ }
1503
+
1504
+ private:
1505
+ Runtime& rt_;
1506
+ Runtime::ScopeState* prv_;
1507
+ };
1508
+
1509
+ /// Base class for jsi exceptions
1510
+ class JSI_EXPORT JSIException : public std::exception {
1511
+ protected:
1512
+ JSIException() {}
1513
+ JSIException(std::string what) : what_(std::move(what)) {}
1514
+
1515
+ public:
1516
+ JSIException(const JSIException&) = default;
1517
+
1518
+ virtual const char* what() const noexcept override {
1519
+ return what_.c_str();
1520
+ }
1521
+
1522
+ virtual ~JSIException() override;
1523
+
1524
+ protected:
1525
+ std::string what_;
1526
+ };
1527
+
1528
+ /// This exception will be thrown by API functions on errors not related to
1529
+ /// JavaScript execution.
1530
+ class JSI_EXPORT JSINativeException : public JSIException {
1531
+ public:
1532
+ JSINativeException(std::string what) : JSIException(std::move(what)) {}
1533
+
1534
+ JSINativeException(const JSINativeException&) = default;
1535
+
1536
+ virtual ~JSINativeException();
1537
+ };
1538
+
1539
+ /// This exception will be thrown by API functions whenever a JS
1540
+ /// operation causes an exception as described by the spec, or as
1541
+ /// otherwise described.
1542
+ class JSI_EXPORT JSError : public JSIException {
1543
+ public:
1544
+ /// Creates a JSError referring to provided \c value
1545
+ JSError(Runtime& r, Value&& value);
1546
+
1547
+ /// Creates a JSError referring to new \c Error instance capturing current
1548
+ /// JavaScript stack. The error message property is set to given \c message.
1549
+ JSError(Runtime& rt, std::string message);
1550
+
1551
+ /// Creates a JSError referring to new \c Error instance capturing current
1552
+ /// JavaScript stack. The error message property is set to given \c message.
1553
+ JSError(Runtime& rt, const char* message)
1554
+ : JSError(rt, std::string(message)) {}
1555
+
1556
+ /// Creates a JSError referring to a JavaScript Object having message and
1557
+ /// stack properties set to provided values.
1558
+ JSError(Runtime& rt, std::string message, std::string stack);
1559
+
1560
+ /// Creates a JSError referring to provided value and what string
1561
+ /// set to provided message. This argument order is a bit weird,
1562
+ /// but necessary to avoid ambiguity with the above.
1563
+ JSError(std::string what, Runtime& rt, Value&& value);
1564
+
1565
+ /// Creates a JSError referring to the provided value, message and stack. This
1566
+ /// constructor does not take a Runtime parameter, and therefore cannot result
1567
+ /// in recursively invoking the JSError constructor.
1568
+ JSError(Value&& value, std::string message, std::string stack);
1569
+
1570
+ JSError(const JSError&) = default;
1571
+
1572
+ virtual ~JSError();
1573
+
1574
+ const std::string& getStack() const {
1575
+ return stack_;
1576
+ }
1577
+
1578
+ const std::string& getMessage() const {
1579
+ return message_;
1580
+ }
1581
+
1582
+ const jsi::Value& value() const {
1583
+ assert(value_);
1584
+ return *value_;
1585
+ }
1586
+
1587
+ // In V8's case, creating an Error object in JS doesn't record the callstack.
1588
+ // To preserve it, we need a way to manually add the stack here and on the JS
1589
+ // side.
1590
+ void setStack(std::string stack) {
1591
+ stack_ = std::move(stack);
1592
+ what_ = message_ + "\n\n" + stack_;
1593
+ }
1594
+
1595
+ private:
1596
+ // This initializes the value_ member and does some other
1597
+ // validation, so it must be called by every branch through the
1598
+ // constructors.
1599
+ void setValue(Runtime& rt, Value&& value);
1600
+
1601
+ // This needs to be on the heap, because throw requires the object
1602
+ // be copyable, and Value is not.
1603
+ std::shared_ptr<jsi::Value> value_;
1604
+ std::string message_;
1605
+ std::string stack_;
1606
+ };
1607
+
1608
+ } // namespace jsi
1609
+ } // namespace facebook
1610
+
1611
+ #include <jsi/jsi-inl.h>