react-native-windows 0.78.5 → 0.78.7

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 (189) hide show
  1. package/Directory.Build.props +6 -4
  2. package/Folly/Folly.vcxproj +46 -6
  3. package/Folly/Folly.vcxproj.filters +16 -4
  4. package/Folly/TEMP_UntilFollyUpdate/ConstexprMath.h +26 -18
  5. package/Folly/TEMP_UntilFollyUpdate/Conv.cpp +1205 -0
  6. package/Folly/TEMP_UntilFollyUpdate/chrono/Hardware.h +155 -0
  7. package/Folly/TEMP_UntilFollyUpdate/concurrency/CacheLocality.cpp +633 -0
  8. package/Folly/TEMP_UntilFollyUpdate/{dynamic-inl.h → json/dynamic-inl.h} +3 -4
  9. package/Folly/TEMP_UntilFollyUpdate/{json.cpp → json/json.cpp} +14 -10
  10. package/Folly/TEMP_UntilFollyUpdate/lang/SafeAssert.h +7 -14
  11. package/Folly/TEMP_UntilFollyUpdate/lang/ToAscii.h +6 -6
  12. package/Folly/ThreadNameStub.cpp +10 -0
  13. package/Folly/cgmanifest.json +11 -1
  14. package/Libraries/Components/View/View.windows.js +107 -56
  15. package/Libraries/Components/View/ViewAccessibility.d.ts +60 -1
  16. package/Libraries/Image/Image.windows.js +42 -21
  17. package/Libraries/Modal/Modal.d.ts +7 -0
  18. package/Libraries/Modal/Modal.windows.js +7 -1
  19. package/Libraries/NativeComponent/BaseViewConfig.windows.js +3 -0
  20. package/Libraries/Text/Text.d.ts +18 -0
  21. package/Microsoft.ReactNative/AsynchronousEventBeat.cpp +4 -25
  22. package/Microsoft.ReactNative/AsynchronousEventBeat.h +0 -3
  23. package/Microsoft.ReactNative/Base/FollyIncludes.h +1 -0
  24. package/Microsoft.ReactNative/CallInvoker.cpp +42 -0
  25. package/Microsoft.ReactNative/CallInvoker.h +34 -0
  26. package/Microsoft.ReactNative/{JSDispatcherWriter.cpp → CallInvokerWriter.cpp} +35 -47
  27. package/Microsoft.ReactNative/CallInvokerWriter.h +74 -0
  28. package/Microsoft.ReactNative/CompositionComponentView.idl +0 -5
  29. package/Microsoft.ReactNative/CompositionSwitcher.idl +7 -0
  30. package/Microsoft.ReactNative/Fabric/AbiViewProps.cpp +8 -10
  31. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +4 -1
  32. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp +12 -2
  33. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.h +2 -0
  34. package/Microsoft.ReactNative/Fabric/Composition/CompositionAnnotationProvider.cpp +100 -0
  35. package/Microsoft.ReactNative/Fabric/Composition/CompositionAnnotationProvider.h +31 -0
  36. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +77 -11
  37. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +43 -1
  38. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +7 -0
  39. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +86 -56
  40. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +5 -1
  41. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +0 -4
  42. package/Microsoft.ReactNative/Fabric/Composition/CompositionUIService.cpp +0 -2
  43. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +118 -63
  44. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +2 -0
  45. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +133 -8
  46. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +16 -2
  47. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.cpp +4 -2
  48. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.h +9 -1
  49. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +34 -11
  50. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +3 -0
  51. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +133 -135
  52. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +9 -6
  53. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +46 -49
  54. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +6 -1
  55. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +13 -8
  56. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +5 -2
  57. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +146 -25
  58. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +14 -0
  59. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +160 -12
  60. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +6 -0
  61. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputEventEmitter.cpp +47 -0
  62. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputEventEmitter.h +15 -1
  63. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputProps.cpp +6 -2
  64. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputProps.h +4 -1
  65. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +7 -9
  66. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.h +4 -1
  67. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +5 -0
  68. package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +40 -36
  69. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +68 -0
  70. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +11 -0
  71. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +70 -13
  72. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +10 -2
  73. package/Microsoft.ReactNative/Fabric/ImageManager.cpp +5 -5
  74. package/Microsoft.ReactNative/Fabric/ImageRequestParams.cpp +26 -0
  75. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +47 -8
  76. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +10 -1
  77. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/CompositionAccessibilityProps.h +67 -0
  78. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.cpp +22 -4
  79. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.h +15 -2
  80. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +20 -0
  81. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.h +5 -0
  82. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/MouseEvent.h +20 -0
  83. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/HostPlatformColor.h +5 -8
  84. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorParser.h +1 -2
  85. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +247 -45
  86. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +15 -0
  87. package/Microsoft.ReactNative/Fabric/platform/react/threading/MessageQueueThreadImpl.cpp +39 -0
  88. package/Microsoft.ReactNative/Fabric/platform/react/threading/MessageQueueThreadImpl.h +54 -0
  89. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.cpp +126 -0
  90. package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.h +73 -0
  91. package/Microsoft.ReactNative/IReactContext.cpp +17 -0
  92. package/Microsoft.ReactNative/IReactContext.h +1 -0
  93. package/Microsoft.ReactNative/IReactContext.idl +18 -1
  94. package/Microsoft.ReactNative/IReactDispatcher.idl +1 -0
  95. package/Microsoft.ReactNative/IReactModuleBuilder.cpp +12 -0
  96. package/Microsoft.ReactNative/IReactModuleBuilder.h +2 -0
  97. package/Microsoft.ReactNative/IReactModuleBuilder.idl +8 -0
  98. package/Microsoft.ReactNative/JsiApi.cpp +10 -2
  99. package/Microsoft.ReactNative/JsiApi.h +1 -0
  100. package/Microsoft.ReactNative/JsiApi.idl +1 -0
  101. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +0 -3
  102. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +2 -3
  103. package/Microsoft.ReactNative/Modules/AlertModule.cpp +7 -12
  104. package/Microsoft.ReactNative/Modules/Animated/AnimationDriver.cpp +2 -1
  105. package/Microsoft.ReactNative/Modules/Animated/NativeAnimatedModule.cpp +4 -8
  106. package/Microsoft.ReactNative/Modules/AppStateModule.cpp +2 -2
  107. package/Microsoft.ReactNative/Modules/ClipboardModule.cpp +6 -8
  108. package/Microsoft.ReactNative/Modules/ClipboardModule.h +1 -1
  109. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +6 -15
  110. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +13 -24
  111. package/Microsoft.ReactNative/QuirkSettings.cpp +0 -16
  112. package/Microsoft.ReactNative/QuirkSettings.h +0 -3
  113. package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +11 -1
  114. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +78 -68
  115. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -2
  116. package/Microsoft.ReactNative/ReactInstanceSettings.cpp +12 -0
  117. package/Microsoft.ReactNative/ReactInstanceSettings.h +2 -0
  118. package/Microsoft.ReactNative/ReactInstanceSettings.idl +6 -0
  119. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -0
  120. package/Microsoft.ReactNative/ReactSupport.cpp +44 -11
  121. package/Microsoft.ReactNative/RedBox.cpp +30 -1
  122. package/Microsoft.ReactNative/SchedulerSettings.cpp +4 -4
  123. package/Microsoft.ReactNative/SchedulerSettings.h +1 -1
  124. package/Microsoft.ReactNative/TurboModulesProvider.cpp +30 -12
  125. package/Microsoft.ReactNative/Utils/ImageUtils.h +1 -0
  126. package/Microsoft.ReactNative/Utils/LocalBundleReader.cpp +37 -31
  127. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.cpp +1 -0
  128. package/Microsoft.ReactNative.Cxx/ApiLoaders/JSRuntimeApi.inc +2 -0
  129. package/Microsoft.ReactNative.Cxx/ApiLoaders/NodeApi_posix.cpp +1 -1
  130. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.cpp +94 -27
  131. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.h +27 -6
  132. package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.cpp +45 -11
  133. package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.h +6 -0
  134. package/Microsoft.ReactNative.Cxx/JSI/decorator.h +220 -0
  135. package/Microsoft.ReactNative.Cxx/JSI/instrumentation.h +28 -0
  136. package/Microsoft.ReactNative.Cxx/JSI/jsi-inl.h +6 -0
  137. package/Microsoft.ReactNative.Cxx/JSI/jsi.cpp +241 -4
  138. package/Microsoft.ReactNative.Cxx/JSI/jsi.h +207 -19
  139. package/Microsoft.ReactNative.Cxx/JSValue.cpp +19 -3
  140. package/Microsoft.ReactNative.Cxx/JSValue.h +15 -7
  141. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +2 -2
  142. package/Microsoft.ReactNative.Cxx/NativeModules.h +60 -2
  143. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.cpp +1267 -614
  144. package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.h +4 -2
  145. package/Microsoft.ReactNative.Cxx/ReactContext.h +7 -0
  146. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp +11 -13
  147. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +2 -3
  148. package/Microsoft.ReactNative.Cxx/node-api/js_native_api.h +81 -20
  149. package/Microsoft.ReactNative.Cxx/node-api/js_native_api_types.h +47 -2
  150. package/Microsoft.ReactNative.Cxx/node-api/js_runtime_api.h +13 -0
  151. package/Microsoft.ReactNative.Cxx/stubs/glog/logging.h +1 -1
  152. package/Microsoft.ReactNative.Managed/ReactContext.cs +3 -1
  153. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  154. package/PropertySheets/JSEngine.props +1 -1
  155. package/PropertySheets/React.Cpp.props +2 -1
  156. package/PropertySheets/WebView2.props +1 -1
  157. package/PropertySheets/WinUI.props +2 -2
  158. package/ReactCommon/TEMP_UntilReactCommonUpdate/jserrorhandler/JsErrorHandler.cpp +429 -0
  159. package/ReactCommon/cgmanifest.json +1 -1
  160. package/Shared/HermesRuntimeHolder.cpp +6 -0
  161. package/Shared/JSI/ChakraRuntime.cpp +4 -0
  162. package/Shared/JSI/ChakraRuntime.h +2 -0
  163. package/Shared/Modules/BlobModule.cpp +14 -16
  164. package/Shared/Modules/BlobModule.h +3 -1
  165. package/Shared/Shared.vcxitems +11 -7
  166. package/Shared/Shared.vcxitems.filters +6 -1
  167. package/Shared/TurboModuleManager.cpp +0 -15
  168. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +6 -6
  169. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +6 -6
  170. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +6 -6
  171. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +6 -6
  172. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +6 -6
  173. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +6 -6
  174. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +6 -6
  175. package/codegen/react/components/rnwcore/InputAccessory.g.h +6 -6
  176. package/codegen/react/components/rnwcore/ModalHostView.g.h +11 -7
  177. package/codegen/react/components/rnwcore/Props.cpp +2 -1
  178. package/codegen/react/components/rnwcore/Props.h +1 -0
  179. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +6 -6
  180. package/codegen/react/components/rnwcore/SafeAreaView.g.h +6 -6
  181. package/codegen/react/components/rnwcore/Switch.g.h +6 -6
  182. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +6 -6
  183. package/index.windows.js +4 -2
  184. package/package.json +3 -4
  185. package/src/private/specs/components/RCTModalHostViewNativeComponent.js +8 -0
  186. package/stubs/glog/logging.h +1 -1
  187. package/Microsoft.ReactNative/JSDispatcherWriter.h +0 -47
  188. package/Microsoft.ReactNative/SynchronousEventBeat.cpp +0 -51
  189. package/Microsoft.ReactNative/SynchronousEventBeat.h +0 -31
