react-native-windows 0.68.0-preview.4 → 0.68.0-preview.5

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 (27) hide show
  1. package/Microsoft.ReactNative/IViewManager.idl +10 -2
  2. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +2 -0
  3. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +6 -0
  4. package/Microsoft.ReactNative/ReactApplication.cpp +6 -2
  5. package/Microsoft.ReactNative/ReactHost/CrashManager.cpp +109 -0
  6. package/Microsoft.ReactNative/ReactHost/CrashManager.h +25 -0
  7. package/Microsoft.ReactNative/ReactHost/React.h +8 -0
  8. package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +27 -0
  9. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +44 -1
  10. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +7 -0
  11. package/Microsoft.ReactNative/ReactInstanceSettings.cpp +8 -0
  12. package/Microsoft.ReactNative/ReactInstanceSettings.h +3 -0
  13. package/Microsoft.ReactNative/ReactInstanceSettings.idl +5 -0
  14. package/Microsoft.ReactNative/ReactNativeHost.cpp +1 -0
  15. package/PropertySheets/External/Microsoft.ReactNative.Common.props +3 -0
  16. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +2 -0
  17. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -0
  18. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +1 -1
  19. package/PropertySheets/Generated/PackageVersion.g.props +1 -1
  20. package/PropertySheets/OutputMSBuildProperties.targets +31 -0
  21. package/Shared/DevSettings.h +2 -0
  22. package/Shared/HermesRuntimeHolder.cpp +13 -5
  23. package/Shared/HermesRuntimeHolder.h +2 -0
  24. package/Shared/HermesShim.cpp +29 -0
  25. package/Shared/HermesShim.h +2 -0
  26. package/Shared/JSI/RuntimeHolder.h +4 -0
  27. package/package.json +2 -2
@@ -88,10 +88,18 @@ namespace Microsoft.ReactNative
88
88
  )
89
89
  void OnPointerEvent(Object view, ReactPointerEventArgs args);
90
90
  };
91
+
92
+ [webhosthidden]
93
+ DOC_STRING(
94
+ "Enables view managers to track when views are"
95
+ "removed from the shadow tree."
96
+ )
91
97
  interface IViewManagerWithDropViewInstance {
92
98
  DOC_STRING(
93
- "Enables the view manager to track when the view is "
94
- "being removed from the visual tree. "
99
+ "Invoked when React has removed the view "
100
+ "from its shadow tree. Note this method call is distinct from "
101
+ "the XAML Unloaded event, which is asynchronously triggered "
102
+ "when the view is removed from the UI tree."
95
103
  )
96
104
  void OnDropViewInstance(XAML_NAMESPACE.FrameworkElement view);
97
105
  };
@@ -281,6 +281,7 @@
281
281
  <ClInclude Include="ReactHost\ReactErrorProvider.h" />
282
282
  <ClInclude Include="ReactHost\ReactHost.h" />
283
283
  <ClInclude Include="ReactHost\ReactInstanceWin.h" />
284
+ <ClInclude Include="ReactHost\CrashManager.h" />
284
285
  <ClInclude Include="ReactHost\ReactNativeHeaders.h" />
285
286
  <ClInclude Include="ReactHost\React_Win.h" />
286
287
  <ClInclude Include="ReactCoreInjection.h">
@@ -615,6 +616,7 @@
615
616
  <ClCompile Include="ReactHost\ReactErrorProvider.cpp" />
616
617
  <ClCompile Include="ReactHost\ReactHost.cpp" />
617
618
  <ClCompile Include="ReactHost\ReactInstanceWin.cpp" />
619
+ <ClCompile Include="ReactHost\CrashManager.cpp" />
618
620
  <ClCompile Include="ReactCoreInjection.cpp">
619
621
  <DependentUpon>ReactCoreInjection.idl</DependentUpon>
620
622
  <SubType>Code</SubType>
@@ -40,6 +40,9 @@
40
40
  <ClCompile Include="ReactHost\ReactInstanceWin.cpp">
41
41
  <Filter>ReactHost</Filter>
42
42
  </ClCompile>
43
+ <ClCompile Include="ReactHost\CrashManager.cpp">
44
+ <Filter>ReactHost</Filter>
45
+ </ClCompile>
43
46
  <ClCompile Include="ReactSupport.cpp" />
44
47
  <ClCompile Include="RedBox.cpp" />
