react-native-windows 0.66.0 → 0.66.4

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 (44) hide show
  1. package/CHANGELOG.json +103 -1
  2. package/CHANGELOG.md +43 -4
  3. package/Chakra/Chakra.vcxitems +0 -1
  4. package/Chakra/Chakra.vcxitems.filters +0 -3
  5. package/Chakra/ChakraHelpers.cpp +0 -267
  6. package/Chakra/ChakraInstanceArgs.h +0 -5
  7. package/Chakra/ChakraPlatform.h +0 -4
  8. package/Chakra/ChakraTracing.cpp +0 -33
  9. package/Chakra/ChakraValue.h +0 -4
  10. package/Chakra/Utf8DebugExtensions.cpp +0 -5
  11. package/Chakra/Utf8DebugExtensions.h +0 -6
  12. package/Libraries/AppTheme/AppTheme.d.ts +3 -2
  13. package/Libraries/AppTheme/AppTheme.js +20 -2
  14. package/Libraries/AppTheme/AppTheme.js.map +1 -1
  15. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +3 -3
  16. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +3 -5
  17. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +0 -4
  18. package/Microsoft.ReactNative/ReactRootView.cpp +28 -3
  19. package/Microsoft.ReactNative/ReactRootView.h +6 -0
  20. package/Microsoft.ReactNative/Version.rc +1 -1
  21. package/Microsoft.ReactNative/Views/DevMenu.cpp +0 -1
  22. package/Microsoft.ReactNative/Views/RootViewManager.cpp +8 -9
  23. package/PropertySheets/JSEngine.props +0 -3
  24. package/PropertySheets/React.Cpp.props +2 -1
  25. package/Scripts/Microsoft.ReactNative.targets +1 -1
  26. package/Shared/HermesRuntimeHolder.cpp +3 -1
  27. package/Shared/HermesSamplingProfiler.cpp +6 -7
  28. package/Shared/HermesShim.cpp +85 -0
  29. package/Shared/HermesShim.h +19 -0
  30. package/Shared/JSI/ChakraApi.cpp +1 -37
  31. package/Shared/JSI/ChakraApi.h +0 -4
  32. package/Shared/JSI/ChakraJsiRuntime_edgemode.cpp +1 -5
  33. package/Shared/JSI/ChakraRuntime.cpp +0 -12
  34. package/Shared/JSI/ChakraRuntimeFactory.h +0 -2
  35. package/Shared/OInstance.cpp +12 -29
  36. package/Shared/Shared.vcxitems +5 -10
  37. package/Shared/Shared.vcxitems.filters +6 -3
  38. package/package.json +3 -3
  39. package/template/metro.config.js +8 -1
  40. package/template/metro.devMode.config.js +3 -1
  41. package/Chakra/ChakraCoreDebugger.h +0 -147
  42. package/Scripts/Microsoft.ChakraCore.ARM64.nuspec +0 -50
  43. package/Scripts/Microsoft.ChakraCore.ARM64.targets +0 -15
  44. package/Shared/JSI/ChakraCoreRuntime.h +0 -59