@@ -49,17 +49,17 @@ facebook::react::RuntimeExecutor &GetRuntimeExecutor(
49
49
  }
50
50
 
51
51
  winrt::Microsoft::ReactNative::ReactPropertyId<
52
- winrt::Microsoft::ReactNative::ReactNonAbiValue<std::shared_ptr<facebook::react::RuntimeScheduler>>>
52
+ winrt::Microsoft::ReactNative::ReactNonAbiValue<std::weak_ptr<facebook::react::RuntimeScheduler>>>
53
53
  RuntimeSchedulerProperty() noexcept {
54
54
  winrt::Microsoft::ReactNative::ReactPropertyId<
55
- winrt::Microsoft::ReactNative::ReactNonAbiValue<std::shared_ptr<facebook::react::RuntimeScheduler>>>
55
+ winrt::Microsoft::ReactNative::ReactNonAbiValue<std::weak_ptr<facebook::react::RuntimeScheduler>>>
56
56
  propId{L"ReactNative", L"RuntimeScheduler"};
57
57
  return propId;
58
58
  }
59
59
 
60
60
  void SetRuntimeScheduler(
61
61
  winrt::Microsoft::ReactNative::ReactPropertyBag properties,
62
- const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler) noexcept {
62
+ const std::weak_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler) noexcept {
63
63
  properties.Set(RuntimeSchedulerProperty(), runtimeScheduler);
64
64
  }