45
48
  <ClCompile Include="TestHook.cpp" />
@@ -388,6 +391,9 @@
388
391
  <ClInclude Include="ReactHost\ReactInstanceWin.h">
389
392
  <Filter>ReactHost</Filter>
390
393
  </ClInclude>
394
+ <ClInclude Include="ReactHost\CrashManager.h">
395
+ <Filter>ReactHost</Filter>
396
+ </ClInclude>
391
397
  <ClInclude Include="ReactHost\ReactNativeHeaders.h">
392
398
  <Filter>ReactHost</Filter>
393
399
  </ClInclude>
@@ -6,6 +6,7 @@
6
6
  #include "ReactApplication.g.cpp"
7
7
  #include "winrt/Microsoft.ReactNative.h"
8
8
 
9
+ #include "CrashManager.h"
9
10
  #include "IReactDispatcher.h"
10
11
  #include "Modules/LinkingManagerModule.h"
11
12
  #include "ReactNativeHost.h"
@@ -40,12 +41,15 @@ ReactApplication::ReactApplication(IInspectable const &outer) noexcept : ReactAp
40
41
  #ifndef USE_WINUI3
41
42
  Suspending({this, &ReactApplication::OnSuspending});
42
43
 
43
- #if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
44
+ #if !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
44
45
  UnhandledException([this](IInspectable const &, UnhandledExceptionEventArgs const &e) {
46
+ #if defined _DEBUG
45
47
  if (IsDebuggerPresent()) {
46
48
  auto errorMessage = e.Message();
47
49
  __debugbreak();
48
- }
50
+ } else
51
+ #endif
52
+ Mso::React::CrashManager::OnUnhandledException();
49
53
  });
50
54
  #endif
51
55
  #endif