@@ -1 +1 @@
1
- {"version":3,"file":"AppTheme.js","sourceRoot":"","sources":["../../src/Libraries/AppTheme/AppTheme.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,CAAC;;;AAEb,+CAA+D;AAG/D,MAAM,cAAc,GAAG,4BAAa,CAAC,WAAW,CAAC;AAEjD,MAAM,cAAe,SAAQ,iCAAkB;IAI7C;QACE,KAAK,CAAC,cAAc,CAAC,CAAC;QAEtB,IAAI,CAAC,mBAAmB,GAAG,cAAc,CAAC,yBAAyB,CAAC;QACpE,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,mBAAmB,CAAC;QAC1D,IAAI,CAAC,WAAW,CACd,qBAAqB,EACrB,CAAC,WAAsC,EAAE,EAAE;YACzC,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,cAAc,CAAC;YAClD,IAAI,CAAC,mBAAmB,GAAG,WAAW,CAAC,kBAAkB,CAAC;QAC5D,CAAC,CACF,CAAC;IACJ,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAI,yBAAyB;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;CACF;AAGY,QAAA,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n'use strict';\n\nimport {NativeEventEmitter, NativeModules} from 'react-native';\nimport {IHighContrastColors, IHighContrastChangedEvent} from './AppThemeTypes';\n\nconst NativeAppTheme = NativeModules.RTCAppTheme;\n\nclass AppThemeModule extends NativeEventEmitter {\n private _isHighContrast: boolean;\n private _highContrastColors: IHighContrastColors;\n\n constructor() {\n super(NativeAppTheme);\n\n this._highContrastColors = NativeAppTheme.initialHighContrastColors;\n this._isHighContrast = NativeAppTheme.initialHighContrast;\n this.addListener(\n 'highContrastChanged',\n (nativeEvent: IHighContrastChangedEvent) => {\n this._isHighContrast = nativeEvent.isHighContrast;\n this._highContrastColors = nativeEvent.highContrastColors;\n },\n );\n }\n\n get isHighContrast(): boolean {\n return this._isHighContrast;\n }\n\n get currentHighContrastColors(): IHighContrastColors {\n return this._highContrastColors;\n }\n}\n\nexport type AppTheme = AppThemeModule;\nexport const AppTheme = new AppThemeModule();\n"]}
1
+ {"version":3,"file":"AppTheme.js","sourceRoot":"","sources":["../../src/Libraries/AppTheme/AppTheme.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,YAAY,CAAC;;;AAEb,+CAIsB;AAGtB,+EAA+E;AAC/E,+EAA+E;AAC/E,sBAAsB;AACtB,MAAM,cAAc,GAAG,4BAAa,CAAC,WAAW,IAAI;IAClD,mBAAmB,EAAE,KAAK;IAC1B,yBAAyB,EAAE;QACzB,eAAe,EAAE,EAAE;QACnB,eAAe,EAAE,EAAE;QACnB,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,EAAE;QAClB,kBAAkB,EAAE,EAAE;QACtB,aAAa,EAAE,EAAE;QACjB,WAAW,EAAE,EAAE;QACf,eAAe,EAAE,EAAE;KACpB;CACF,CAAC;AAEF,MAAM,cAAe,SAAQ,iCAAkB;IAI7C;QACE,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,mBAAmB,GAAG,cAAc,CAAC,yBAAyB,CAAC;QACpE,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,mBAAmB,CAAC;QAC1D,IAAI,CAAC,WAAW,CACd,qBAAqB,EACrB,CAAC,WAAsC,EAAE,EAAE;YACzC,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,cAAc,CAAC;YAClD,IAAI,CAAC,mBAAmB,GAAG,WAAW,CAAC,kBAAkB,CAAC;QAC5D,CAAC,CACF,CAAC;IACJ,CAAC;IAED,WAAW,CACT,SAAgC,EAChC,QAA0D;QAE1D,OAAO,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAI,yBAAyB;QAC3B,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;CACF;AAGY,QAAA,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n'use strict';\n\nimport {\n EmitterSubscription,\n NativeEventEmitter,\n NativeModules,\n} from 'react-native';\nimport {IHighContrastColors, IHighContrastChangedEvent} from './AppThemeTypes';\n\n// We previously gracefully handled importing AppTheme in the Jest environment.\n// Mock the NM until we have a coherent story for exporting our own Jest mocks,\n// or remove this API.\nconst NativeAppTheme = NativeModules.RTCAppTheme || {\n initialHighContrast: false,\n initialHighContrastColors: {\n ButtonFaceColor: '',\n ButtonTextColor: '',\n GrayTextColor: '',\n HighlightColor: '',\n HighlightTextColor: '',\n HotlightColor: '',\n WindowColor: '',\n WindowTextColor: '',\n },\n};\n\nclass AppThemeModule extends NativeEventEmitter {\n private _isHighContrast: boolean;\n private _highContrastColors: IHighContrastColors;\n\n constructor() {\n super();\n\n this._highContrastColors = NativeAppTheme.initialHighContrastColors;\n this._isHighContrast = NativeAppTheme.initialHighContrast;\n this.addListener(\n 'highContrastChanged',\n (nativeEvent: IHighContrastChangedEvent) => {\n this._isHighContrast = nativeEvent.isHighContrast;\n this._highContrastColors = nativeEvent.highContrastColors;\n },\n );\n }\n\n addListener(\n eventName: 'highContrastChanged',\n listener: (nativeEvent: IHighContrastChangedEvent) => void,\n ): EmitterSubscription {\n return super.addListener(eventName, listener);\n }\n\n get isHighContrast(): boolean {\n return this._isHighContrast;\n }\n\n get currentHighContrastColors(): IHighContrastColors {\n return this._highContrastColors;\n }\n}\n\nexport type AppTheme = AppThemeModule;\nexport const AppTheme = new AppThemeModule();\n"]}
@@ -118,8 +118,6 @@
118
118
  REACTWINDOWS_BUILD - building with REACTWINDOWS_API as dll exports
119
119
  OLD_CPPWINRT is a workaround to make target version to 19H1
120
120
  -->
121
- <PreprocessorDefinitions Condition="'$(CHAKRACOREUWP)'=='true'">CHAKRACORE;CHAKRACORE_UWP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122
- <PreprocessorDefinitions Condition="'$(CHAKRACOREUWP)'!='true'">USE_EDGEMODE_JSRT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123
121
  <PreprocessorDefinitions>
124
122
  REACTWINDOWS_BUILD;
125
123
  RN_PLATFORM=windows;
@@ -143,6 +141,8 @@
143
141
  <SubSystem>Console</SubSystem>
144
142
  <GenerateWindowsMetadata>true</GenerateWindowsMetadata>
145
143
  <ModuleDefinitionFile>Microsoft.ReactNative.def</ModuleDefinitionFile>
144
+ <!-- #8824: The Hermes NuGet package adds itself to be linked, but we go through Hermes Shim instead. Ignore the unused DLL until using NuGet package with "HermesNoLink" -->
145
+ <AdditionalOptions>/IGNORE:4199</AdditionalOptions>
146
146
  </Link>
