react-native-windows 0.82.1 → 0.83.0-preview.0

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 (232) hide show
  1. package/.flowconfig +2 -7
  2. package/Libraries/Animated/components/AnimatedFlatList.js +5 -3
  3. package/Libraries/Animated/components/AnimatedImage.js +4 -3
  4. package/Libraries/Animated/components/AnimatedSectionList.js +2 -2
  5. package/Libraries/Animated/components/AnimatedText.js +7 -3
  6. package/Libraries/Animated/components/AnimatedView.js +3 -2
  7. package/Libraries/Animated/createAnimatedComponent.js +24 -12
  8. package/Libraries/Animated/nodes/AnimatedColor.js +26 -10
  9. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +43 -15
  10. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.windows.js +43 -15
  11. package/Libraries/Components/ActivityIndicator/ActivityIndicator.d.ts +2 -2
  12. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +2 -2
  13. package/Libraries/Components/Glyph/Glyph.js +4 -1
  14. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.d.ts +2 -2
  15. package/Libraries/Components/RefreshControl/RefreshControl.d.ts +3 -3
  16. package/Libraries/Components/SafeAreaView/SafeAreaView.d.ts +2 -2
  17. package/Libraries/Components/ScrollView/ScrollView.js +1 -0
  18. package/Libraries/Components/ScrollView/ScrollView.windows.js +1 -0
  19. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +6 -6
  20. package/Libraries/Components/Switch/Switch.d.ts +2 -2
  21. package/Libraries/Components/Switch/Switch.windows.js +1 -1
  22. package/Libraries/Components/TextInput/TextInput.d.ts +2 -5
  23. package/Libraries/Components/TextInput/TextInput.js +6 -0
  24. package/Libraries/Components/TextInput/TextInput.windows.js +6 -0
  25. package/Libraries/Components/Touchable/TouchableBounce.js +7 -7
  26. package/Libraries/Components/Touchable/TouchableBounce.windows.js +7 -7
  27. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +1 -1
  28. package/Libraries/Components/View/ReactNativeStyleAttributes.js +19 -1
  29. package/Libraries/Components/View/View.d.ts +2 -2
  30. package/Libraries/Components/View/View.windows.js +0 -1
  31. package/Libraries/Components/View/ViewNativeComponent.js +13 -1
  32. package/Libraries/Core/ReactNativeVersion.js +3 -3
  33. package/Libraries/Core/setUpPerformance.js +2 -0
  34. package/Libraries/Debugging/DebuggingOverlay.js +14 -14
  35. package/Libraries/Debugging/DebuggingOverlayRegistry.js +8 -2
  36. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +5 -2
  37. package/Libraries/Image/Image.d.ts +3 -3
  38. package/Libraries/Image/ImageInjection.js +3 -6
  39. package/Libraries/Image/ImageTypes.flow.js +3 -7
  40. package/Libraries/Lists/FlatList.js +8 -8
  41. package/Libraries/Lists/SectionList.d.ts +5 -1
  42. package/Libraries/Lists/ViewabilityHelper.js +1 -1
  43. package/Libraries/Lists/VirtualizedList.js +1 -0
  44. package/Libraries/LogBox/UI/AnsiHighlight.js +4 -1
  45. package/Libraries/NativeComponent/BaseViewConfig.android.js +11 -2
  46. package/Libraries/NativeComponent/NativeComponentRegistry.d.ts +98 -0
  47. package/Libraries/NativeComponent/NativeComponentRegistry.js +2 -0
  48. package/Libraries/NativeComponent/NativeComponentRegistryUnstable.js +3 -1
  49. package/Libraries/NativeComponent/ViewConfigIgnore.windows.js +45 -0
  50. package/Libraries/Network/RCTNetworking.android.js +3 -1
  51. package/Libraries/Network/RCTNetworking.ios.js +3 -0
  52. package/Libraries/Network/RCTNetworking.windows.js +3 -0
  53. package/Libraries/Network/XMLHttpRequest.js +1 -41
  54. package/Libraries/Pressability/usePressability.js +14 -3
  55. package/Libraries/ReactNative/PaperUIManager.windows.js +3 -3
  56. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +20 -82
  57. package/Libraries/ReactNative/getNativeComponentAttributes.js +12 -0
  58. package/Libraries/Renderer/implementations/ReactFabric-dev.js +6759 -4478
  59. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3169 -3119
  60. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4732 -3535
  61. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +6646 -4070
  62. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3136 -2825
  63. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4761 -3312
  64. package/Libraries/Renderer/shims/ReactNative.js +3 -1
  65. package/Libraries/Renderer/shims/ReactNativeTypes.js +2 -1
  66. package/Libraries/Renderer/shims/ReactNativeTypes.windows.js +2 -1
  67. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
  68. package/Libraries/StyleSheet/StyleSheetTypes.js +44 -0
  69. package/Libraries/StyleSheet/processBackgroundPosition.js +284 -0
  70. package/Libraries/StyleSheet/processBackgroundRepeat.js +105 -0
  71. package/Libraries/StyleSheet/processBackgroundSize.js +104 -0
  72. package/Libraries/Text/Text.d.ts +2 -2
  73. package/Libraries/Text/TextNativeComponent.js +10 -0
  74. package/Libraries/TurboModule/TurboModuleRegistry.js +3 -9
  75. package/Libraries/Utilities/DevLoadingView.js +14 -6
  76. package/Libraries/Utilities/HMRClient.js +13 -5
  77. package/Microsoft.ReactNative/Base/CxxReactIncludes.h +11 -0
  78. package/Microsoft.ReactNative/CompositionComponentView.idl +2 -0
  79. package/Microsoft.ReactNative/CompositionHwndHost.idl +1 -0
  80. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +1 -1
  81. package/Microsoft.ReactNative/Fabric/ComponentView.h +1 -1
  82. package/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp +10 -40
  83. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +3 -80
  84. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +45 -12
  85. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +8 -0
  86. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +61 -74
  87. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +4 -0
  88. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +1 -0
  89. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +4 -3
  90. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +2 -1
  91. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.cpp +245 -0
  92. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.h +80 -0
  93. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +20 -36
  94. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +70 -49
  95. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -1
  96. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +5 -0
  97. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/WindowsTextLayoutManager.cpp +7 -2
  98. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +1 -0
  99. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -1
  100. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -1
  101. package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +20 -94
  102. package/Microsoft.ReactNative/Modules/LogBoxModule.h +1 -3
  103. package/Microsoft.ReactNative/Pch/pch.h +2 -0
  104. package/Microsoft.ReactNative/ReactHost/CrashManager.cpp +5 -0
  105. package/Microsoft.ReactNative/ReactHost/ReactNativeHeaders.h +1 -0
  106. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +0 -41
  107. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +0 -11
  108. package/Microsoft.ReactNative/ReactNativeIsland.idl +2 -3
  109. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +31 -101
  110. package/Microsoft.ReactNative/ReactNativeWin32App.h +2 -13
  111. package/Microsoft.ReactNative/ReactNativeWindow.idl +44 -0
  112. package/Microsoft.ReactNative.Cxx/AutoDraw.h +9 -1
  113. package/Microsoft.ReactNative.Cxx/ReactCommon/CallInvoker.h +13 -16
  114. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModule.h +24 -36
  115. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModuleUtils.h +5 -8
  116. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/AString.h +8 -6
  117. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Array.h +32 -49
  118. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Base.h +27 -76
  119. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Bool.h +4 -2
  120. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/CallbackWrapper.h +19 -18
  121. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Class.h +25 -48
  122. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Convert.h +38 -31
  123. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Error.h +11 -6
  124. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/EventEmitter.h +47 -45
  125. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Function.h +69 -89
  126. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/HighResTimeStamp.h +8 -8
  127. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/LongLivedObject.h +6 -6
  128. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Number.h +16 -8
  129. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Object.h +17 -24
  130. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Promise.h +17 -17
  131. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Value.h +20 -29
  132. package/Microsoft.ReactNative.Cxx/ReactCommon/react/debug/react_native_assert.h +2 -7
  133. package/Microsoft.ReactNative.Cxx/ReactCommon/react/timing/primitives.h +127 -115
  134. package/PropertySheets/External/Microsoft.ReactNative.Composition.CppLib.props +10 -0
  135. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +10 -0
  136. package/PropertySheets/Generated/PackageVersion.g.props +5 -5
  137. package/PropertySheets/Warnings.props +2 -1
  138. package/ReactCommon/ReactCommon.vcxproj +21 -12
  139. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/CxxNativeModule.cpp +2 -2
  140. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/Instance.cpp +381 -0
  141. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +49 -0
  142. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSIndexedRAMBundle.cpp +145 -0
  143. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/MethodCall.cpp +100 -0
  144. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ModuleRegistry.cpp +256 -0
  145. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +13 -4
  146. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/RAMBundleRegistry.cpp +93 -0
  147. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ReactMarker.cpp +149 -0
  148. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/TraceSection.h +25 -35
  149. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +86 -67
  150. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSIExecutor.cpp +629 -0
  151. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSINativeModules.cpp +123 -0
  152. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.cpp +84 -68
  153. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.h +31 -35
  154. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/Utf8.h +4 -5
  155. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/network/HttpUtils.cpp +2 -1
  156. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +24 -36
  157. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/dom/NativeDOM.h +28 -66
  158. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/webperformance/NativePerformance.cpp +414 -0
  159. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +3 -3
  160. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/image/conversions.h +8 -4
  161. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/ParagraphShadowNode.cpp +19 -16
  162. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h +8 -9
  163. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +25 -95
  164. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +85 -42
  165. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventDispatcher.cpp +81 -0
  166. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventQueueProcessor.cpp +140 -0
  167. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/primitives.h +25 -31
  168. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/UIManager.cpp +746 -0
  169. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +702 -0
  170. package/Scripts/Tfs/Layout-Desktop-Headers.ps1 +1 -15
  171. package/Scripts/creaternwapp.cmd +1 -1
  172. package/Scripts/perf/compare-results.js +357 -0
  173. package/Scripts/perf/create-perf-test.js +343 -0
  174. package/Scripts/perf/post-pr-comment.js +210 -0
  175. package/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +8 -0
  176. package/Shared/Hermes/HermesRuntimeTargetDelegate.h +3 -0
  177. package/Shared/Shared.vcxitems +24 -12
  178. package/Shared/Shared.vcxitems.filters +11 -3
  179. package/codegen/NativeIntersectionObserverSpec.g.h +2 -0
  180. package/codegen/NativeNetworkingIOSSpec.g.h +2 -0
  181. package/codegen/NativePerformanceSpec.g.h +6 -0
  182. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +229 -139
  183. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +2 -1
  184. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +42 -25
  185. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +2 -1
  186. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +2 -1
  187. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +11 -6
  188. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +11 -6
  189. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +1 -0
  190. package/codegen/react/components/rnwcore/InputAccessory.g.h +2 -1
  191. package/codegen/react/components/rnwcore/ModalHostView.g.h +40 -23
  192. package/codegen/react/components/rnwcore/Props.cpp +6 -1
  193. package/codegen/react/components/rnwcore/Props.h +1 -0
  194. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +11 -6
  195. package/codegen/react/components/rnwcore/SafeAreaView.g.h +1 -0
  196. package/codegen/react/components/rnwcore/Switch.g.h +11 -6
  197. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +2 -1
  198. package/codegen/react/components/rnwcore/VirtualView.g.h +41 -8
  199. package/codegen/react/components/rnwcore/VirtualViewExperimental.g.h +45 -8
  200. package/codegen/rnwcoreJSI.h +3973 -6059
  201. package/index.js +6 -0
  202. package/index.windows.js +6 -0
  203. package/jest/mockComponent.js +6 -6
  204. package/jest/setup.js +15 -10
  205. package/package.json +27 -27
  206. package/src/private/components/virtualview/VirtualView.js +22 -27
  207. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +6 -0
  208. package/src/private/featureflags/ReactNativeFeatureFlags.js +100 -19
  209. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +18 -3
  210. package/src/private/setup/setUpDefaultReactNativeEnvironment.js +6 -0
  211. package/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js +1 -1
  212. package/src/private/specs_DEPRECATED/modules/NativeNetworkingIOS.js +1 -0
  213. package/src/private/webapis/dom/nodes/ReactNativeElement.js +12 -2
  214. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +76 -15
  215. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +1 -0
  216. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
  217. package/src/private/webapis/performance/ResourceTiming.js +31 -4
  218. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +4 -1
  219. package/src/private/webapis/performance/specs/NativePerformance.js +3 -0
  220. package/stubs/double-conversion/double-conversion.h +5 -0
  221. package/templates/cpp-app/template.config.js +1 -1
  222. package/templates/cpp-app/windows/MyApp/MyApp.vcxproj +3 -1
  223. package/templates/cpp-lib/template.config.js +1 -1
  224. package/templates/cpp-lib/windows/MyLib/MyLib.vcxproj +1 -1
  225. package/types/index.d.ts +1 -0
  226. package/types/public/ReactNativeTypes.d.ts +115 -2
  227. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +0 -152
  228. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/conversions.h +0 -1574
  229. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/ShadowNode.cpp +0 -528
  230. package/Scripts/OpenSSL.nuspec +0 -39
  231. package/Scripts/OpenSSL.targets +0 -36
  232. package/codegen/rnwcoreJSI-generated.cpp +0 -3470