@@ -0,0 +1,109 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #include "CrashManager.h"
5
+ #include "ReactInstanceWin.h"
6
+
7
+ #include <winrt/Windows.Storage.h>
8
+
9
+ #include <WerApi.h>
10
+
11
+ namespace Mso::React {
12
+
13
+ // When calling SetUnhandledExceptionFilter the previous filter is returned.
14
+ // That should be saved so that if needed it can be called after the new unhandled exception has finished executing.
15
+ // This allows the Windows Error Reporting system to process the error and upload the data for processing.
16
+ static LPTOP_LEVEL_EXCEPTION_FILTER g_previousExceptionFilter = nullptr;
17
+
18
+ static std::wstring g_logFileName;
19
+ static bool g_WERExceptionFilterWasCalled{false}; // Prevent recursion in the custom handler
20
+
21
+ /*static*/ std::atomic_uint CrashManager::_regCount{0};
22
+
23
+ extern "C" LONG WINAPI CustomWERExceptionFilter(LPEXCEPTION_POINTERS const exceptionPointers) {
24
+ if (g_WERExceptionFilterWasCalled) {
25
+ return EXCEPTION_EXECUTE_HANDLER;
26
+ }
27
+
28
+ g_WERExceptionFilterWasCalled = true;
29
+
30
+ CrashManager::OnUnhandledException();
31
+
32
+ return g_previousExceptionFilter(exceptionPointers);
33
+ }
34
+
35
+ void InternalRegisterCustomHandler() noexcept {
36
+ // Do this now because by the time we catch the exception we may be in OOM
37
+ #ifndef CORE_ABI // win32 vs uwp file permissions
38
+ wchar_t currentDirectory[MAX_PATH]{};
39
+ VerifyElseCrash(!!GetTempPath(MAX_PATH, currentDirectory));
40
+ g_logFileName = currentDirectory;
41
+ #else
42
+ g_logFileName = winrt::Windows::Storage::ApplicationData::Current().LocalFolder().Path() + L"\\";
43
+ #endif
44
+
45
+ g_logFileName += L"ReactNativeCrashDetails_" + std::to_wstring(GetCurrentProcessId()) + L".txt";
46
+
47
+ VerifySucceededElseCrash(::WerRegisterFile(g_logFileName.c_str(), WerRegFileTypeOther, WER_FILE_ANONYMOUS_DATA));
48
+
49
+ g_previousExceptionFilter = ::SetUnhandledExceptionFilter(CustomWERExceptionFilter);
50
+ }
51
+
52
+ void InternalUnregisterCustomHandler() noexcept {
53
+ VerifySucceededElseCrash(::WerUnregisterFile(g_logFileName.c_str()));
54
+
55
+ if (g_previousExceptionFilter) {
56
+ ::SetUnhandledExceptionFilter(g_previousExceptionFilter);
57
+ g_previousExceptionFilter = nullptr;
58
+ }
59
+ }
60
+
61
+ /*static*/ void CrashManager::OnUnhandledException() noexcept {
62
+ FILE *f{nullptr};
63
+ auto err = _wfopen_s(&f, g_logFileName.c_str(), L"w");
64
+ if (err == 0) {
65
+ CrashHandler(_fileno(f));
66
+ fclose(f);
67
+ }
68
+ }
69
+
70
+ /*static*/ void CrashManager::CrashHandler(int fileDescriptor) noexcept {
71
+ ReactInstanceWin::CrashHandler(fileDescriptor);
72
+
73
+ // call any other component's static crash handlers here
74
+ }
75
+
76
+ /*static*/ void CrashManager::RegisterCustomHandler() noexcept {
77
+ if (_regCount++ == 0) {
78
+ InternalRegisterCustomHandler();
79
+ }
80
+ }
81
+
82
+ /*static*/ void CrashManager::UnregisterCustomHandler() noexcept {
83
+ if (--_regCount == 0) {
84
+ InternalUnregisterCustomHandler();
85
+ }
86
+ }
87
+
88
+ #if defined(DEBUG)
89
+ /*static*/ std::string CrashManager::TestCollectCrashData() {
90
+ FILE *f{nullptr};
91
+ if (tmpfile_s(&f) != 0) {
92
+ return std::string{};
93
+ }
94
+
95
+ CrashHandler(_fileno(f));
96
+ const auto sz = (size_t)ftell(f);
97
+ rewind(f);
98
+
99
+ std::string out;
100
+ out.resize(sz);
101
+ const auto readsz = fread(&out[0], 1, sz, f);
102
+ assert(readsz == sz);
103
+ fclose(f);
104
+
105
+ return out;
106
+ }
107
+ #endif
108
+
109
+ } // namespace Mso::React
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #pragma once
5
+
6
+ #include <atomic>
7
+
8
+ namespace Mso::React {
9
+
10
+ class CrashManager final {
11
+ public:
12
+ static void RegisterCustomHandler() noexcept;
13
+ static void UnregisterCustomHandler() noexcept;
14
+ static void OnUnhandledException() noexcept;
15
+
16
+ #if defined(DEBUG)
17
+ static std::string TestCollectCrashData();
18
+ #endif
19
+
20
+ private:
21
+ static void CrashHandler(int fileDescriptor) noexcept;
22
+ static std::atomic_uint _regCount;
23
+ };
24
+
25
+ } // namespace Mso::React
@@ -307,6 +307,14 @@ struct ReactOptions {
307
307
  bool value) noexcept;
308
308
  static bool UseDirectDebugger(winrt::Microsoft::ReactNative::IReactPropertyBag const &properties) noexcept;
309
309
 
310
+ //! Enables the default unhandled exception handler
311
+ void SetEnableDefaultCrashHandler(bool enable) noexcept;
312
+ bool EnableDefaultCrashHandler() const noexcept;
313
+ static void SetEnableDefaultCrashHandler(
314
+ winrt::Microsoft::ReactNative::IReactPropertyBag const &properties,
315
+ bool value) noexcept;
316
+ static bool EnableDefaultCrashHandler(winrt::Microsoft::ReactNative::IReactPropertyBag const &properties) noexcept;
317
+
310
318
  //! Adds registered JS bundle to JSBundles.
311
319
  LIBLET_PUBLICAPI ReactOptions &AddRegisteredJSBundle(std::string_view jsBundleId) noexcept;
312
320
 
@@ -75,6 +75,14 @@ winrt::Microsoft::ReactNative::IReactPropertyName EnableFabricProperty() noexcep
75
75
  return propName;
76
76
  }
77
77
 
78
+ winrt::Microsoft::ReactNative::IReactPropertyName EnableDefaultCrashHandlerProperty() noexcept {
79
+ static winrt::Microsoft::ReactNative::IReactPropertyName propName =
80
+ winrt::Microsoft::ReactNative::ReactPropertyBagHelper::GetName(
81
+ winrt::Microsoft::ReactNative::ReactPropertyBagHelper::GetNamespace(L"ReactNative.ReactOptions"),
82
+ L"EnableDefaultCrashHandler");
83
+ return propName;
84
+ }
85
+
78
86
  //=============================================================================================