65
65
 
@@ -68,7 +68,7 @@ std::shared_ptr<facebook::react::RuntimeScheduler> RuntimeSchedulerFromPropertie
68
68
  auto runtimeScheduler = properties.Get(RuntimeSchedulerProperty());
69
69
  if (!runtimeScheduler)
70
70
  return nullptr;
71
- return runtimeScheduler.Value();
71
+ return runtimeScheduler.Value().lock();
72
72
  }
73
73
 
74
74
  } // namespace Microsoft::ReactNative::SchedulerSettings
@@ -27,7 +27,7 @@ facebook::react::RuntimeExecutor &GetRuntimeExecutor(
27
27
 
28
28
  void SetRuntimeScheduler(
29
29
  winrt::Microsoft::ReactNative::ReactPropertyBag properties,
30
- const std::shared_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler) noexcept;
30
+ const std::weak_ptr<facebook::react::RuntimeScheduler> &runtimeScheduler) noexcept;
31
31
 
32
32
  std::shared_ptr<facebook::react::RuntimeScheduler> RuntimeSchedulerFromProperties(
33
33
  winrt::Microsoft::ReactNative::ReactPropertyBag properties) noexcept;
@@ -7,9 +7,10 @@
7
7
 
8
8
  #include "pch.h"
9
9
  #include "TurboModulesProvider.h"
10
+ #include <IReactContext.h>
10
11
  #include <ReactCommon/TurboModuleUtils.h>
11
12
  #include <react/bridging/EventEmitter.h>
12
- #include "JSDispatcherWriter.h"
13
+ #include "CallInvokerWriter.h"
13
14
  #include "JSValueWriter.h"
14
15
  #include "JsiApi.h"
15
16
  #include "JsiReader.h"
@@ -42,6 +43,14 @@ struct TurboModuleBuilder : winrt::implements<TurboModuleBuilder, IReactModuleBu
42
43
  initializer(m_reactContext);
43
44
  }
44
45
 