147
147
  <Midl>
148
148
  <AdditionalIncludeDirectories>$(ReactNativeWindowsDir)Microsoft.ReactNative\Views\cppwinrt;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -781,7 +781,7 @@
781
781
  <Import Project="$(SolutionDir)packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Windows.CppWinRT.2.0.210312.4\build\native\Microsoft.Windows.CppWinRT.targets')" />
782
782
  <Import Project="$(SolutionDir)packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets" Condition="Exists('$(SolutionDir)packages\$(WinUIPackageName).$(WinUIPackageVersion)\build\native\$(WinUIPackageName).targets')" />
783
783
  <Import Project="$(V8Package)\build\native\ReactNative.V8JSI.Windows.UWP.targets" Condition="Exists('$(V8Package)\build\native\ReactNative.V8JSI.Windows.UWP.targets') AND '$(UseV8)' == 'true'" />
784
- <Import Project="$(HermesPackage)\build\native\ReactNative.Hermes.Windows.targets" Condition="Exists('$(HermesPackage)\build\native\ReactNative.Hermes.Windows.targets') AND '$(IncludeHermes)' == 'true'" />
784
+ <Import Project="$(HermesPackage)\build\native\ReactNative.Hermes.Windows.targets" Condition="Exists('$(HermesPackage)\build\native\ReactNative.Hermes.Windows.targets')" />
785
785
  <Import Project="$(SolutionDir)\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.Build.Tasks.Git.1.0.0\build\Microsoft.Build.Tasks.Git.targets')" />
786
786
  <Import Project="$(SolutionDir)\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.SourceLink.Common.1.0.0\build\Microsoft.SourceLink.Common.targets')" />
787
787
  <Import Project="$(SolutionDir)\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets" Condition="Exists('$(SolutionDir)\packages\Microsoft.SourceLink.GitHub.1.0.0\build\Microsoft.SourceLink.GitHub.targets')" />
@@ -173,11 +173,9 @@ struct RootShadowNode final : public ShadowNodeBase {
173
173
  }
174
174
 
175
175
  void AddView(ShadowNode &child, int64_t index) override {
176
- auto panel(GetView().as<winrt::Panel>());
177
- if (panel != nullptr) {
178
- auto childView = static_cast<ShadowNodeBase &>(child).GetView().as<xaml::UIElement>();
179
- panel.Children().InsertAt(static_cast<uint32_t>(index), childView);
180
- }
176
+ auto panel(GetView().as<winrt::Microsoft::ReactNative::ReactRootView>());
177
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactRootView>(panel)->AddView(
178
+ static_cast<uint32_t>(index), static_cast<ShadowNodeBase &>(child).GetView().as<xaml::UIElement>());
181
179
  }
182
180
  };
183
181
 
@@ -67,9 +67,7 @@
67
67
  #include <Utils/UwpScriptStore.h>
68
68
  #endif
69
69
 
70
- #if defined(INCLUDE_HERMES)
71
70
  #include "HermesRuntimeHolder.h"
72
- #endif // INCLUDE_HERMES
73
71
 
74
72
  #if defined(USE_V8)
75
73
  #include <winrt/Windows.Storage.h>