79
87
  // ReactOptions implementation
80
88
  //=============================================================================================
@@ -234,6 +242,25 @@ bool ReactOptions::UseDirectDebugger() const noexcept {
234
242
  return winrt::unbox_value_or<bool>(properties.Get(UseDirectDebuggerProperty()), false);
235
243
  }
236
244
 
245
+ void ReactOptions::SetEnableDefaultCrashHandler(bool enabled) noexcept {
246
+ Properties.Set(EnableDefaultCrashHandlerProperty(), winrt::box_value(enabled));
247
+ }
248
+
249
+ bool ReactOptions::EnableDefaultCrashHandler() const noexcept {
250
+ return EnableDefaultCrashHandler(Properties);
251
+ }
252
+
253
+ /*static*/ void ReactOptions::SetEnableDefaultCrashHandler(
254
+ winrt::Microsoft::ReactNative::IReactPropertyBag const &properties,
255
+ bool value) noexcept {
256
+ properties.Set(EnableDefaultCrashHandlerProperty(), winrt::box_value(value));
257
+ }
258
+
259
+ /*static*/ bool ReactOptions::EnableDefaultCrashHandler(
260
+ winrt::Microsoft::ReactNative::IReactPropertyBag const &properties) noexcept {
261
+ return winrt::unbox_value_or<bool>(properties.Get(EnableDefaultCrashHandlerProperty()), false);
262
+ }
263
+
237
264
  //=============================================================================================
238
265
  // ReactHost implementation
239
266
  //=============================================================================================
@@ -75,6 +75,7 @@
75
75
  #include <tuple>
76
76
  #include "ChakraRuntimeHolder.h"
77
77
 
78
+ #include "CrashManager.h"
78
79
  #include "JsiApi.h"
79
80
  #include "ReactCoreInjection.h"
80
81
 
@@ -193,6 +194,9 @@ struct BridgeUIBatchInstanceCallback final : public facebook::react::InstanceCal
193
194
  // ReactInstanceWin implementation
194
195
  //=============================================================================================
195
196
 