@@ -0,0 +1,629 @@
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
+
9
+ #if _MSC_VER
10
+ #pragma warning(push)
11
+ #pragma warning(disable : 4996) // deprecated APIs
12
+ #endif
13
+ #include "jsireact/JSIExecutor.h"
14
+
15
+ #include <cxxreact/ErrorUtils.h>
16
+ #include <cxxreact/JSBigString.h>
17
+ #include <cxxreact/ModuleRegistry.h>
18
+ #include <cxxreact/ReactMarker.h>
19
+ #include <cxxreact/TraceSection.h>
20
+ #include <folly/json.h>
21
+ #include <glog/logging.h>
22
+ #include <jsi/JSIDynamic.h>
23
+ #include <jsi/instrumentation.h>
24
+ #include <reactperflogger/BridgeNativeModulePerfLogger.h>
25
+
26
+ #include <sstream>
27
+ #include <stdexcept>
28
+
29
+ using namespace facebook::jsi;
30
+
31
+ namespace facebook::react {
32
+
33
+ #ifndef RCT_REMOVE_LEGACY_ARCH
34
+
35
+ class JSIExecutor::NativeModuleProxy : public jsi::HostObject {
36
+ public:
37
+ NativeModuleProxy(std::shared_ptr<JSINativeModules> nativeModules)
38
+ : weakNativeModules_(nativeModules) {}
39
+
40
+ Value get(Runtime& rt, const PropNameID& name) override {
41
+ if (name.utf8(rt) == "name") {
42
+ return jsi::String::createFromAscii(rt, "NativeModules");
43
+ }
44
+
45
+ auto nativeModules = weakNativeModules_.lock();
46
+ if (!nativeModules) {
47
+ return nullptr;
48
+ }
49
+
50
+ return nativeModules->getModule(rt, name);
51
+ }
52
+
53
+ void set(
54
+ Runtime& /*unused*/,
55
+ const PropNameID& /*name*/,
56
+ const Value& /*value*/) override {
57
+ throw std::runtime_error(
58
+ "Unable to put on NativeModules: Operation unsupported");
59
+ }
60
+
61
+ private:
62
+ std::weak_ptr<JSINativeModules> weakNativeModules_;
63
+ };
64
+
65
+ namespace {
66
+
67
+ // basename_r isn't in all iOS SDKs, so use this simple version instead.
68
+ std::string simpleBasename(const std::string& path) {
69
+ size_t pos = path.rfind('/');
70
+ return (pos != std::string::npos) ? path.substr(pos) : path;
71
+ }
72
+
73
+ } // namespace
74
+
75
+ JSIExecutor::JSIExecutor(
76
+ std::shared_ptr<jsi::Runtime> runtime,
77
+ std::shared_ptr<ExecutorDelegate> delegate,
78
+ const JSIScopedTimeoutInvoker& scopedTimeoutInvoker,
79
+ RuntimeInstaller runtimeInstaller)
80
+ : runtime_(runtime),
81
+ delegate_(delegate),
82
+ nativeModules_(
83
+ std::make_shared<JSINativeModules>(
84
+ delegate ? delegate->getModuleRegistry() : nullptr)),
85
+ moduleRegistry_(delegate ? delegate->getModuleRegistry() : nullptr),
86
+ scopedTimeoutInvoker_(scopedTimeoutInvoker),
87
+ runtimeInstaller_(runtimeInstaller) {
88
+ runtime_->global().setProperty(
89
+ *runtime, "__jsiExecutorDescription", runtime->description());
90
+ }
91
+
92
+ void JSIExecutor::initializeRuntime() {
93
+ TraceSection s("JSIExecutor::initializeRuntime");
94
+
95
+ bindNativePerformanceNow(*runtime_);
96
+
97
+ runtime_->global().setProperty(
98
+ *runtime_,
99
+ "nativeModuleProxy",
100
+ Object::createFromHostObject(
101
+ *runtime_, std::make_shared<NativeModuleProxy>(nativeModules_)));
102
+
103
+ runtime_->global().setProperty(
104
+ *runtime_,
105
+ "nativeFlushQueueImmediate",
106
+ Function::createFromHostFunction(
107
+ *runtime_,
108
+ PropNameID::forAscii(*runtime_, "nativeFlushQueueImmediate"),
109
+ 1,
110
+ [this](
111
+ jsi::Runtime&,
112
+ const jsi::Value&,
113
+ const jsi::Value* args,
114
+ size_t count) {
115
+ if (count != 1) {
116
+ throw std::invalid_argument(
117
+ "nativeFlushQueueImmediate arg count must be 1");
118
+ }
119
+ callNativeModules(args[0], false);
120
+ return Value::undefined();
121
+ }));
122
+
123
+ runtime_->global().setProperty(
124
+ *runtime_,
125
+ "nativeCallSyncHook",
126
+ Function::createFromHostFunction(
127
+ *runtime_,
128
+ PropNameID::forAscii(*runtime_, "nativeCallSyncHook"),
129
+ 1,
130
+ [this](
131
+ jsi::Runtime&,
132
+ const jsi::Value&,
133
+ const jsi::Value* args,
134
+ size_t count) { return nativeCallSyncHook(args, count); }));
135
+
136
+ runtime_->global().setProperty(
137
+ *runtime_,
138
+ "globalEvalWithSourceUrl",
139
+ Function::createFromHostFunction(
140
+ *runtime_,
141
+ PropNameID::forAscii(*runtime_, "globalEvalWithSourceUrl"),
142
+ 1,
143
+ [this](
144
+ jsi::Runtime&,
145
+ const jsi::Value&,
146
+ const jsi::Value* args,
147
+ size_t count) { return globalEvalWithSourceUrl(args, count); }));
148
+
149
+ if (runtimeInstaller_) {
150
+ runtimeInstaller_(*runtime_);
151
+ }
152
+ bool hasLogger = false;
153
+ {
154
+ std::shared_lock lock(ReactMarker::logTaggedMarkerImplMutex);
155
+ hasLogger = ReactMarker::logTaggedMarkerImpl != nullptr;
156
+ }
157
+ if (hasLogger) {
158
+ ReactMarker::logMarker(ReactMarker::CREATE_REACT_CONTEXT_STOP);
159
+ }
160
+ }
161
+
162
+ void JSIExecutor::loadBundle(
163
+ std::unique_ptr<const JSBigString> script,
164
+ std::string sourceURL) {
165
+ TraceSection s("JSIExecutor::loadBundle");
166
+ bool hasLogger = false;
167
+ {
168
+ std::shared_lock lock(ReactMarker::logTaggedMarkerImplMutex);
169
+ hasLogger = ReactMarker::logTaggedMarkerImpl != nullptr;
170
+ }
171
+ std::string scriptName = simpleBasename(sourceURL);
172
+ if (hasLogger) {
173
+ ReactMarker::logTaggedMarker(
174
+ ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str());
175
+ }
176
+ runtime_->evaluateJavaScript(
177
+ std::make_unique<BigStringBuffer>(std::move(script)), sourceURL);
178
+ flush();
179
+ if (hasLogger) {
180
+ ReactMarker::logTaggedMarker(
181
+ ReactMarker::RUN_JS_BUNDLE_STOP, scriptName.c_str());
182
+ ReactMarker::logMarker(ReactMarker::INIT_REACT_RUNTIME_STOP);
183
+ ReactMarker::logMarker(ReactMarker::APP_STARTUP_STOP);
184
+ }
185
+ }
186
+
187
+ void JSIExecutor::setBundleRegistry(std::unique_ptr<RAMBundleRegistry> r) {
188
+ if (!bundleRegistry_) {
189
+ runtime_->global().setProperty(
190
+ *runtime_,
191
+ "nativeRequire",
192
+ Function::createFromHostFunction(
193
+ *runtime_,
194
+ PropNameID::forAscii(*runtime_, "nativeRequire"),
195
+ 2,
196
+ [this](
197
+ [[maybe_unused]] Runtime& rt,
198
+ const facebook::jsi::Value&,
199
+ const facebook::jsi::Value* args,
200
+ size_t count) { return nativeRequire(args, count); }));
201
+ }
202
+ bundleRegistry_ = std::move(r);
203
+ }
204
+
205
+ void JSIExecutor::registerBundle(
206
+ uint32_t bundleId,
207
+ const std::string& bundlePath) {
208
+ auto tag = std::to_string(bundleId);
209
+ ReactMarker::logTaggedMarker(
210
+ ReactMarker::REGISTER_JS_SEGMENT_START, tag.c_str());
211
+ if (bundleRegistry_) {
212
+ bundleRegistry_->registerBundle(bundleId, bundlePath);
213
+ } else {
214
+ auto script = JSBigFileString::fromPath(bundlePath);
215
+ if (script->size() == 0) {
216
+ throw std::invalid_argument(
217
+ "Empty bundle registered with ID " + tag + " from " + bundlePath);
218
+ }
219
+ runtime_->evaluateJavaScript(
220
+ std::make_unique<BigStringBuffer>(std::move(script)),
221
+ JSExecutor::getSyntheticBundlePath(bundleId, bundlePath));
222
+ }
223
+ ReactMarker::logTaggedMarker(
224
+ ReactMarker::REGISTER_JS_SEGMENT_STOP, tag.c_str());
225
+ }
226
+
227
+ void JSIExecutor::callFunction(
228
+ const std::string& moduleId,
229
+ const std::string& methodId,
230
+ const folly::dynamic& arguments) {
231
+ TraceSection s(
232
+ "JSIExecutor::callFunction", "moduleId", moduleId, "methodId", methodId);
233
+ if (!callFunctionReturnFlushedQueue_) {
234
+ bindBridge();
235
+ }
236
+
237
+ // Construct the error message producer in case this times out.
238
+ // This is executed on a background thread, so it must capture its parameters
239
+ // by value.
240
+ auto errorProducer = [=] {
241
+ std::stringstream ss;
242
+ ss << "moduleID: " << moduleId << " methodID: " << methodId;
243
+ return ss.str();
244
+ };
245
+
246
+ Value ret = Value::undefined();
247
+ try {
248
+ scopedTimeoutInvoker_(
249
+ [&] {
250
+ ret = callFunctionReturnFlushedQueue_->call(
251
+ *runtime_,
252
+ moduleId,
253
+ methodId,
254
+ valueFromDynamic(*runtime_, arguments));
255
+ },
256
+ std::move(errorProducer));
257
+ } catch (...) {
258
+ std::throw_with_nested(
259
+ std::runtime_error("Error calling " + moduleId + "." + methodId));
260
+ }
261
+
262
+ callNativeModules(ret, true);
263
+ }
264
+
265
+ void JSIExecutor::invokeCallback(
266
+ const double callbackId,
267
+ const folly::dynamic& arguments) {
268
+ TraceSection s("JSIExecutor::invokeCallback", "callbackId", callbackId);
269
+ if (!invokeCallbackAndReturnFlushedQueue_) {
270
+ bindBridge();
271
+ }
272
+ Value ret;
273
+ try {
274
+ ret = invokeCallbackAndReturnFlushedQueue_->call(
275
+ *runtime_, callbackId, valueFromDynamic(*runtime_, arguments));
276
+ } catch (...) {
277
+ std::throw_with_nested(
278
+ std::runtime_error(
279
+ "Error invoking callback " + std::to_string(callbackId)));
280
+ }
281
+
282
+ callNativeModules(ret, true);
283
+ }
284
+
285
+ void JSIExecutor::setGlobalVariable(
286
+ std::string propName,
287
+ std::unique_ptr<const JSBigString> jsonValue) {
288
+ TraceSection s("JSIExecutor::setGlobalVariable", "propName", propName);
289
+ runtime_->global().setProperty(
290
+ *runtime_,
291
+ propName.c_str(),
292
+ Value::createFromJsonUtf8(
293
+ *runtime_,
294
+ reinterpret_cast<const uint8_t*>(jsonValue->c_str()),
295
+ jsonValue->size()));
296
+ }
297
+
298
+ std::string JSIExecutor::getDescription() {
299
+ return "JSI (" + runtime_->description() + ")";
300
+ }
301
+
302
+ void* JSIExecutor::getJavaScriptContext() {
303
+ return runtime_.get();
304
+ }
305
+
306
+ bool JSIExecutor::isInspectable() {
307
+ return runtime_->isInspectable();
308
+ }
309
+
310
+ void JSIExecutor::handleMemoryPressure(int pressureLevel) {
311
+ // The level is an enum value passed by the Android OS to an onTrimMemory
312
+ // event callback. Defined in ComponentCallbacks2.
313
+ enum AndroidMemoryPressure {
314
+ TRIM_MEMORY_BACKGROUND = 40,
315
+ TRIM_MEMORY_COMPLETE = 80,
316
+ TRIM_MEMORY_MODERATE = 60,
317
+ TRIM_MEMORY_RUNNING_CRITICAL = 15,
318
+ TRIM_MEMORY_RUNNING_LOW = 10,
319
+ TRIM_MEMORY_RUNNING_MODERATE = 5,
320
+ TRIM_MEMORY_UI_HIDDEN = 20,
321
+ };
322
+ const char* levelName;
323
+ switch (pressureLevel) {
324
+ case TRIM_MEMORY_BACKGROUND:
325
+ levelName = "TRIM_MEMORY_BACKGROUND";
326
+ break;
327
+ case TRIM_MEMORY_COMPLETE:
328
+ levelName = "TRIM_MEMORY_COMPLETE";
329
+ break;
330
+ case TRIM_MEMORY_MODERATE:
331
+ levelName = "TRIM_MEMORY_MODERATE";
332
+ break;
333
+ case TRIM_MEMORY_RUNNING_CRITICAL:
334
+ levelName = "TRIM_MEMORY_RUNNING_CRITICAL";
335
+ break;
336
+ case TRIM_MEMORY_RUNNING_LOW:
337
+ levelName = "TRIM_MEMORY_RUNNING_LOW";
338
+ break;
339
+ case TRIM_MEMORY_RUNNING_MODERATE:
340
+ levelName = "TRIM_MEMORY_RUNNING_MODERATE";
341
+ break;
342
+ case TRIM_MEMORY_UI_HIDDEN:
343
+ levelName = "TRIM_MEMORY_UI_HIDDEN";
344
+ break;
345
+ default:
346
+ levelName = "UNKNOWN";
347
+ break;
348
+ }
349
+
350
+ switch (pressureLevel) {
351
+ case TRIM_MEMORY_RUNNING_LOW:
352
+ case TRIM_MEMORY_RUNNING_MODERATE:
353
+ case TRIM_MEMORY_UI_HIDDEN:
354
+ // For non-severe memory trims, do nothing.
355
+ LOG(INFO) << "Memory warning (pressure level: " << levelName
356
+ << ") received by JS VM, ignoring because it's non-severe";
357
+ break;
358
+ case TRIM_MEMORY_BACKGROUND:
359
+ case TRIM_MEMORY_COMPLETE:
360
+ case TRIM_MEMORY_MODERATE:
361
+ case TRIM_MEMORY_RUNNING_CRITICAL:
362
+ // For now, pressureLevel is unused by collectGarbage.
363
+ // This may change in the future if the JS GC has different styles of
364
+ // collections.
365
+ LOG(INFO) << "Memory warning (pressure level: " << levelName
366
+ << ") received by JS VM, running a GC";
367
+ runtime_->instrumentation().collectGarbage(levelName);
368
+ break;
369
+ default:
370
+ // Use the raw number instead of the name here since the name is
371
+ // meaningless.
372
+ LOG(WARNING) << "Memory warning (pressure level: " << pressureLevel
373
+ << ") received by JS VM, unrecognized pressure level";
374
+ break;
375
+ }
376
+ }
377
+
378
+ void JSIExecutor::bindBridge() {
379
+ std::call_once(bindFlag_, [this] {
380
+ TraceSection s("JSIExecutor::bindBridge (once)");
381
+ Value batchedBridgeValue =
382
+ runtime_->global().getProperty(*runtime_, "__fbBatchedBridge");
383
+ if (batchedBridgeValue.isUndefined() || !batchedBridgeValue.isObject()) {
384
+ throw JSINativeException(
385
+ "Could not get BatchedBridge, make sure your bundle is packaged correctly");
386
+ }
387
+
388
+ Object batchedBridge = batchedBridgeValue.asObject(*runtime_);
389
+ callFunctionReturnFlushedQueue_ = batchedBridge.getPropertyAsFunction(
390
+ *runtime_, "callFunctionReturnFlushedQueue");
391
+ invokeCallbackAndReturnFlushedQueue_ = batchedBridge.getPropertyAsFunction(
392
+ *runtime_, "invokeCallbackAndReturnFlushedQueue");
393
+ flushedQueue_ =
394
+ batchedBridge.getPropertyAsFunction(*runtime_, "flushedQueue");
395
+ });
396
+ }
397
+
398
+ void JSIExecutor::callNativeModules(const Value& queue, bool isEndOfBatch) {
399
+ TraceSection s("JSIExecutor::callNativeModules");
400
+ // If this fails, you need to pass a fully functional delegate with a
401
+ // module registry to the factory/ctor.
402
+ CHECK(delegate_) << "Attempting to use native modules without a delegate";
403
+ #if 0 // maybe useful for debugging
404
+ std::string json = runtime_->global().getPropertyAsObject(*runtime_, "JSON")
405
+ .getPropertyAsFunction(*runtime_, "stringify").call(*runtime_, queue)
406
+ .getString(*runtime_).utf8(*runtime_);
407
+ #endif
408
+ BridgeNativeModulePerfLogger::asyncMethodCallBatchPreprocessStart();
409
+
410
+ delegate_->callNativeModules(
411
+ *this, dynamicFromValue(*runtime_, queue), isEndOfBatch);
412
+ }
413
+
414
+ void JSIExecutor::flush() {
415
+ TraceSection s("JSIExecutor::flush");
416
+ if (flushedQueue_) {
417
+ Value ret = flushedQueue_->call(*runtime_);
418
+ callNativeModules(ret, true);
419
+ return;
420
+ }
421
+
422
+ // When a native module is called from JS, BatchedBridge.enqueueNativeCall()
423
+ // is invoked. For that to work, require('BatchedBridge') has to be called,
424
+ // and when that happens, __fbBatchedBridge is set as a side effect.
425
+ Value batchedBridge =
426
+ runtime_->global().getProperty(*runtime_, "__fbBatchedBridge");
427
+ // So here, if __fbBatchedBridge doesn't exist, then we know no native calls
428
+ // have happened, and we were able to determine this without forcing
429
+ // BatchedBridge to be loaded as a side effect.
430
+ if (!batchedBridge.isUndefined()) {
431
+ // If calls were made, we bind to the JS bridge methods, and use them to
432
+ // get the pending queue of native calls.
433
+ bindBridge();
434
+ Value ret = flushedQueue_->call(*runtime_);
435
+ callNativeModules(ret, true);
436
+ } else if (delegate_) {
437
+ // If we have a delegate, we need to call it; we pass a null list to
438
+ // callNativeModules, since we know there are no native calls, without
439
+ // calling into JS again. If no calls were made and there's no delegate,
440
+ // nothing happens, which is correct.
441
+ callNativeModules(nullptr, true);
442
+ }
443
+ }
444
+
445
+ Value JSIExecutor::nativeRequire(const Value* args, size_t count) {
446
+ if (count > 2 || count == 0) {
447
+ throw std::invalid_argument("Got wrong number of args");
448
+ }
449
+
450
+ auto moduleId = static_cast<uint32_t>(args[0].getNumber());
451
+ uint32_t bundleId =
452
+ count == 2 ? static_cast<uint32_t>(args[1].getNumber()) : 0;
453
+ auto module = bundleRegistry_->getModule(bundleId, moduleId);
454
+
455
+ runtime_->evaluateJavaScript(
456
+ std::make_unique<StringBuffer>(module.code), module.name);
457
+ return facebook::jsi::Value();
458
+ }
459
+
460
+ Value JSIExecutor::nativeCallSyncHook(const Value* args, size_t count) {
461
+ if (count != 3) {
462
+ throw std::invalid_argument("nativeCallSyncHook arg count must be 3");
463
+ }
464
+
465
+ if (!args[2].isObject() || !args[2].asObject(*runtime_).isArray(*runtime_)) {
466
+ throw std::invalid_argument("method parameters should be array");
467
+ }
468
+
469
+ unsigned int moduleId = static_cast<unsigned int>(args[0].getNumber());
470
+ unsigned int methodId = static_cast<unsigned int>(args[1].getNumber());
471
+ std::string moduleName;
472
+ std::string methodName;
473
+
474
+ if (moduleRegistry_) {
475
+ moduleName = moduleRegistry_->getModuleName(moduleId);
476
+ methodName = moduleRegistry_->getModuleSyncMethodName(moduleId, methodId);
477
+
478
+ BridgeNativeModulePerfLogger::syncMethodCallStart(
479
+ moduleName.c_str(), methodName.c_str());
480
+
481
+ BridgeNativeModulePerfLogger::syncMethodCallArgConversionStart(
482
+ moduleName.c_str(), methodName.c_str());
483
+ }
484
+
485
+ MethodCallResult result = delegate_->callSerializableNativeHook(
486
+ *this, moduleId, methodId, dynamicFromValue(*runtime_, args[2]));
487
+
488
+ /**
489
+ * Note:
490
+ * In RCTNativeModule, std::nullopt is returned from
491
+ * callSerializableNativeHook when executing a NativeModule method fails.
492
+ * Therefore, it's safe to not terminate the syncMethodCall when std::nullopt
493
+ * is returned.
494
+ *
495
+ * TODO: In JavaNativeModule, std::nullopt is returned when the synchronous
496
+ * NativeModule method has the void return type. Change this to return
497
+ * folly::dynamic(nullptr) instead, so that std::nullopt is reserved for
498
+ * exceptional scenarios.
499
+ *
500
+ * TODO: Investigate CxxModule infra to see if std::nullopt is used for
501
+ * returns in exceptional scenarios.
502
+ **/
503
+
504
+ if (!result.has_value()) {
505
+ return Value::undefined();
506
+ }
507
+
508
+ Value returnValue = valueFromDynamic(*runtime_, result.value());
509
+
510
+ if (moduleRegistry_) {
511
+ BridgeNativeModulePerfLogger::syncMethodCallReturnConversionEnd(
512
+ moduleName.c_str(), methodName.c_str());
513
+ BridgeNativeModulePerfLogger::syncMethodCallEnd(
514
+ moduleName.c_str(), methodName.c_str());
515
+ }
516
+
517
+ return returnValue;
518
+ }
519
+
520
+ Value JSIExecutor::globalEvalWithSourceUrl(const Value* args, size_t count) {
521
+ if (count != 1 && count != 2) {
522
+ throw std::invalid_argument(
523
+ "globalEvalWithSourceUrl arg count must be 1 or 2");
524
+ }
525
+
526
+ auto code = args[0].asString(*runtime_).utf8(*runtime_);
527
+ std::string url;
528
+ if (count > 1 && args[1].isString()) {
529
+ url = args[1].asString(*runtime_).utf8(*runtime_);
530
+ }
531
+
532
+ return runtime_->evaluateJavaScript(
533
+ std::make_unique<StringBuffer>(std::move(code)), url);
534
+ }
535
+
536
+ #else // RCT_REMOVE_LEGACY_ARCH
537
+
538
+ JSIExecutor::JSIExecutor(
539
+ std::shared_ptr<jsi::Runtime> runtime,
540
+ std::shared_ptr<ExecutorDelegate> delegate,
541
+ const JSIScopedTimeoutInvoker& scopedTimeoutInvoker,
542
+ RuntimeInstaller runtimeInstaller) {}
543
+
544
+ void JSIExecutor::initializeRuntime() {}
545
+
546
+ void JSIExecutor::loadBundle(
547
+ std::unique_ptr<const JSBigString> script,
548
+ std::string sourceURL) {}
549
+
550
+ void JSIExecutor::registerBundle(
551
+ uint32_t bundleId,
552
+ const std::string& bundlePath) {}
553
+
554
+ void JSIExecutor::callFunction(
555
+ const std::string& moduleId,
556
+ const std::string& methodId,
557
+ const folly::dynamic& arguments) {}
558
+
559
+ void JSIExecutor::invokeCallback(
560
+ const double callbackId,
561
+ const folly::dynamic& arguments) {}
562
+
563
+ void JSIExecutor::setGlobalVariable(
564
+ std::string propName,
565
+ std::unique_ptr<const JSBigString> jsonValue) {}
566
+
567
+ std::string JSIExecutor::getDescription() {
568
+ return "null";
569
+ }
570
+
571
+ void* JSIExecutor::getJavaScriptContext() {
572
+ return nullptr;
573
+ }
574
+
575
+ bool JSIExecutor::isInspectable() {
576
+ return false;
577
+ }
578
+
579
+ void JSIExecutor::handleMemoryPressure(int pressureLevel) {}
580
+
581
+ void JSIExecutor::flush() {}
582
+
583
+ #endif // RCT_REMOVE_LEGACY_ARCH
584
+
585
+ void bindNativeLogger(Runtime& runtime, Logger logger) {
586
+ runtime.global().setProperty(
587
+ runtime,
588
+ "nativeLoggingHook",
589
+ Function::createFromHostFunction(
590
+ runtime,
591
+ PropNameID::forAscii(runtime, "nativeLoggingHook"),
592
+ 2,
593
+ [logger = std::move(logger)](
594
+ jsi::Runtime& runtime,
595
+ const jsi::Value&,
596
+ const jsi::Value* args,
597
+ size_t count) {
598
+ if (count != 2) {
599
+ throw std::invalid_argument(
600
+ "nativeLoggingHook takes 2 arguments");
601
+ }
602
+ logger(
603
+ args[0].asString(runtime).utf8(runtime),
604
+ static_cast<unsigned int>(args[1].asNumber()));
605
+ return Value::undefined();
606
+ }));
607
+ }
608
+
609
+ void bindNativePerformanceNow(Runtime& runtime) {
610
+ runtime.global().setProperty(
611
+ runtime,
612
+ "nativePerformanceNow",
613
+ Function::createFromHostFunction(
614
+ runtime,
615
+ PropNameID::forAscii(runtime, "nativePerformanceNow"),
616
+ 0,
617
+ [](jsi::Runtime& runtime,
618
+ const jsi::Value&,
619
+ const jsi::Value* args,
620
+ size_t /*count*/) {
621
+ return HighResTimeStamp::now().toDOMHighResTimeStamp();
622
+ }));
623
+ }
624
+
625
+ } // namespace facebook::react
626
+
627
+ #if _MSC_VER
628
+ #pragma warning(pop)
629
+ #endif