@@ -429,12 +427,10 @@ void ReactInstanceWin::Initialize() noexcept {
429
427
 
430
428
  switch (m_options.JsiEngine()) {
431
429
  case JSIEngine::Hermes:
432
- #if defined(INCLUDE_HERMES)
433
430
  devSettings->jsiRuntimeHolder =
434
431
  std::make_shared<facebook::react::HermesRuntimeHolder>(devSettings, m_jsMessageThread.Load());
435
432
  devSettings->inlineSourceMap = false;
436
433
  break;
437
- #endif
438
434
  case JSIEngine::V8:
439
435
  #if defined(USE_V8)
440
436
  #ifndef CORE_ABI
@@ -337,9 +337,6 @@ void ReactRootView::ShowInstanceLoading() noexcept {
337
337
 
338
338
  void ReactRootView::EnsureFocusSafeHarbor() noexcept {
339
339
  if (!m_focusSafeHarbor) {
340
- // focus safe harbor is delayed to be inserted to the visual tree
341
- VerifyElseCrash(Children().Size() == 1);
342
-
343
340
  m_focusSafeHarbor = xaml::Controls::ContentControl{};
344
341
  m_focusSafeHarbor.Width(0.0);
345
342
  m_focusSafeHarbor.IsTabStop(false);
@@ -526,4 +523,32 @@ Windows::Foundation::Size ReactRootView::ArrangeOverride(Windows::Foundation::Si
526
523
  return finalSize;
527
524
  }
528
525
 
526
+ // Maps react-native's view of the root view to the actual UI
527
+ // react-native is unaware that there are non-RN elements within the ReactRootView
528
+ uint32_t ReactRootView::RNIndexToXamlIndex(uint32_t index) noexcept {
529
+ // If m_focusSafeHarbor exists, it should be at index 0
530
+ // m_xamlRootView is the next element, followed by any RN content.
531
+ #if DEBUG
532
+ uint32_t findIndex{0};
533
+ Assert(!m_focusSafeHarbor || Children().IndexOf(m_focusSafeHarbor, findIndex) && findIndex == 0);
534
+ Assert(Children().IndexOf(m_xamlRootView, findIndex) && findIndex == (m_focusSafeHarbor ? 1 : 0));
535
+ #endif
536
+
537
+ return index + (m_focusSafeHarbor ? 2 : 1);
538
+ }
539
+
540
+ void ReactRootView::AddView(uint32_t index, xaml::UIElement child) {
541
+ Children().InsertAt(RNIndexToXamlIndex(index), child);
542
+ }
543
+
544
+ void ReactRootView::RemoveAllChildren() {
545
+ const uint32_t numLeft = m_focusSafeHarbor ? 2 : 1;
546
+ while (Children().Size() > numLeft)
547
+ Children().RemoveAt(numLeft);
548
+ }
549
+
550
+ void ReactRootView::RemoveChildAt(uint32_t index) {
551
+ Children().RemoveAt(RNIndexToXamlIndex(index));
552
+ }
553
+
529
554
  } // namespace winrt::Microsoft::ReactNative::implementation
@@ -42,6 +42,11 @@ struct ReactRootView : ReactRootViewT<ReactRootView>, ::Microsoft::ReactNative::
42
42
 
43
43
  void ReloadView() noexcept;
44
44
 
45
+ // Used by RootViewManager
46
+ void AddView(uint32_t index, xaml::UIElement child);
47
+ void RemoveAllChildren();
48
+ void RemoveChildAt(uint32_t index);
49
+
45
50
  public: // IXamlRootView
46
51
  ::Microsoft::ReactNative::XamlView GetXamlView() const noexcept override;
47
52
 
@@ -98,6 +103,7 @@ struct ReactRootView : ReactRootViewT<ReactRootView>, ::Microsoft::ReactNative::
98
103
  // JS created children
99
104
  winrt::Grid m_xamlRootView{nullptr};
100
105
 
106
+ uint32_t RNIndexToXamlIndex(uint32_t index) noexcept;
101
107
  void UpdatePerspective();
102
108
  void UpdateRootViewInternal() noexcept;
103
109
  void ClearLoadingUI() noexcept;
@@ -4,7 +4,7 @@
4
4
  #define STRINGIZE(s) #s
5
5
 
6
6
  #ifdef RNW_PKG_VERSION_STR
7
- #define VER_FILEVERSION_STR STRINGIZE(RNW_PKG_VERSION_STR)
7
+ #define VER_FILEVERSION_STR XSTRINGIZE(RNW_PKG_VERSION_STR)
8
8
  #else
9
9
  #define VER_FILEVERSION_STR "Private Build"
10
10
  #endif
@@ -110,7 +110,6 @@ void DevMenuManager::CreateAndShowUI() noexcept {
110
110
  devMenu.FastRefreshText().Text(
111
111
  Mso::React::ReactOptions::UseFastRefresh(m_context->Properties()) ? L"Disable Fast Refresh"
112
112
  : L"Enable Fast Refresh");
113
-
114
113
  if (Mso::React::ReactOptions::JsiEngine(m_context->Properties()) == Mso::React::JSIEngine::Hermes) {
115
114
  devMenu.SamplingProfilerText().Text(
116
115
  !Microsoft::ReactNative::HermesSamplingProfiler::IsStarted() ? L"Start Hermes sampling profiler"
@@ -6,6 +6,7 @@
6
6
  #include "RootViewManager.h"
7
7
 
8
8
  #include <IXamlRootView.h>
9
+ #include <ReactRootView.h>
9
10
  #include <UI.Xaml.Controls.h>
10
11
 
11
12
  namespace winrt {
@@ -29,21 +30,19 @@ XamlView RootViewManager::CreateViewCore(int64_t /*tag*/, const winrt::Microsoft
29
30
  }
30
31
 
31
32
  void RootViewManager::AddView(const XamlView &parent, const XamlView &child, int64_t index) {
32
- auto panel(parent.as<winrt::Panel>());
33
- if (panel != nullptr)
34
- panel.Children().InsertAt(static_cast<uint32_t>(index), child.as<xaml::UIElement>());
33
+ // Goes through RootShadowNode::AddView instead of here
34
+ assert(false);
35
35
  }
36
36
 
37
37
  void RootViewManager::RemoveAllChildren(const XamlView &parent) {
38
- auto panel(parent.as<winrt::Panel>());
39
- if (panel != nullptr)
40
- panel.Children().Clear();
38
+ auto panel(parent.as<winrt::Microsoft::ReactNative::ReactRootView>());
39
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactRootView>(panel)->RemoveAllChildren();
41
40
  }
42
41
 
43
42
  void RootViewManager::RemoveChildAt(const XamlView &parent, int64_t index) {
44
- auto panel(parent.as<winrt::Panel>());
45
- if (panel != nullptr)
46
- panel.Children().RemoveAt(static_cast<uint32_t>(index));
43
+ auto panel(parent.as<winrt::Microsoft::ReactNative::ReactRootView>());
44
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactRootView>(panel)->RemoveChildAt(
45
+ static_cast<uint32_t>(index));
47
46
  }
48
47
 
49
48
  void RootViewManager::SetLayoutProps(
@@ -8,12 +8,9 @@
8
8
  <!-- Enabling this will (1) Include hermes glues in the Microsoft.ReactNative binaries AND (2) Make hermes the default engine -->
9
9
  <UseHermes Condition="'$(UseHermes)' == ''">false</UseHermes>
10
10
  <!-- This will be true if (1) the client want to use hermes by setting UseHermes to true OR (2) We are building for UWP where dynamic switching is enabled -->
11
- <IncludeHermes Condition="'$(IncludeHermes)' == '' And ('$(UseHermes)' == 'true' Or '$(ApplicationType)' == 'Windows Store')">true</IncludeHermes>
12
11
  <HermesVersion Condition="'$(HermesVersion)' == ''">0.9.0-ms.4</HermesVersion>
13
12
  <HermesPackage Condition="'$(HermesPackage)' == '' And Exists('$(PkgReactNative_Hermes_Windows)')">$(PkgReactNative_Hermes_Windows)</HermesPackage>
14
13
  <HermesPackage Condition="'$(HermesPackage)' == ''">$(SolutionDir)packages\ReactNative.Hermes.Windows.$(HermesVersion)</HermesPackage>
15
- <!-- TODO: Can we automatically distinguish between uwp and win32 here? -->
16
- <HermesArch Condition="'$(HermesArch)' == ''">uwp</HermesArch>
17
14
  <EnableHermesInspectorInReleaseFlavor Condition="'$(EnableHermesInspectorInReleaseFlavor)' == ''">false</EnableHermesInspectorInReleaseFlavor>
18
15
  <!-- Use Hermes bytecode bundles provided by metro hermes compiler when available -->
19
16
  <EnableDevServerHBCBundles Condition="'$(EnableDevServerHBCBundles)' == ''">false</EnableDevServerHBCBundles>
@@ -51,7 +51,6 @@
51
51
  <ItemDefinitionGroup>
52
52
  <ClCompile>
53
53
  <PreprocessorDefinitions Condition="'$(UseHermes)'=='true'">USE_HERMES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
54
- <PreprocessorDefinitions Condition="'$(IncludeHermes)'=='true'">INCLUDE_HERMES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
55
54
  <PreprocessorDefinitions Condition="'$(EnableDevServerHBCBundles)'=='true'">ENABLE_DEVSERVER_HBCBUNDLES;%(PreprocessorDefinitions)</PreprocessorDefinitions>
56
55
  <PreprocessorDefinitions Condition="'$(UseV8)'=='true'">USE_V8;%(PreprocessorDefinitions)</PreprocessorDefinitions>
57
56
  <PreprocessorDefinitions Condition="'$(UseFabric)'=='true'">USE_FABRIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -86,6 +85,7 @@
86
85
  BOOST_NO_TYPEID - Configure boost not to check typeid (not to use RTTI)
87
86
  BOOST_SYSTEM_SOURCE - Build boost::system symbols from sources (drop dependency on boost_system.lib).
88
87
  GTEST_HAS_RTTI - Let GTest know not to use RTTI
88
+ USE_EDGEMODE_JSRT When using Chakra, enforce System Chakra instead of JS9.
89
89
  WIN32_LEAN_AND_MEAN - Reduce the Windows API included surface.
90
90
  WINRT_LEAN_AND_MEAN - Disable rarely used cppwinrt templates that impact compile-time/PCH size.
91
91
  -->
@@ -97,6 +97,7 @@
97
97
  BOOST_NO_TYPEID;
98
98
  BOOST_SYSTEM_SOURCE;
99
99
  GTEST_HAS_RTTI=0;
100
+ USE_EDGEMODE_JSRT;
100
101
  WIN32_LEAN_AND_MEAN;
101
102
  %(PreprocessorDefinitions)
102
103
  </PreprocessorDefinitions>
@@ -8,7 +8,7 @@
8
8
  <_rnwFolder>$(MSBuildThisFileDirectory)..\..\runtimes\win10-$(Native-Platform)\native\</_rnwFolder>
9
9
  </PropertyGroup>
10
10
 
11
- <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
11
+ <ItemGroup>
12
12
  <Reference Include="$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.ReactNative.winmd" Private="false">
13
13
  <Implementation>Microsoft.ReactNative.dll</Implementation>
14
14
  </Reference>
@@ -14,12 +14,14 @@
14
14
  #include <hermes/hermes_dbg.h>
15
15
  #endif
16
16
  #include "HermesRuntimeHolder.h"
17
+ #include "HermesShim.h"
17
18
 
18
19
  #if defined(HERMES_ENABLE_DEBUGGER)
19
20
  #include <hermes/inspector/chrome/Registration.h>
20
21
  #endif
21
22
 
22
23
  using namespace facebook;
24
+ using namespace Microsoft::ReactNative;
23
25
 
24
26
  namespace facebook {
25
27
  namespace react {
@@ -29,7 +31,7 @@ namespace {
29
31
  std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeSystraced(
30
32
  const ::hermes::vm::RuntimeConfig &runtimeConfig) {
31
33
  SystraceSection s("HermesExecutorFactory::makeHermesRuntimeSystraced");
32
- return hermes::makeHermesRuntime(runtimeConfig);
34
+ return HermesShim::makeHermesRuntime(runtimeConfig);
33
35
  }
34
36
 
35
37
  #ifdef HERMES_ENABLE_DEBUGGER
@@ -15,6 +15,7 @@
15
15
  #endif
16
16
 
17
17
  #include "HermesSamplingProfiler.h"
18
+ #include "HermesShim.h"
18
19
 
19
20
  namespace Microsoft::ReactNative {
20
21
 
@@ -50,26 +51,24 @@ std::string HermesSamplingProfiler::GetLastTraceFilePath() noexcept {
50
51
  }
51
52
 
52
53
  winrt::fire_and_forget HermesSamplingProfiler::Start() noexcept {
53
- #ifdef INCLUDE_HERMES
54
54
  if (!s_isStarted) {
55
55
  s_isStarted = true;
56
56
  co_await winrt::resume_background();
57
- facebook::hermes::HermesRuntime::enableSamplingProfiler();
57
+ HermesShim::enableSamplingProfiler();
58
58
  }
59
- #endif
59
+
60
60
  co_return;
61
61
  }
62
62
 
63
63
  std::future<std::string> HermesSamplingProfiler::Stop() noexcept {
64
- #ifdef INCLUDE_HERMES
65
64
  if (s_isStarted) {
66
65
  s_isStarted = false;
67
66
  co_await winrt::resume_background();
68
- facebook::hermes::HermesRuntime::disableSamplingProfiler();
67
+ HermesShim::disableSamplingProfiler();
69
68
  s_lastTraceFilePath = co_await getTraceFilePath();
70
- facebook::hermes::HermesRuntime::dumpSampledTraceToFile(s_lastTraceFilePath);
69
+ HermesShim::dumpSampledTraceToFile(s_lastTraceFilePath);
71
70
  }
72
- #endif
71
+
73
72
  co_return s_lastTraceFilePath;
74
73
  }
75
74
 
@@ -0,0 +1,85 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #include "HermesShim.h"
5
+ #include "Crash.h"
6
+
7
+ namespace Microsoft::ReactNative::HermesShim {
8
+
9
+ static HMODULE s_hermesModule{nullptr};
10
+ static decltype(&facebook::hermes::makeHermesRuntime) s_makeHermesRuntime{nullptr};
11
+ static decltype(&facebook::hermes::HermesRuntime::enableSamplingProfiler) s_enableSamplingProfiler{nullptr};
12
+ static decltype(&facebook::hermes::HermesRuntime::disableSamplingProfiler) s_disableSamplingProfiler{nullptr};
13
+ static decltype(&facebook::hermes::HermesRuntime::dumpSampledTraceToFile) s_dumpSampledTraceToFile{nullptr};
14
+
15
+ #if _M_X64
16
+ constexpr const char *makeHermesRuntimeSymbol =
17
+ "?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@AEBVRuntimeConfig@vm@1@@Z";
18
+ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
19
+ constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
20
+ constexpr const char *dumpSampledTraceToFileSymbol =
21
+ "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
22
+ #endif
23
+
24
+ #if _M_ARM64
25
+ constexpr const char *makeHermesRuntimeSymbol =
26
+ "?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@AEBVRuntimeConfig@vm@1@@Z";
27
+ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
28
+ constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
29
+ constexpr const char *dumpSampledTraceToFileSymbol =
30
+ "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
31
+ #endif
32
+
33
+ #if _M_IX86
34
+ constexpr const char *makeHermesRuntimeSymbol =
35
+ "?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@ABVRuntimeConfig@vm@1@@Z";
36
+ constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
37
+ constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
38
+ constexpr const char *dumpSampledTraceToFileSymbol =
39
+ "?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
40
+ #endif
41
+
42
+ static void EnsureHermesLoaded() noexcept {
43
+ if (!s_hermesModule) {
44
+ s_hermesModule = LoadLibrary(L"hermes.dll");
45
+ VerifyElseCrashSz(s_hermesModule, "Could not load \"hermes.dll\"");
46
+
47
+ s_makeHermesRuntime =
48
+ reinterpret_cast<decltype(s_makeHermesRuntime)>(GetProcAddress(s_hermesModule, makeHermesRuntimeSymbol));
49
+ VerifyElseCrash(s_makeHermesRuntime);
50
+
51
+ s_enableSamplingProfiler = reinterpret_cast<decltype(s_enableSamplingProfiler)>(
52
+ GetProcAddress(s_hermesModule, enableSamlingProfilerSymbol));
53
+ VerifyElseCrash(s_enableSamplingProfiler);
54
+
55
+ s_disableSamplingProfiler = reinterpret_cast<decltype(s_disableSamplingProfiler)>(
56
+ GetProcAddress(s_hermesModule, disableSamlingProfilerSymbol));
57
+ VerifyElseCrash(s_disableSamplingProfiler);
58
+
59
+ s_dumpSampledTraceToFile = reinterpret_cast<decltype(s_dumpSampledTraceToFile)>(
60
+ GetProcAddress(s_hermesModule, dumpSampledTraceToFileSymbol));
61
+ VerifyElseCrash(s_dumpSampledTraceToFile);
62
+ }
63
+ }
64
+
65
+ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntime(const hermes::vm::RuntimeConfig &runtimeConfig) {
66
+ EnsureHermesLoaded();
67
+ return s_makeHermesRuntime(runtimeConfig);
68
+ }
69
+
70
+ void enableSamplingProfiler() {
71
+ EnsureHermesLoaded();
72
+ s_enableSamplingProfiler();
73
+ }
74
+
75
+ void disableSamplingProfiler() {
76
+ EnsureHermesLoaded();
77
+ s_disableSamplingProfiler();
78
+ }
79
+
80
+ void dumpSampledTraceToFile(const std::string &fileName) {
81
+ EnsureHermesLoaded();
82
+ s_dumpSampledTraceToFile(fileName);
83
+ }
84
+
85
+ } // namespace Microsoft::ReactNative::HermesShim
@@ -0,0 +1,19 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #pragma once
5
+
6
+ #include <hermes/hermes.h>
7
+
8
+ //! We do not package hermes.dll for projects that do not require it. We cannot
9
+ //! use pure delay-loading to achieve this, since WACK will detect the
10
+ //! non-present DLL. Functions in this namespace shim to the Hermes DLL via
11
+ //! GetProcAddress.
12
+ namespace Microsoft::ReactNative::HermesShim {
13
+
14
+ std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntime(const hermes::vm::RuntimeConfig &runtimeConfig);
15
+ void enableSamplingProfiler();
16
+ void disableSamplingProfiler();
17
+ void dumpSampledTraceToFile(const std::string &fileName);
18
+
19
+ } // namespace Microsoft::ReactNative::HermesShim
@@ -144,17 +144,9 @@ ChakraApi::JsRefHolder::~JsRefHolder() noexcept {
144
144
  JsPropertyIdRef propertyId{JS_INVALID_REFERENCE};
145
145
  // We use a #ifdef here because we can avoid a UTF-8 to UTF-16 conversion
146
146
  // using ChakraCore's JsCreatePropertyId API.
147
- #ifdef CHAKRACORE
148
- if (React::GetRuntimeOptionBool("JSI.ForceSystemChakra")) {
149
- std::wstring utf16 = Common::Unicode::Utf8ToUtf16(name.data(), name.length());
150
- ChakraVerifyJsErrorElseThrow(JsGetPropertyIdFromName(utf16.data(), &propertyId));
151
- } else {
152
- ChakraVerifyJsErrorElseThrow(JsCreatePropertyId(name.data(), name.length(), &propertyId));
153
- }
154
- #else
155
147
  std::wstring utf16 = Common::Unicode::Utf8ToUtf16(name.data(), name.length());
156
148
  ChakraVerifyJsErrorElseThrow(JsGetPropertyIdFromName(utf16.data(), &propertyId));
157
- #endif
149
+
158
150
  return propertyId;
159
151
  }
160
152
 
@@ -275,18 +267,7 @@ ChakraApi::JsRefHolder::~JsRefHolder() noexcept {
275
267
  /*static*/ JsValueRef ChakraApi::PointerToString(std::string_view value) {
276
268
  ChakraVerifyElseThrow(value.data(), "Cannot convert a nullptr to a JS string.");
277
269
 
278
- // ChakraCore API helps to reduce cost of UTF-8 to UTF-16 conversion.
279
- #ifdef CHAKRACORE
280
- if (React::GetRuntimeOptionBool("JSI.ForceSystemChakra")) {
281
- return PointerToString(Common::Unicode::Utf8ToUtf16(value));
282
- } else {
283
- JsValueRef result{JS_INVALID_REFERENCE};
284
- ChakraVerifyJsErrorElseThrow(JsCreateString(value.data(), value.length(), &result));
285
- return result;
286
- }
287
- #else
288
270
  return PointerToString(Common::Unicode::Utf8ToUtf16(value));
289
- #endif
290
271
  }
291
272
 
292
273
  /*static*/ std::wstring_view ChakraApi::StringToPointer(JsValueRef string) {
@@ -300,24 +281,7 @@ ChakraApi::JsRefHolder::~JsRefHolder() noexcept {
300
281
  ChakraVerifyElseThrow(
301
282
  GetValueType(string) == JsString, "Cannot convert a non JS string ChakraObjectRef to a std::string.");
302
283
 
303
- // We use a #ifdef here because we can avoid a UTF-8 to UTF-16 conversion
304
- // using ChakraCore's JsCopyString API.
305
- #ifdef CHAKRACORE
306
- if (React::GetRuntimeOptionBool("JSI.ForceSystemChakra")) {
307
- return Common::Unicode::Utf16ToUtf8(StringToPointer(string));
308
- } else {
309
- size_t length{0};
310
- ChakraVerifyJsErrorElseThrow(JsCopyString(string, nullptr, 0, &length));
311
-
312
- std::string result(length, 'a');
313
- ChakraVerifyJsErrorElseThrow(JsCopyString(string, result.data(), result.length(), &length));
314
-
315
- ChakraVerifyElseThrow(length == result.length(), "Failed to convert a JS string to a std::string.");
316
- return result;
317
- }
318
- #else
319
284
  return Common::Unicode::Utf16ToUtf8(StringToPointer(string));
320
- #endif
321
285
  }
322
286
 
323
287
  /*static*/ JsValueRef ChakraApi::ConvertValueToString(JsValueRef value) {
@@ -3,14 +3,10 @@
3
3
 
4
4
  #pragma once
5
5
 
6
- #ifdef CHAKRACORE
7
- #include "ChakraCore.h"
8
- #else
9
6
  #ifndef USE_EDGEMODE_JSRT
10
7
  #define USE_EDGEMODE_JSRT
11
8
  #endif
12
9
  #include <jsrt.h>
13
- #endif
14
10
 
15
11
  #include <cassert>
16
12
  #include <cstddef>
@@ -15,7 +15,7 @@ JsStartDebugging();
15
15
 
16
16
  namespace Microsoft::JSI {
17
17
 
18
- #if defined(USE_EDGEMODE_JSRT) && !defined(CHAKRACORE)
18
+ #if defined(USE_EDGEMODE_JSRT)
19
19
  /*static*/ void ChakraRuntime::initRuntimeVersion() noexcept {}
20
20
  #endif
21
21
 
@@ -42,11 +42,7 @@ std::unique_ptr<const facebook::jsi::Buffer> SystemChakraRuntime::generatePrepar
42
42
  const std::wstring scriptUTF16 =
43
43
  Microsoft::Common::Unicode::Utf8ToUtf16(reinterpret_cast<const char *>(sourceBuffer.data()), sourceBuffer.size());
44
44
 
45
- #ifdef CHAKRACORE
46
- unsigned int bytecodeSize = 0;
47
- #else
48
45
  unsigned long bytecodeSize = 0;
49
- #endif
50
46
  if (JsSerializeScript(scriptUTF16.c_str(), nullptr, &bytecodeSize) == JsNoError) {
51
47
  std::unique_ptr<ByteArrayBuffer> bytecodeBuffer(std::make_unique<ByteArrayBuffer>(bytecodeSize));
52
48
  if (JsSerializeScript(scriptUTF16.c_str(), bytecodeBuffer->data(), &bytecodeSize) == JsNoError) {
@@ -16,14 +16,10 @@
16
16
  #include <sstream>
17
17
  #include <unordered_set>
18
18
 
19
- #ifdef CHAKRACORE
20
- #include <ChakraCore.h>
21
- #else
22
19
  #ifndef USE_EDGEMODE_JSRT
23
20
  #define USE_EDGEMODE_JSRT
24
21
  #endif
25
22
  #include <jsrt.h>
26
- #endif
27
23
 
28
24
  namespace Microsoft::JSI {
29
25
 
@@ -1011,15 +1007,7 @@ std::once_flag ChakraRuntime::s_runtimeVersionInitFlag;
1011
1007
  uint64_t ChakraRuntime::s_runtimeVersion = 0;
1012
1008
 
1013
1009
  std::unique_ptr<facebook::jsi::Runtime> makeChakraRuntime(ChakraRuntimeArgs &&args) noexcept {
1014
- #ifdef CHAKRACORE
1015
- if (React::GetRuntimeOptionBool("JSI.ForceSystemChakra")) {
1016
- return MakeSystemChakraRuntime(std::move(args));
1017
- } else {
1018
- return MakeChakraCoreRuntime(std::move(args));
1019
- }
1020
- #else
1021
1010
  return MakeSystemChakraRuntime(std::move(args));
1022
- #endif // CHAKRACORE
1023
1011
  }
1024
1012
 
1025
1013
  } // namespace Microsoft::JSI
@@ -11,7 +11,5 @@ struct ChakraRuntimeArgs;
11
11
 
12
12
  std::unique_ptr<facebook::jsi::Runtime> makeChakraRuntime(ChakraRuntimeArgs &&args) noexcept;
13
13
 
14
- std::unique_ptr<facebook::jsi::Runtime> MakeChakraCoreRuntime(ChakraRuntimeArgs &&args) noexcept;
15
-
16
14
  std::unique_ptr<facebook::jsi::Runtime> MakeSystemChakraRuntime(ChakraRuntimeArgs &&args) noexcept;
17
15
  } // namespace Microsoft::JSI