197
+ /*static*/ std::mutex ReactInstanceWin::s_registryMutex;
198
+ /*static*/ std::vector<ReactInstanceWin *> ReactInstanceWin::s_instanceRegistry;
199
+
196
200
  ReactInstanceWin::ReactInstanceWin(
197
201
  IReactHost &reactHost,
198
202
  ReactOptions const &options,
@@ -247,9 +251,48 @@ ReactInstanceWin::ReactInstanceWin(
247
251
  // OnInstanceCreated event is raised only after the internal react-native instance is ready and
248
252
  // it starts handling JS queue work items.
249
253
  m_whenCreated.SetValue();
254
+
255
+ if (m_options.EnableDefaultCrashHandler()) {
256
+ CrashManager::RegisterCustomHandler();
257
+ }
258
+
259
+ {
260
+ std::scoped_lock lock{s_registryMutex};
261
+ s_instanceRegistry.push_back(this);
262
+ }
263
+ }
264
+
265
+ ReactInstanceWin::~ReactInstanceWin() noexcept {
266
+ std::scoped_lock lock{s_registryMutex};
267
+ auto it = std::find(s_instanceRegistry.begin(), s_instanceRegistry.end(), this);
268
+ if (it != s_instanceRegistry.end()) {
269
+ s_instanceRegistry.erase(it);
270
+ }
271
+
272
+ if (m_options.EnableDefaultCrashHandler()) {
273
+ CrashManager::UnregisterCustomHandler();
274
+ }
275
+ }
276
+
277
+ void ReactInstanceWin::InstanceCrashHandler(int fileDescriptor) noexcept {
278
+ if (!m_options.EnableDefaultCrashHandler()) {
279
+ return;
280
+ }
281
+
282
+ if (m_jsiRuntimeHolder) {
283
+ m_jsiRuntimeHolder->crashHandler(fileDescriptor);
284
+ }
285
+
286
+ // record additional information that could be useful for debugging crash dumps here
287
+ // (perhaps properties and settings or clues about the react tree)
250
288
  }
251
289
 
252
- ReactInstanceWin::~ReactInstanceWin() noexcept {}
290
+ /*static*/ void ReactInstanceWin::CrashHandler(int fileDescriptor) noexcept {
291
+ std::scoped_lock lock{s_registryMutex};
292
+ for (auto &entry : s_instanceRegistry) {
293
+ entry->InstanceCrashHandler(fileDescriptor);
294
+ }
295
+ }
253
296
 
254
297
  void ReactInstanceWin::LoadModules(
255
298
  const std::shared_ptr<winrt::Microsoft::ReactNative::NativeModulesProvider> &nativeModulesProvider,
@@ -82,6 +82,8 @@ class ReactInstanceWin final : public Mso::ActiveObject<IReactInstanceInternal>
82
82
  bool UseDeveloperSupport() const noexcept;
83
83
  JSIEngine JsiEngine() const noexcept;
84
84
 
85
+ static void CrashHandler(int fileDescriptor) noexcept;
86
+
85
87
  private:
86
88
  friend MakePolicy;
87
89
  ReactInstanceWin(
@@ -124,6 +126,8 @@ class ReactInstanceWin final : public Mso::ActiveObject<IReactInstanceInternal>
124
126
  void DrainJSCallQueue() noexcept;
125
127
  void AbandonJSCallQueue() noexcept;
126
128
 
129
+ void InstanceCrashHandler(int fileDescriptor) noexcept;
130
+
127
131
  struct JSCallEntry {
128
132
  std::string ModuleName;
129
133
  std::string MethodName;
@@ -185,6 +189,9 @@ class ReactInstanceWin final : public Mso::ActiveObject<IReactInstanceInternal>
185
189
 
186
190
  std::shared_ptr<Microsoft::JSI::RuntimeHolderLazyInit> m_jsiRuntimeHolder;
187
191
  winrt::Microsoft::ReactNative::JsiRuntime m_jsiRuntime{nullptr};
192
+
193
+ static std::mutex s_registryMutex; // protects access to s_instanceRegistry
194
+ static std::vector<ReactInstanceWin *> s_instanceRegistry;
188
195
  };
189
196
 
190
197
  } // namespace Mso::React
@@ -99,6 +99,14 @@ void ReactInstanceSettings::DebuggerBreakOnNextLine(bool value) noexcept {
99
99
  Mso::React::ReactOptions::SetDebuggerBreakOnNextLine(m_properties, value);
100
100
  }
101
101
 
102
+ bool ReactInstanceSettings::EnableDefaultCrashHandler() noexcept {
103
+ return Mso::React::ReactOptions::EnableDefaultCrashHandler(m_properties);
104
+ }
105
+
106
+ void ReactInstanceSettings::EnableDefaultCrashHandler(bool value) noexcept {
107
+ Mso::React::ReactOptions::SetEnableDefaultCrashHandler(m_properties, value);
108
+ }
109
+
102
110
  bool ReactInstanceSettings::EnableDeveloperMenu() noexcept {
103
111
  return UseDeveloperSupport();
104
112
  }
@@ -96,6 +96,9 @@ struct ReactInstanceSettings : ReactInstanceSettingsT<ReactInstanceSettings> {
96
96
  bool EnableByteCodeCaching() noexcept;
97
97
  void EnableByteCodeCaching(bool value) noexcept;
98
98
 
99
+ bool EnableDefaultCrashHandler() noexcept;
100
+ void EnableDefaultCrashHandler(bool value) noexcept;
101
+
99
102
  //! Same as UseDeveloperSupport
100
103
  bool EnableDeveloperMenu() noexcept;
101
104
  void EnableDeveloperMenu(bool value) noexcept;
@@ -151,6 +151,11 @@ namespace Microsoft.ReactNative
151
151
  DOC_DEFAULT("false")
152
152
  Boolean EnableByteCodeCaching { get; set; };
153
153
 
154
+ DOC_STRING(
155
+ "Enables the default unhandled exception handler that logs additional information into a text file for [Windows Error Reporting](https://docs.microsoft.com/windows/win32/wer/windows-error-reporting).")
156
+ DOC_DEFAULT("false")
157
+ Boolean EnableDefaultCrashHandler { get; set; };
158
+
154
159
  // Deprecated
155
160
  [deprecated(
156
161
  "This property has been replaced by @.UseDeveloperSupport. "
@@ -136,6 +136,7 @@ IAsyncAction ReactNativeHost::ReloadInstance() noexcept {
136
136
 
137
137
  reactOptions.ByteCodeFileUri = to_string(m_instanceSettings.ByteCodeFileUri());
138
138
  reactOptions.EnableByteCodeCaching = m_instanceSettings.EnableByteCodeCaching();
139
+ reactOptions.SetEnableDefaultCrashHandler(m_instanceSettings.EnableDefaultCrashHandler());
139
140
  reactOptions.SetJsiEngine(static_cast<Mso::React::JSIEngine>(m_instanceSettings.JSIEngineOverride()));
140
141
 
141
142
  reactOptions.ModuleProvider = modulesProvider;
@@ -41,6 +41,9 @@
41
41
  <PropertyGroup Label="NuGet" Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
42
42
  <!--See https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target-->
43
43
  <RestoreUseStaticGraphEvaluation Condition="'$(BuildingInsideVisualStudio)' == 'true'">true</RestoreUseStaticGraphEvaluation>
44
+
45
+ <!-- Ensure PackageReference compatibility for any consuming projects/apps -->
46
+ <ResolveNuGetPackages>false</ResolveNuGetPackages>
44
47
  </PropertyGroup>
45
48
 
46
49
  <Import Project="$(ReactNativeWindowsDir)\PropertySheets\Generated\PackageVersion.g.props" />
@@ -46,4 +46,6 @@
46
46
  </Target>
47
47
 
48
48
  <Import Project="$(ReactNativeWindowsDir)\PropertySheets\RequireSolution.targets" />
49
+
50
+ <Import Project="$(ReactNativeWindowsDir)\PropertySheets\OutputMSBuildProperties.targets" />
49
51
  </Project>
@@ -47,6 +47,7 @@
47
47
  <Import Project="$(ReactNativeWindowsDir)\PropertySheets\CppAppConsumeCSharpModule.targets" />
48
48
  <Import Project="$(ReactNativeWindowsDir)\PropertySheets\RequireSolution.targets" />
49
49
  <Import Project="$(ReactNativeWindowsDir)\PropertySheets\FixupRoslynCscWarnings.targets" />
50
+ <Import Project="$(ReactNativeWindowsDir)\PropertySheets\OutputMSBuildProperties.targets" />
50
51
 
51
52
  <ItemDefinitionGroup>
52
53
  <Reference>
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <!--
2
+ <!--
3
3
  Copyright (c) Microsoft Corporation.
4
4
  Licensed under the MIT License.
5
5
 
@@ -10,7 +10,7 @@
10
10
  -->
11
11
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
12
  <PropertyGroup>
13
- <ReactNativeWindowsVersion>0.68.0-preview.4</ReactNativeWindowsVersion>
13
+ <ReactNativeWindowsVersion>0.68.0-preview.5</ReactNativeWindowsVersion>
14
14
  <ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
15
15
  <ReactNativeWindowsMinor>68</ReactNativeWindowsMinor>
16
16
  <ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+ Licensed under the MIT License..
5
+ -->
6
+ <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
7
+
8
+ <Target Name="OutputMSBuildProperties" AfterTargets="PrepareForBuild">
9
+ <PropertyGroup>
10
+ <!--
11
+ These are the properties we will report in telemetry. Do NOT add properties that may contain PII.
12
+ You can add new properties following the format "PropertyName": "$(PropertyName)",
13
+ -->
14
+ <MSBuildPropertiesJSON>
15
+ {
16
+ "WinUIPackageName": "$(WinUIPackageName)",
17
+ "WinUIPackageVersion": "$(WinUIPackageVersion)",
18
+ "WindowsTargetPlatformVersion": "$(WindowsTargetPlatformVersion)",
19
+ "UseExperimentalNuGet": "$(UseExperimentalNuGet)",
20
+ "UseHermes": "$(UseHermes)",
21
+ "UseWinUI3": "$(UseWinUI3)"
22
+ }
23
+ </MSBuildPropertiesJSON>
24
+ </PropertyGroup>
25
+ <WriteLinesToFile
26
+ File="$([MSBuild]::NormalizePath($(ProjectDir)\Generated Files))\msbuildproperties.g.json"
27
+ Overwrite="true"
28
+ Lines="$(MSBuildPropertiesJSON)" />
29
+ </Target>
30
+
31
+ </Project>
@@ -89,6 +89,8 @@ struct DevSettings {
89
89
  std::function<void()> showDevMenuCallback;
90
90
 
91
91
  bool inlineSourceMap{true};
92
+
93
+ bool enableDefaultCrashHandler{false};
92
94
  };
93
95
 
94
96
  } // namespace react
@@ -25,10 +25,14 @@ namespace react {
25
25
 
26
26
  namespace {
27
27
 
28
- std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeSystraced(
29
- const ::hermes::vm::RuntimeConfig &runtimeConfig) {
28
+ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeSystraced(bool enableDefaultCrashHandler) {
30
29
  SystraceSection s("HermesExecutorFactory::makeHermesRuntimeSystraced");
31
- return HermesShim::makeHermesRuntime(runtimeConfig);
30
+ if (enableDefaultCrashHandler) {
31
+ return HermesShim::makeHermesRuntimeWithWER();
32
+ } else {
33
+ auto runtimeConfig = ::hermes::vm::RuntimeConfig();
34
+ return HermesShim::makeHermesRuntime(runtimeConfig);
35
+ }
32
36
  }
33
37
 
34
38
  #ifdef HERMES_ENABLE_DEBUGGER
@@ -69,6 +73,10 @@ class HermesExecutorRuntimeAdapter final : public facebook::hermes::inspector::R
69
73
 
70
74
  } // namespace
71
75
 
76
+ void HermesRuntimeHolder::crashHandler(int fileDescriptor) noexcept {
77
+ HermesShim::hermesCrashHandler(static_cast<facebook::hermes::HermesRuntime &>(*m_runtime), fileDescriptor);
78
+ }
79
+
72
80
  facebook::react::JSIEngineOverride HermesRuntimeHolder::getRuntimeType() noexcept {
73
81
  return facebook::react::JSIEngineOverride::Hermes;
74
82
  }
@@ -92,8 +100,8 @@ HermesRuntimeHolder::HermesRuntimeHolder(
92
100
  : m_devSettings(std::move(devSettings)), m_jsQueue(std::move(jsQueue)) {}
93
101
 
94
102
  void HermesRuntimeHolder::initRuntime() noexcept {
95
- auto runtimeConfig = ::hermes::vm::RuntimeConfig();
96
- auto hermesRuntime = makeHermesRuntimeSystraced(runtimeConfig);
103
+ auto hermesRuntime = makeHermesRuntimeSystraced(m_devSettings->enableDefaultCrashHandler);
104
+
97
105
  facebook::hermes::HermesRuntime &hermesRuntimeRef = *hermesRuntime;
98
106
 
99
107
  m_runtime = std::move(hermesRuntime);
@@ -17,6 +17,8 @@ class HermesRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
17
17
  std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override;
18
18
  facebook::react::JSIEngineOverride getRuntimeType() noexcept override;
19
19
 
20
+ void crashHandler(int fileDescriptor) noexcept override;
21
+
20
22
  HermesRuntimeHolder(
21
23
  std::shared_ptr<facebook::react::DevSettings> devSettings,
22
24
  std::shared_ptr<facebook::react::MessageQueueThread> jsQueue) noexcept;
@@ -11,6 +11,8 @@ static decltype(&facebook::hermes::makeHermesRuntime) s_makeHermesRuntime{nullpt
11
11
  static decltype(&facebook::hermes::HermesRuntime::enableSamplingProfiler) s_enableSamplingProfiler{nullptr};
12
12
  static decltype(&facebook::hermes::HermesRuntime::disableSamplingProfiler) s_disableSamplingProfiler{nullptr};
13
13
  static decltype(&facebook::hermes::HermesRuntime::dumpSampledTraceToFile) s_dumpSampledTraceToFile{nullptr};
14
+ static decltype(&facebook::hermes::makeHermesRuntimeWithWER) s_makeHermesRuntimeWithWER{nullptr};
15
+ static decltype(&facebook::hermes::hermesCrashHandler) s_hermesCrashHandler{nullptr};
14
16
 
15
17
  #if _M_X64
16
18
  constexpr const char *makeHermesRuntimeSymbol =
@@ -19,6 +21,9 @@ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@Her
19
21
  constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
20
22
  constexpr const char *dumpSampledTraceToFileSymbol =
21
23
  "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
24
+ constexpr const char *makeHermesRuntimeWithWERSymbol =
25
+ "?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
26
+ constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAEAVHermesRuntime@12@H@Z";
22
27
  #endif
23
28
 
24
29
  #if _M_ARM64
@@ -28,6 +33,9 @@ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@Her
28
33
  constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
29
34
  constexpr const char *dumpSampledTraceToFileSymbol =
30
35
  "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
36
+ constexpr const char *makeHermesRuntimeWithWERSymbol =
37
+ "?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
38
+ constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAEAVHermesRuntime@12@H@Z";
31
39
  #endif
32
40
 
33
41
  #if _M_IX86
@@ -37,6 +45,9 @@ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@Her
37
45
  constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
38
46
  constexpr const char *dumpSampledTraceToFileSymbol =
39
47
  "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
48
+ constexpr const char *makeHermesRuntimeWithWERSymbol =
49
+ "?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
50
+ constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAAVHermesRuntime@12@H@Z";
40
51
  #endif
41
52
 
42
53
  static void EnsureHermesLoaded() noexcept {
@@ -59,6 +70,14 @@ static void EnsureHermesLoaded() noexcept {
59
70
  s_dumpSampledTraceToFile = reinterpret_cast<decltype(s_dumpSampledTraceToFile)>(
60
71
  GetProcAddress(s_hermesModule, dumpSampledTraceToFileSymbol));
61
72
  VerifyElseCrash(s_dumpSampledTraceToFile);
73
+
74
+ s_makeHermesRuntimeWithWER = reinterpret_cast<decltype(s_makeHermesRuntimeWithWER)>(
75
+ GetProcAddress(s_hermesModule, makeHermesRuntimeWithWERSymbol));
76
+ VerifyElseCrash(s_makeHermesRuntimeWithWER);
77
+
78
+ s_hermesCrashHandler =
79
+ reinterpret_cast<decltype(s_hermesCrashHandler)>(GetProcAddress(s_hermesModule, hermesCrashHandlerSymbol));
80
+ VerifyElseCrash(s_hermesCrashHandler);
62
81
  }
63
82
  }
64
83
 
@@ -82,4 +101,14 @@ void dumpSampledTraceToFile(const std::string &fileName) {
82
101
  s_dumpSampledTraceToFile(fileName);
83
102
  }
84
103
 
104
+ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeWithWER() {
105
+ EnsureHermesLoaded();
106
+ return s_makeHermesRuntimeWithWER();
107
+ }
108
+
109
+ void hermesCrashHandler(facebook::hermes::HermesRuntime &runtime, int fileDescriptor) {
110
+ EnsureHermesLoaded();
111
+ s_hermesCrashHandler(runtime, fileDescriptor);
112
+ }
113
+
85
114
  } // namespace Microsoft::ReactNative::HermesShim
@@ -15,5 +15,7 @@ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntime(const hermes:
15
15
  void enableSamplingProfiler();
16
16
  void disableSamplingProfiler();
17
17
  void dumpSampledTraceToFile(const std::string &fileName);
18
+ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeWithWER();
19
+ void hermesCrashHandler(facebook::hermes::HermesRuntime &runtime, int fileDescriptor);
18
20
 
19
21
  } // namespace Microsoft::ReactNative::HermesShim
@@ -17,6 +17,10 @@ namespace Microsoft::JSI {
17
17
  struct RuntimeHolderLazyInit {
18
18
  virtual std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept = 0;
19
19
  virtual facebook::react::JSIEngineOverride getRuntimeType() noexcept = 0;
20
+
21
+ // You can call this when a crash happens to attempt recording additional data
22
+ // The fd supplied is a raw file stream an implementation might write JSON to
23
+ virtual void crashHandler(int fileDescriptor) noexcept {};
20
24
  };
21
25
 
22
26
  } // namespace Microsoft::JSI
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.68.0-preview.4",
3
+ "version": "0.68.0-preview.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "@react-native-community/cli": "^7.0.1",
27
27
  "@react-native-community/cli-platform-android": "^7.0.1",
28
28
  "@react-native-community/cli-platform-ios": "^7.0.1",
29
- "@react-native-windows/cli": "0.68.0-preview.4",
29
+ "@react-native-windows/cli": "0.68.0-preview.5",
30
30
  "@react-native-windows/virtualized-list": "0.68.0-preview.2",
31
31
  "@react-native/assets": "1.0.0",
32
32
  "@react-native/normalize-color": "2.0.0",