46
+ void AddJsiInitializer(JsiInitializerDelegate const &initializer) noexcept {
47
+ initializer(
48
+ m_reactContext,
49
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactContext>(m_reactContext)
50
+ ->GetInner()
51
+ .JsiRuntime());
52
+ }
53
+
45
54
  void AddConstantProvider(ConstantProviderDelegate const &constantProvider) noexcept {
46
55
  EnsureMemberNotSet("getConstants", false);
47
56
  m_constantProviders.push_back(constantProvider);
@@ -119,6 +128,10 @@ class TurboModuleImpl : public facebook::react::TurboModule {
119
128
  m_moduleBuilder(winrt::make_self<TurboModuleBuilder>(reactContext)),
120
129
  m_providedModule(reactModuleProvider(m_moduleBuilder.as<IReactModuleBuilder>())) {
121
130
  if (auto hostObject = m_providedModule.try_as<IJsiHostObject>()) {
131
+ // Force ABI runtime creation if it hasn't already been created
132
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactContext>(m_reactContext)
133
+ ->GetInner()
134
+ .JsiRuntime();
122
135
  m_hostObjectWrapper = std::make_shared<implementation::HostObjectWrapper>(hostObject);
123
136
  }
124
137
  }
@@ -202,7 +215,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
202
215
  runtime,
203
216
  propName,
204
217
  0,
205
- [jsDispatcher = m_reactContext.JSDispatcher(),
218
+ [jsInvoker = jsInvoker_,
206
219
  method = methodInfo.Method,
207
220
  longLivedObjectCollection = m_longLivedObjectCollection](
208
221
  facebook::jsi::Runtime &rt,
@@ -212,11 +225,13 @@ class TurboModuleImpl : public facebook::react::TurboModule {
212
225
  VerifyElseCrash(argCount > 0);
213
226
  if (auto strongLongLivedObjectCollection = longLivedObjectCollection.lock()) {
214
227
  auto jsiRuntimeHolder = LongLivedJsiRuntime::CreateWeak(strongLongLivedObjectCollection, rt);
228
+ auto writer = winrt::make<CallInvokerWriter>(jsInvoker, jsiRuntimeHolder);
215
229
  method(
216
230
  winrt::make<JsiReader>(rt, args, argCount - 1),
217
- winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder),
231
+ writer,
218
232
  MakeCallback(rt, strongLongLivedObjectCollection, args[argCount - 1]),
219
233
  nullptr);
234
+ winrt::get_self<CallInvokerWriter>(writer)->ExitCurrentCallInvokeScope();
220
235
  }
221
236
  return facebook::jsi::Value::undefined();
222
237
  });
@@ -225,7 +240,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
225
240
  runtime,
226
241
  propName,
227
242
  0,
228
- [jsDispatcher = m_reactContext.JSDispatcher(),
243
+ [jsInvoker = jsInvoker_,
229
244
  method = methodInfo.Method,
230
245
  longLivedObjectCollection = m_longLivedObjectCollection](
231
246
  facebook::jsi::Runtime &rt,
@@ -240,11 +255,12 @@ class TurboModuleImpl : public facebook::react::TurboModule {
240
255
  auto weakCallback2 = LongLivedJsiFunction::CreateWeak(
241
256
  strongLongLivedObjectCollection, rt, args[argCount - 1].getObject(rt).getFunction(rt));
242
257
 
258
+ auto writer = winrt::make<CallInvokerWriter>(jsInvoker, jsiRuntimeHolder);
243
259
  method(
244
260
  winrt::make<JsiReader>(rt, args, argCount - 2),
245
- winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder),
261
+ writer,
246
262
  [weakCallback1, weakCallback2, jsiRuntimeHolder](const IJSValueWriter &writer) noexcept {
247
- writer.as<JSDispatcherWriter>()->WithResultArgs(
263
+ writer.as<CallInvokerWriter>()->WithResultArgs(
248
264
  [weakCallback1, weakCallback2, jsiRuntimeHolder](
249
265
  facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t count) {
250
266
  if (auto callback1 = weakCallback1.lock()) {
@@ -260,7 +276,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
260
276
  });
261
277
  },
262
278
  [weakCallback1, weakCallback2, jsiRuntimeHolder](const IJSValueWriter &writer) noexcept {
263
- writer.as<JSDispatcherWriter>()->WithResultArgs(
279
+ writer.as<CallInvokerWriter>()->WithResultArgs(
264
280
  [weakCallback1, weakCallback2, jsiRuntimeHolder](
265
281
  facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t count) {
266
282
  if (auto callback2 = weakCallback2.lock()) {
@@ -275,6 +291,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
275
291
  }
276
292
  });
277
293
  });
294
+ winrt::get_self<CallInvokerWriter>(writer)->ExitCurrentCallInvokeScope();
278
295
  }
279
296
  return facebook::jsi::Value::undefined();
280
297
  });
@@ -283,7 +300,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
283
300
  runtime,
284
301
  propName,
285
302
  0,
286
- [jsDispatcher = m_reactContext.JSDispatcher(),
303
+ [jsInvoker = jsInvoker_,
287
304
  method = methodInfo.Method,
288
305
  longLivedObjectCollection = m_longLivedObjectCollection](
289
306
  facebook::jsi::Runtime &rt,
@@ -293,7 +310,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
293
310
  if (auto strongLongLivedObjectCollection = longLivedObjectCollection.lock()) {
294
311
  auto jsiRuntimeHolder = LongLivedJsiRuntime::CreateWeak(strongLongLivedObjectCollection, rt);
295
312
  auto argReader = winrt::make<JsiReader>(rt, args, count);
296
- auto argWriter = winrt::make<JSDispatcherWriter>(jsDispatcher, jsiRuntimeHolder);
313
+ auto argWriter = winrt::make<CallInvokerWriter>(jsInvoker, jsiRuntimeHolder);
297
314
  return facebook::react::createPromiseAsJSIValue(
298
315
  rt,
299
316
  [method, argReader, argWriter, strongLongLivedObjectCollection, jsiRuntimeHolder](
@@ -306,7 +323,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
306
323
  argReader,
307
324
  argWriter,
308
325
  [weakResolve, weakReject, jsiRuntimeHolder](const IJSValueWriter &writer) {
309
- writer.as<JSDispatcherWriter>()->WithResultArgs(
326
+ writer.as<CallInvokerWriter>()->WithResultArgs(
310
327
  [weakResolve, weakReject, jsiRuntimeHolder](
311
328
  facebook::jsi::Runtime &runtime,
312
329
  facebook::jsi::Value const *args,
@@ -325,7 +342,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
325
342
  });
326
343
  },
327
344
  [weakResolve, weakReject, jsiRuntimeHolder](const IJSValueWriter &writer) {
328
- writer.as<JSDispatcherWriter>()->WithResultArgs(
345
+ writer.as<CallInvokerWriter>()->WithResultArgs(
329
346
  [weakResolve, weakReject, jsiRuntimeHolder](
330
347
  facebook::jsi::Runtime &runtime,
331
348
  facebook::jsi::Value const *args,
@@ -356,6 +373,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
356
373
  }
357
374
  });
358
375
  });
376
+ winrt::get_self<CallInvokerWriter>(argWriter)->ExitCurrentCallInvokeScope();
359
377
  });
360
378
  }
361
379
  return facebook::jsi::Value::undefined();
@@ -438,7 +456,7 @@ class TurboModuleImpl : public facebook::react::TurboModule {
438
456
  auto weakCallback =
439
457
  LongLivedJsiFunction::CreateWeak(longLivedObjectCollection, rt, callback.getObject(rt).getFunction(rt));
440
458
  return [weakCallback = std::move(weakCallback)](const IJSValueWriter &writer) noexcept {
441
- writer.as<JSDispatcherWriter>()->WithResultArgs(
459
+ writer.as<CallInvokerWriter>()->WithResultArgs(
442
460
  [weakCallback](facebook::jsi::Runtime &rt, facebook::jsi::Value const *args, size_t count) {
443
461
  if (auto callback = weakCallback.lock()) {
444
462
  callback->Value().call(rt, args, count);
@@ -15,6 +15,7 @@ struct ReactImageSource {
15
15
  std::string uri;
16
16
  std::string method;
17
17
  std::vector<std::pair<std::string, std::string>> headers;
18
+ std::string body;
18
19
  double width = 0;
19
20
  double height = 0;
20
21
  double scale = 1.0;
@@ -54,38 +54,44 @@ std::string GetBundleFromEmbeddedResource(const winrt::Windows::Foundation::Uri
54
54
  }
55
55
 
56
56
  std::future<std::string> LocalBundleReader::LoadBundleAsync(const std::wstring bundleUri) {
57
- co_await winrt::resume_background();
58
-
59
- winrt::Windows::Storage::StorageFile file{nullptr};
60
-
61
- // Supports "ms-appx://" or "ms-appdata://"
62
- if (bundleUri.starts_with(L"ms-app")) {
63
- winrt::Windows::Foundation::Uri uri(bundleUri);
64
- file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri);
65
- } else if (bundleUri.starts_with(L"resource://")) {
66
- winrt::Windows::Foundation::Uri uri(bundleUri);
67
- co_return GetBundleFromEmbeddedResource(uri);
68
- } else {
69
- file = co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(bundleUri);
57
+ try {
58
+ co_await winrt::resume_background();
59
+
60
+ winrt::Windows::Storage::StorageFile file{nullptr};
61
+
62
+ // Supports "ms-appx://" or "ms-appdata://"
63
+ if (bundleUri.starts_with(L"ms-app")) {
64
+ winrt::Windows::Foundation::Uri uri(bundleUri);
65
+ file = co_await winrt::Windows::Storage::StorageFile::GetFileFromApplicationUriAsync(uri);
66
+ } else if (bundleUri.starts_with(L"resource://")) {
67
+ winrt::Windows::Foundation::Uri uri(bundleUri);
68
+ co_return GetBundleFromEmbeddedResource(uri);
69
+ } else {
70
+ file = co_await winrt::Windows::Storage::StorageFile::GetFileFromPathAsync(bundleUri);
71
+ }
72
+
73
+ // Read the buffer manually to avoid a Utf8 -> Utf16 -> Utf8 encoding
74
+ // roundtrip.
75
+ auto fileBuffer{co_await winrt::Windows::Storage::FileIO::ReadBufferAsync(file)};
76
+ auto dataReader{winrt::Windows::Storage::Streams::DataReader::FromBuffer(fileBuffer)};
77
+
78
+ // No need to use length + 1, STL guarantees that string storage is null-terminated.
79
+ std::string script(fileBuffer.Length(), '\0');
80
+
81
+ // Construct the array_view to slice into the first fileBuffer.Length bytes.
82
+ // DataReader.ReadBytes will read as many bytes as are present in the
83
+ // array_view. The backing string has fileBuffer.Length() + 1 bytes, without
84
+ // an explicit end it will read 1 byte to many and throw.
85
+ dataReader.ReadBytes(winrt::array_view<uint8_t>{
86
+ reinterpret_cast<uint8_t *>(&script[0]), reinterpret_cast<uint8_t *>(&script[script.length()])});
87
+ dataReader.Close();
88
+
89
+ co_return script;
90
+ }
91
+ // RuntimeScheduler only handles std::exception or jsi::JSError
92
+ catch (winrt::hresult_error const &e) {
93
+ throw std::exception(winrt::to_string(e.message()).c_str());
70
94
  }
71
-
72
- // Read the buffer manually to avoid a Utf8 -> Utf16 -> Utf8 encoding
73
- // roundtrip.
74
- auto fileBuffer{co_await winrt::Windows::Storage::FileIO::ReadBufferAsync(file)};
75
- auto dataReader{winrt::Windows::Storage::Streams::DataReader::FromBuffer(fileBuffer)};
76
-
77
- // No need to use length + 1, STL guarantees that string storage is null-terminated.
78
- std::string script(fileBuffer.Length(), '\0');
79
-
80
- // Construct the array_view to slice into the first fileBuffer.Length bytes.
81
- // DataReader.ReadBytes will read as many bytes as are present in the
82
- // array_view. The backing string has fileBuffer.Length() + 1 bytes, without
83
- // an explicit end it will read 1 byte to many and throw.
84
- dataReader.ReadBytes(winrt::array_view<uint8_t>{
85
- reinterpret_cast<uint8_t *>(&script[0]), reinterpret_cast<uint8_t *>(&script[script.length()])});
86
- dataReader.Close();
87
-
88
- co_return script;
89
95
  }
90
96
 
91
97
  std::string LocalBundleReader::LoadBundle(const std::wstring &bundlePath) {
@@ -9,6 +9,7 @@ EXTERN_C_START
9
9
  extern napi_status NAPI_CDECL default_jsr_open_napi_env_scope(napi_env env, jsr_napi_env_scope *scope);
10
10
  extern napi_status NAPI_CDECL default_jsr_close_napi_env_scope(napi_env env, jsr_napi_env_scope scope);
11
11
  extern napi_status NAPI_CDECL default_jsr_get_description(napi_env env, const char **result);
12
+ extern napi_status NAPI_CDECL default_jsr_queue_microtask(napi_env env, napi_value callback);
12
13
  extern napi_status NAPI_CDECL default_jsr_drain_microtasks(napi_env env, int32_t max_count_hint, bool *result);
13
14
  extern napi_status NAPI_CDECL default_jsr_is_inspectable(napi_env env, bool *result);
14
15
 
@@ -17,6 +17,7 @@
17
17
  JSR_FUNC(jsr_collect_garbage)
18
18
  JSR_FUNC(jsr_config_enable_gc_api)
19
19
  JSR_FUNC(jsr_config_enable_inspector)
20
+ JSR_FUNC(jsr_config_set_explicit_microtasks)
20
21
  JSR_FUNC(jsr_config_set_inspector_break_on_start)
21
22
  JSR_FUNC(jsr_config_set_inspector_port)
22
23
  JSR_FUNC(jsr_config_set_inspector_runtime_name)
@@ -33,6 +34,7 @@ JSR_FUNC(jsr_runtime_get_node_api_env)
33
34
 
34
35
  // The JS runtime functions needed for JSI.
35
36
  JSR_JSI_FUNC(jsr_close_napi_env_scope)
37
+ JSR_JSI_FUNC(jsr_queue_microtask)
36
38
  JSR_JSI_FUNC(jsr_drain_microtasks)
37
39
  JSR_JSI_FUNC(jsr_get_description)
38
40
  JSR_JSI_FUNC(jsr_is_inspectable)
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
 
4
- #include "LibLoader.h"
4
+ #include "NodeApi.h"
5
5
 
6
6
  namespace Microsoft::NodeApiJsi {
7
7
 
@@ -4,6 +4,7 @@
4
4
  #include "pch.h"
5
5
  #include "JsiAbiApi.h"
6
6
  #include <utility>
7
+ #include "ReactContext.h"
7
8
  #include "ReactNonAbiValue.h"
8
9
  #include "winrt/Windows.Foundation.Collections.h"
9
10
 
@@ -14,6 +15,16 @@ using namespace facebook::jsi;
14
15
 
15
16
  namespace winrt::Microsoft::ReactNative {
16
17
 
18
+ namespace Details {
19
+ // Try to get JSI Runtime for the ReactContext
20
+ // If it is not found, then create it based on context JSI runtime and store it in the context.Properties().
21
+ // The function returns nullptr if the current context does not have JSI runtime.
22
+ // It makes sure that the JSI runtime holder is removed when the instance is unloaded.
23
+ JsiAbiRuntime *TryGetOrCreateContextRuntime(
24
+ winrt::Microsoft::ReactNative::ReactContext const &context,
25
+ JsiRuntime const &runtimeHandle) noexcept;
26
+ } // namespace Details
27
+
17
28
  // The macro to simplify recording JSI exceptions.
18
29
  // It looks strange to keep the normal structure of the try/catch in code.
19
30
  #define JSI_RUNTIME_SET_ERROR(runtime) \
@@ -132,6 +143,52 @@ std::shared_ptr<facebook::jsi::HostObject> const &JsiHostObjectWrapper::HostObje
132
143
  return m_hostObject;
133
144
  }
134
145
 
146
+ //===========================================================================
147
+ // JsiHostObjectGetOrCreateWrapper implementation
148
+ //===========================================================================
149
+
150
+ JsiHostObjectGetOrCreateWrapper::JsiHostObjectGetOrCreateWrapper(
151
+ const winrt::Microsoft::ReactNative::IReactContext &context,
152
+ std::shared_ptr<HostObject> &&hostObject) noexcept
153
+ : m_hostObject(std::move(hostObject)), m_context(context) {}
154
+
155
+ JsiValueRef JsiHostObjectGetOrCreateWrapper::GetProperty(JsiRuntime const &runtime, JsiPropertyIdRef const &name) try {
156
+ JsiAbiRuntime *rt{Details::TryGetOrCreateContextRuntime(m_context, runtime)};
157
+ JsiAbiRuntime::PropNameIDRef nameRef{name};
158
+ return JsiAbiRuntime::DetachJsiValueRef(m_hostObject->get(*rt, nameRef));
159
+ } catch (JSI_RUNTIME_SET_ERROR(runtime)) {
160
+ throw;
161
+ }
162
+
163
+ void JsiHostObjectGetOrCreateWrapper::SetProperty(
164
+ JsiRuntime const &runtime,
165
+ JsiPropertyIdRef const &name,
166
+ JsiValueRef const &value) try {
167
+ JsiAbiRuntime *rt{Details::TryGetOrCreateContextRuntime(m_context, runtime)};
168
+ m_hostObject->set(*rt, JsiAbiRuntime::PropNameIDRef{name}, JsiAbiRuntime::ValueRef(value));
169
+ } catch (JSI_RUNTIME_SET_ERROR(runtime)) {
170
+ throw;
171
+ }
172
+
173
+ winrt::Windows::Foundation::Collections::IVector<JsiPropertyIdRef> JsiHostObjectGetOrCreateWrapper::GetPropertyIds(
174
+ JsiRuntime const &runtime) try {
175
+ JsiAbiRuntime *rt{Details::TryGetOrCreateContextRuntime(m_context, runtime)};
176
+ auto names = m_hostObject->getPropertyNames(*rt);
177
+ std::vector<JsiPropertyIdRef> result;
178
+ result.reserve(names.size());
179
+ for (auto &name : names) {
180
+ result.push_back(JsiAbiRuntime::DetachJsiPropertyIdRef(std::move(name)));
181
+ }
182
+
183
+ return winrt::single_threaded_vector<JsiPropertyIdRef>(std::move(result));
184
+ } catch (JSI_RUNTIME_SET_ERROR(runtime)) {
185
+ throw;
186
+ }
187
+
188
+ std::shared_ptr<facebook::jsi::HostObject> const &JsiHostObjectGetOrCreateWrapper::HostObjectSharedPtr() noexcept {
189
+ return m_hostObject;
190
+ }
191
+
135
192
  //===========================================================================
136
193
  // JsiHostFunctionWrapper implementation
137
194
  //===========================================================================
@@ -162,38 +219,41 @@ JsiValueRef JsiHostFunctionWrapper::operator()(
162
219
  // JsiAbiRuntime implementation
163
220
  //===========================================================================
164
221
 
165
- // The tls_jsiAbiRuntimeMap map allows us to associate JsiAbiRuntime with JsiRuntime.
166
- // The association is thread-specific and DLL-specific.
167
- // It is thread specific because we want to have the safe access only in JS thread.
168
- // It is DLL-specific because JsiAbiRuntime is not ABI-safe and each module DLL will
169
- // have their own JsiAbiRuntime instance.
170
- static thread_local std::map<void *, JsiAbiRuntime *> *tls_jsiAbiRuntimeMap{nullptr};
222
+ // The s_jsiAbiRuntimeMap map allows us to associate JsiAbiRuntime with JsiRuntime.
223
+ // The association is DLL-specific because JsiAbiRuntime is not ABI-safe and each module DLL will have their own
224
+ // JsiAbiRuntime instance.
225
+ static std::map<void *, JsiAbiRuntime *> *s_jsiAbiRuntimeMap{nullptr};
226
+ static std::recursive_mutex s_jsiRuntimeMapMutex;
171
227
 
172
228
  JsiAbiRuntime::JsiAbiRuntime(JsiRuntime const &runtime) noexcept : m_runtime{runtime} {
173
229
  VerifyElseCrashSz(runtime, "JSI runtime is null");
174
- VerifyElseCrashSz(
175
- GetFromJsiRuntime(runtime) == nullptr,
176
- "We can have only one instance of JsiAbiRuntime for JsiRuntime in the thread.");
177
- if (!tls_jsiAbiRuntimeMap) {
178
- tls_jsiAbiRuntimeMap = new std::map<void *, JsiAbiRuntime *>();
230
+
231
+ {
232
+ std::lock_guard<std::recursive_mutex> guard(s_jsiRuntimeMapMutex);
233
+ VerifyElseCrashSz(
234
+ GetFromJsiRuntime(runtime) == nullptr, "We can have only one instance of JsiAbiRuntime for a JsiRuntime.");
235
+
236
+ if (!s_jsiAbiRuntimeMap) {
237
+ s_jsiAbiRuntimeMap = new std::map<void *, JsiAbiRuntime *>();
238
+ }
239
+ s_jsiAbiRuntimeMap->try_emplace(get_abi(runtime), this);
179
240
  }
180
- tls_jsiAbiRuntimeMap->try_emplace(get_abi(runtime), this);
181
241
  }
182
242
 
183
243
  JsiAbiRuntime::~JsiAbiRuntime() {
184
- VerifyElseCrashSz(
185
- GetFromJsiRuntime(m_runtime) != nullptr, "JsiAbiRuntime must be called in the same thread where it was created.");
186
- tls_jsiAbiRuntimeMap->erase(get_abi(m_runtime));
187
- if (tls_jsiAbiRuntimeMap->empty()) {
188
- delete tls_jsiAbiRuntimeMap;
189
- tls_jsiAbiRuntimeMap = nullptr;
244
+ std::lock_guard<std::recursive_mutex> guard(s_jsiRuntimeMapMutex);
245
+ s_jsiAbiRuntimeMap->erase(get_abi(m_runtime));
246
+ if (s_jsiAbiRuntimeMap->empty()) {
247
+ delete s_jsiAbiRuntimeMap;
248
+ s_jsiAbiRuntimeMap = nullptr;
190
249
  }
191
250
  }
192
251
 
193
252
  /*static*/ JsiAbiRuntime *JsiAbiRuntime::GetFromJsiRuntime(JsiRuntime const &runtime) noexcept {
194
- if (tls_jsiAbiRuntimeMap && runtime) {
195
- auto it = tls_jsiAbiRuntimeMap->find(get_abi(runtime));
196
- if (it != tls_jsiAbiRuntimeMap->end()) {
253
+ std::lock_guard<std::recursive_mutex> guard(s_jsiRuntimeMapMutex);
254
+ if (s_jsiAbiRuntimeMap && runtime) {
255
+ auto it = s_jsiAbiRuntimeMap->find(get_abi(runtime));
256
+ if (it != s_jsiAbiRuntimeMap->end()) {
197
257
  return it->second;
198
258
  }
199
259
  }
@@ -233,6 +293,13 @@ bool JsiAbiRuntime::drainMicrotasks(int maxMicrotasksHint) try {
233
293
  throw;
234
294
  }
235
295
 
296
+ void JsiAbiRuntime::queueMicrotask(const facebook::jsi::Function &callback) try {
297
+ return m_runtime.QueueMicrotask(AsJsiObjectRef(callback));
298
+ } catch (hresult_error const &) {
299
+ RethrowJsiError();
300
+ throw;
301
+ }
302
+
236
303
  Object JsiAbiRuntime::global() try { return MakeObject(m_runtime.Global()); } catch (hresult_error const &) {
237
304
  RethrowJsiError();
238
305
  throw;
@@ -956,7 +1023,7 @@ JsiAbiRuntime::DataPointerValue::DataPointerValue(winrt::weak_ref<JsiRuntime> &&
956
1023
 
957
1024
  JsiAbiRuntime::DataPointerValue::DataPointerValue(uint64_t data) noexcept : m_data{data} {}
958
1025
 
959
- void JsiAbiRuntime::DataPointerValue::invalidate() {}
1026
+ void JsiAbiRuntime::DataPointerValue::invalidate() noexcept {}
960
1027
 
961
1028
  //===========================================================================
962
1029
  // JsiAbiRuntime::SymbolPointerValue implementation
@@ -967,7 +1034,7 @@ JsiAbiRuntime::SymbolPointerValue::SymbolPointerValue(
967
1034
  JsiSymbolRef &&symbol) noexcept
968
1035
  : DataPointerValue{std::move(weakRuntime), std::exchange(symbol.Data, 0)} {}
969
1036
 
970
- void JsiAbiRuntime::SymbolPointerValue::invalidate() {
1037
+ void JsiAbiRuntime::SymbolPointerValue::invalidate() noexcept {
971
1038
  if (m_data) {
972
1039
  if (auto runtime = m_weakRuntime.get()) {
973
1040
  m_weakRuntime = nullptr;
@@ -993,7 +1060,7 @@ JsiAbiRuntime::BigIntPointerValue::BigIntPointerValue(
993
1060
  JsiBigIntRef &&bigInt) noexcept
994
1061
  : DataPointerValue{std::move(weakRuntime), std::exchange(bigInt.Data, 0)} {}
995
1062
 
996
- void JsiAbiRuntime::BigIntPointerValue::invalidate() {
1063
+ void JsiAbiRuntime::BigIntPointerValue::invalidate() noexcept {
997
1064
  if (m_data) {
998
1065
  if (auto runtime = m_weakRuntime.get()) {
999
1066
  m_weakRuntime = nullptr;
@@ -1019,7 +1086,7 @@ JsiAbiRuntime::StringPointerValue::StringPointerValue(
1019
1086
  JsiStringRef &&str) noexcept
1020
1087
  : DataPointerValue{std::move(weakRuntime), std::exchange(str.Data, 0)} {}
1021
1088
 
1022
- void JsiAbiRuntime::StringPointerValue::invalidate() {
1089
+ void JsiAbiRuntime::StringPointerValue::invalidate() noexcept {
1023
1090
  if (m_data) {
1024
1091
  if (auto runtime = m_weakRuntime.get()) {
1025
1092
  m_weakRuntime = nullptr;
@@ -1047,7 +1114,7 @@ JsiAbiRuntime::ObjectPointerValue::ObjectPointerValue(
1047
1114
  JsiObjectRef &&obj) noexcept
1048
1115
  : DataPointerValue{std::move(weakRuntime), std::exchange(obj.Data, 0)} {}
1049
1116
 
1050
- void JsiAbiRuntime::ObjectPointerValue::invalidate() {
1117
+ void JsiAbiRuntime::ObjectPointerValue::invalidate() noexcept {
1051
1118
  if (m_data) {
1052
1119
  if (auto runtime = m_weakRuntime.get()) {
1053
1120
  m_weakRuntime = nullptr;
@@ -1075,7 +1142,7 @@ JsiAbiRuntime::PropNameIDPointerValue::PropNameIDPointerValue(
1075
1142
  JsiPropertyIdRef &&propertyId) noexcept
1076
1143
  : DataPointerValue{std::move(weakRuntime), std::exchange(propertyId.Data, 0)} {}
1077
1144
 
1078
- void JsiAbiRuntime::PropNameIDPointerValue::invalidate() {
1145
+ void JsiAbiRuntime::PropNameIDPointerValue::invalidate() noexcept {
1079
1146
  if (m_data) {
1080
1147
  if (auto runtime = m_weakRuntime.get()) {
1081
1148
  m_weakRuntime = nullptr;
@@ -54,6 +54,25 @@ struct JsiHostObjectWrapper : implements<JsiHostObjectWrapper, IJsiHostObject> {
54
54
  std::shared_ptr<facebook::jsi::HostObject> m_hostObject;
55
55
  };
56
56
 
57
+ // An ABI-safe wrapper for facebook::jsi::HostObject, similar to JsiHostObjectWrapper,
58
+ // but uses GetOrCreate for the AbiRuntime to ensure its created on first use
59
+ // This is important for use with TurboModules, which may not go through the ReactContext.CallInvoker
60
+ struct JsiHostObjectGetOrCreateWrapper : implements<JsiHostObjectGetOrCreateWrapper, IJsiHostObject> {
61
+ JsiHostObjectGetOrCreateWrapper(
62
+ const winrt::Microsoft::ReactNative::IReactContext &context,
63
+ std::shared_ptr<facebook::jsi::HostObject> &&hostObject) noexcept;
64
+
65
+ JsiValueRef GetProperty(JsiRuntime const &runtime, JsiPropertyIdRef const &name);
66
+ void SetProperty(JsiRuntime const &runtime, JsiPropertyIdRef const &name, JsiValueRef const &value);
67
+ winrt::Windows::Foundation::Collections::IVector<JsiPropertyIdRef> GetPropertyIds(JsiRuntime const &runtime);
68
+
69
+ std::shared_ptr<facebook::jsi::HostObject> const &HostObjectSharedPtr() noexcept;
70
+
71
+ private:
72
+ std::shared_ptr<facebook::jsi::HostObject> m_hostObject;
73
+ winrt::Microsoft::ReactNative::IReactContext m_context;
74
+ };
75
+
57
76
  // The function object that wraps up the facebook::jsi::HostFunctionType
58
77
  struct JsiHostFunctionWrapper {
59
78
  // We only support new and move constructors.
@@ -85,6 +104,7 @@ struct JsiAbiRuntime : facebook::jsi::Runtime {
85
104
  facebook::jsi::Value evaluatePreparedJavaScript(
86
105
  const std::shared_ptr<const facebook::jsi::PreparedJavaScript> &js) override;
87
106
  bool drainMicrotasks(int maxMicrotasksHint = -1) override;
107
+ void queueMicrotask(const facebook::jsi::Function &callback) override;
88
108
  facebook::jsi::Object global() override;
89
109
  std::string description() override;
90
110
  bool isInspectable() override;
@@ -225,6 +245,7 @@ struct JsiAbiRuntime : facebook::jsi::Runtime {
225
245
  // Allow access to the helper function
226
246
  friend struct JsiByteBufferWrapper;
227
247
  friend struct JsiHostObjectWrapper;
248
+ friend struct JsiHostObjectGetOrCreateWrapper;
228
249
  friend struct JsiHostFunctionWrapper;
229
250
  friend struct AbiJSError;
230
251
  friend struct AbiJSINativeException;
@@ -233,7 +254,7 @@ struct JsiAbiRuntime : facebook::jsi::Runtime {
233
254
  struct DataPointerValue : PointerValue {
234
255
  DataPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, uint64_t data) noexcept;
235
256
  DataPointerValue(uint64_t data) noexcept;
236
- void invalidate() override;
257
+ void invalidate() noexcept override;
237
258
 
238
259
  uint64_t m_data;
239
260
  winrt::weak_ref<JsiRuntime> m_weakRuntime;
@@ -241,35 +262,35 @@ struct JsiAbiRuntime : facebook::jsi::Runtime {
241
262
 
242
263
  struct SymbolPointerValue : DataPointerValue {
243
264
  SymbolPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, JsiSymbolRef &&symbol) noexcept;
244
- void invalidate() override;
265
+ void invalidate() noexcept override;
245
266
  static JsiSymbolRef const &GetData(PointerValue const *pv) noexcept;
246
267
  static JsiSymbolRef Detach(PointerValue const *pv) noexcept;
247
268
  };
248
269
 
249
270
  struct BigIntPointerValue : DataPointerValue {
250
271
  BigIntPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, JsiBigIntRef &&bigInt) noexcept;
251
- void invalidate() override;
272
+ void invalidate() noexcept override;
252
273
  static JsiBigIntRef const &GetData(PointerValue const *pv) noexcept;
253
274
  static JsiBigIntRef Detach(PointerValue const *pv) noexcept;
254
275
  };
255
276
 
256
277
  struct StringPointerValue : DataPointerValue {
257
278
  StringPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, JsiStringRef &&str) noexcept;
258
- void invalidate() override;
279
+ void invalidate() noexcept override;
259
280
  static JsiStringRef const &GetData(PointerValue const *pv) noexcept;
260
281
  static JsiStringRef Detach(PointerValue const *pv) noexcept;
261
282
  };
262
283
 
263
284
  struct ObjectPointerValue : DataPointerValue {
264
285
  ObjectPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, JsiObjectRef &&obj) noexcept;
265
- void invalidate() override;
286
+ void invalidate() noexcept override;
266
287
  static JsiObjectRef const &GetData(PointerValue const *pv) noexcept;
267
288
  static JsiObjectRef Detach(PointerValue const *pv) noexcept;
268
289
  };
269
290
 
270
291
  struct PropNameIDPointerValue : DataPointerValue {
271
292
  PropNameIDPointerValue(winrt::weak_ref<JsiRuntime> &&weakRuntime, JsiPropertyIdRef &&propertyId) noexcept;
272
- void invalidate() override;
293
+ void invalidate() noexcept override;
273
294
  static JsiPropertyIdRef const &GetData(PointerValue const *pv) noexcept;
274
295
  static JsiPropertyIdRef Detach(PointerValue const *pv) noexcept;
275
296
  };