react-native-windows 0.71.24 → 0.71.26

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 (78) hide show
  1. package/Directory.Build.props +5 -0
  2. package/Libraries/Network/RCTNetworking.windows.js +10 -16
  3. package/Microsoft.ReactNative/IReactDispatcher.cpp +4 -0
  4. package/Microsoft.ReactNative/IReactDispatcher.h +1 -0
  5. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +3 -7
  6. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +0 -7
  7. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +43 -21
  8. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +0 -2
  9. package/Microsoft.ReactNative/Views/DevMenu.cpp +3 -3
  10. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +16 -0
  11. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +43 -12
  12. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +17 -6
  13. package/Microsoft.ReactNative.Managed/packages.lock.json +73 -4
  14. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +1 -1
  15. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -1
  16. package/PropertySheets/External/Microsoft.ReactNative.WinAppSDK.CSharpApp.targets +1 -1
  17. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  18. package/PropertySheets/JSEngine.props +4 -4
  19. package/PropertySheets/React.Cpp.props +3 -3
  20. package/PropertySheets/Warnings.props +6 -0
  21. package/ReactCommon/ReactCommon.vcxproj +53 -1
  22. package/ReactCommon/cgmanifest.json +15 -0
  23. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +36 -0
  24. package/Shared/BaseFileReaderResource.cpp +95 -0
  25. package/Shared/BaseFileReaderResource.h +41 -0
  26. package/Shared/CreateModules.h +27 -5
  27. package/Shared/DevSupportManager.cpp +2 -9
  28. package/Shared/DevSupportManager.h +2 -6
  29. package/Shared/HermesRuntimeHolder.cpp +344 -84
  30. package/Shared/HermesRuntimeHolder.h +32 -21
  31. package/Shared/HermesSamplingProfiler.cpp +66 -14
  32. package/Shared/HermesSamplingProfiler.h +5 -3
  33. package/Shared/IFileReaderResource.h +36 -0
  34. package/Shared/InspectorPackagerConnection.cpp +62 -108
  35. package/Shared/InspectorPackagerConnection.h +9 -21
  36. package/Shared/JSI/RuntimeHolder.h +2 -2
  37. package/Shared/JSI/ScriptStore.h +18 -20
  38. package/Shared/JSI/V8RuntimeHolder.cpp +260 -0
  39. package/Shared/JSI/V8RuntimeHolder.h +37 -0
  40. package/Shared/Modules/BlobModule.cpp +93 -298
  41. package/Shared/Modules/BlobModule.h +25 -91
  42. package/Shared/Modules/CxxModuleUtilities.cpp +32 -0
  43. package/Shared/Modules/CxxModuleUtilities.h +17 -0
  44. package/Shared/Modules/FileReaderModule.cpp +118 -51
  45. package/Shared/Modules/FileReaderModule.h +27 -1
  46. package/Shared/Modules/HttpModule.cpp +143 -32
  47. package/Shared/Modules/HttpModule.h +33 -1
  48. package/Shared/Modules/IRequestBodyHandler.h +6 -4
  49. package/Shared/Modules/IResponseHandler.h +3 -3
  50. package/Shared/Modules/IUriHandler.h +3 -3
  51. package/Shared/Modules/IWebSocketModuleContentHandler.h +6 -4
  52. package/Shared/Modules/WebSocketModule.cpp +190 -7
  53. package/Shared/Modules/WebSocketTurboModule.h +52 -0
  54. package/Shared/Networking/DefaultBlobResource.cpp +328 -0
  55. package/Shared/Networking/DefaultBlobResource.h +133 -0
  56. package/Shared/Networking/IBlobResource.h +56 -0
  57. package/Shared/Networking/IHttpResource.h +6 -5
  58. package/Shared/Networking/WinRTHttpResource.cpp +49 -32
  59. package/Shared/Networking/WinRTHttpResource.h +4 -3
  60. package/Shared/Networking/WinRTTypes.h +3 -3
  61. package/Shared/OInstance.cpp +32 -68
  62. package/Shared/SafeLoadLibrary.cpp +41 -0
  63. package/Shared/SafeLoadLibrary.h +15 -0
  64. package/Shared/Shared.vcxitems +27 -9
  65. package/Shared/Shared.vcxitems.filters +47 -33
  66. package/package.json +2 -2
  67. package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
  68. package/Microsoft.ReactNative/Base/CoreNativeModules.cpp +0 -59
  69. package/Microsoft.ReactNative/Base/CoreNativeModules.h +0 -30
  70. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +0 -2103
  71. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +0 -73
  72. package/Shared/HermesShim.cpp +0 -118
  73. package/Shared/HermesShim.h +0 -21
  74. package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +0 -209
  75. package/Shared/JSI/NapiJsiV8RuntimeHolder.h +0 -44
  76. package/Shared/V8JSIRuntimeHolder.cpp +0 -70
  77. package/Shared/V8JSIRuntimeHolder.h +0 -53
  78. /package/Shared/{Modules/IBlobPersistor.h → IBlobPersistor.h} +0 -0
@@ -6,6 +6,7 @@
6
6
  #include "WinRTHttpResource.h"
7
7
 
8
8
  #include <CppRuntimeOptions.h>
9
+ #include <Networking/IBlobResource.h>
9
10
  #include <ReactPropertyBag.h>
10
11
  #include <Utils/CppWinrtLessExceptions.h>
11
12
  #include <Utils/WinRTConversions.h>
@@ -23,8 +24,6 @@
23
24
  #include <winrt/Windows.Storage.Streams.h>
24
25
  #include <winrt/Windows.Web.Http.Headers.h>
25
26
 
26
- using folly::dynamic;
27
-
28
27
  using std::function;
29
28
  using std::scoped_lock;
30
29
  using std::shared_ptr;
@@ -35,6 +34,7 @@ using std::weak_ptr;
35
34
  using winrt::fire_and_forget;
36
35
  using winrt::hresult_error;
37
36
  using winrt::to_hstring;
37
+ using winrt::Microsoft::ReactNative::JSValueObject;
38
38
  using winrt::Windows::Foundation::IAsyncOperation;
39
39
  using winrt::Windows::Foundation::IInspectable;
40
40
  using winrt::Windows::Foundation::Uri;
@@ -69,15 +69,15 @@ constexpr char responseTypeBlob[] = "blob";
69
69
  namespace Microsoft::React::Networking {
70
70
 
71
71
  // May throw winrt::hresult_error
72
- void AttachMultipartHeaders(IHttpContent content, const dynamic &headers) {
72
+ void AttachMultipartHeaders(IHttpContent content, const JSValueObject &headers) {
73
73
  HttpMediaTypeHeaderValue contentType{nullptr};
74
74
 
75
75
  // Headers are generally case-insensitive
76
76
  // https://www.ietf.org/rfc/rfc2616.txt section 4.2
77
77
  // TODO: Consolidate with PerformRequest's header parsing.
78
- for (auto &header : headers.items()) {
79
- auto &name = header.first.getString();
80
- auto &value = header.second.getString();
78
+ for (auto &header : headers) {
79
+ auto &name = header.first;
80
+ auto value = header.second.AsString();
81
81
 
82
82
  if (boost::iequals(name.c_str(), "Content-Type")) {
83
83
  contentType = HttpMediaTypeHeaderValue::Parse(to_hstring(value));
@@ -147,6 +147,14 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
147
147
  }
148
148
  co_return nullptr;
149
149
  }
150
+ } else if (boost::iequals(name.c_str(), "User-Agent")) {
151
+ bool success = request.Headers().TryAppendWithoutValidation(to_hstring(name), to_hstring(value));
152
+ if (!success) {
153
+ if (self->m_onError) {
154
+ self->m_onError(reqArgs->RequestId, "Failed to append User-Agent", false);
155
+ }
156
+ co_return nullptr;
157
+ }
150
158
  } else {
151
159
  try {
152
160
  request.Headers().Append(to_hstring(name), to_hstring(value));
@@ -162,11 +170,11 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
162
170
  // Initialize content
163
171
  IHttpContent content{nullptr};
164
172
  auto &data = reqArgs->Data;
165
- if (!data.isNull()) {
173
+ if (!data.empty()) {
166
174
  auto bodyHandler = self->m_requestBodyHandler.lock();
167
175
  if (bodyHandler && bodyHandler->Supports(data)) {
168
176
  auto contentTypeString = contentType ? winrt::to_string(contentType.ToString()) : "";
169
- dynamic blob;
177
+ JSValueObject blob;
170
178
  try {
171
179
  blob = bodyHandler->ToRequestBody(data, contentTypeString);
172
180
  } catch (const std::invalid_argument &e) {
@@ -175,44 +183,45 @@ IAsyncOperation<HttpRequestMessage> WinRTHttpResource::CreateRequest(
175
183
  }
176
184
  co_return nullptr;
177
185
  }
178
- auto bytes = blob["bytes"];
186
+ auto &bytes = blob["bytes"].AsArray();
179
187
  auto byteVector = vector<uint8_t>(bytes.size());
180
188
  for (auto &byte : bytes) {
181
- byteVector.push_back(static_cast<uint8_t>(byte.asInt()));
189
+ byteVector.push_back(static_cast<uint8_t>(byte.AsUInt8()));
182
190
  }
183
191
  auto view = winrt::array_view<uint8_t const>{byteVector};
184
192
  auto buffer = CryptographicBuffer::CreateFromByteArray(view);
185
193
  content = HttpBufferContent{std::move(buffer)};
186
- } else if (!data["string"].isNull()) {
187
- content = HttpStringContent{to_hstring(data["string"].asString())};
188
- } else if (!data["base64"].empty()) {
189
- auto buffer = CryptographicBuffer::DecodeFromBase64String(to_hstring(data["base64"].asString()));
194
+ } else if (data.find("string") != data.cend()) {
195
+ content = HttpStringContent{to_hstring(data["string"].AsString())};
196
+ } else if (data.find("base64") != data.cend()) {
197
+ auto buffer = CryptographicBuffer::DecodeFromBase64String(to_hstring(data["base64"].AsString()));
190
198
  content = HttpBufferContent{std::move(buffer)};
191
- } else if (!data["uri"].empty()) {
192
- auto file = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{to_hstring(data["uri"].asString())});
199
+ } else if (data.find("uri") != data.cend()) {
200
+ auto file = co_await StorageFile::GetFileFromApplicationUriAsync(Uri{to_hstring(data["uri"].AsString())});
193
201
  auto stream = co_await file.OpenReadAsync();
194
202
  content = HttpStreamContent{std::move(stream)};
195
- } else if (!data["formData"].empty()) {
203
+ } else if (data.find("formData") != data.cend()) {
196
204
  winrt::Windows::Web::Http::HttpMultipartFormDataContent multiPartContent;
197
- auto formData = data["formData"];
205
+ auto &formData = data["formData"].AsObject();
198
206
 
199
207
  // #6046 - Overwriting WinRT's HttpMultipartFormDataContent implicit Content-Type clears the generated boundary
200
208
  contentType = nullptr;
201
209
 
202
210
  for (auto &formDataPart : formData) {
203
211
  IHttpContent formContent{nullptr};
204
- if (!formDataPart["string"].isNull()) {
205
- formContent = HttpStringContent{to_hstring(formDataPart["string"].asString())};
206
- } else if (!formDataPart["uri"].empty()) {
207
- auto filePath = to_hstring(formDataPart["uri"].asString());
212
+ auto &itr = formDataPart.second["string"];
213
+ if (!formDataPart.second["string"].IsNull()) {
214
+ formContent = HttpStringContent{to_hstring(formDataPart.second["string"].AsString())};
215
+ } else if (!formDataPart.second["uri"].IsNull()) {
216
+ auto filePath = to_hstring(formDataPart.second["uri"].AsString());
208
217
  auto file = co_await StorageFile::GetFileFromPathAsync(filePath);
209
218
  auto stream = co_await file.OpenReadAsync();
210
219
  formContent = HttpStreamContent{stream};
211
220
  }
212
221
 
213
222
  if (formContent) {
214
- AttachMultipartHeaders(formContent, formDataPart["headers"]);
215
- multiPartContent.Add(formContent, to_hstring(formDataPart["fieldName"].asString()));
223
+ AttachMultipartHeaders(formContent, formDataPart.second["headers"].AsObject());
224
+ multiPartContent.Add(formContent, to_hstring(formDataPart.second["fieldName"].AsString()));
216
225
  }
217
226
  } // foreach form data part
218
227
 
@@ -266,7 +275,7 @@ void WinRTHttpResource::SendRequest(
266
275
  string &&url,
267
276
  int64_t requestId,
268
277
  Headers &&headers,
269
- dynamic &&data,
278
+ JSValueObject &&data,
270
279
  string &&responseType,
271
280
  bool useIncrementalUpdates,
272
281
  int64_t timeout,
@@ -345,10 +354,10 @@ void WinRTHttpResource::SetOnData(function<void(int64_t requestId, string &&resp
345
354
  m_onData = std::move(handler);
346
355
  }
347
356
 
348
- void WinRTHttpResource::SetOnData(function<void(int64_t requestId, dynamic &&responseData)> &&handler) noexcept
357
+ void WinRTHttpResource::SetOnData(function<void(int64_t requestId, JSValueObject &&responseData)> &&handler) noexcept
349
358
  /*override*/
350
359
  {
351
- m_onDataDynamic = std::move(handler);
360
+ m_onDataObject = std::move(handler);
352
361
  }
353
362
 
354
363
  void WinRTHttpResource::SetOnIncrementalData(
@@ -397,7 +406,7 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
397
406
  // Ensure background thread
398
407
  co_await winrt::resume_background();
399
408
 
400
- auto props = winrt::multi_threaded_map<winrt::hstring, IInspectable>();
409
+ auto props = winrt::single_threaded_map<winrt::hstring, IInspectable>();
401
410
  props.Insert(L"RequestArgs", coArgs);
402
411
 
403
412
  auto coRequestOp = CreateRequest(std::move(coMethod), std::move(coUri), props);
@@ -418,8 +427,8 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
418
427
  try {
419
428
  if (uriHandler->Supports(uri, reqArgs->ResponseType)) {
420
429
  auto blob = uriHandler->Fetch(uri);
421
- if (self->m_onDataDynamic && self->m_onRequestSuccess) {
422
- self->m_onDataDynamic(reqArgs->RequestId, std::move(blob));
430
+ if (self->m_onDataObject && self->m_onRequestSuccess) {
431
+ self->m_onDataObject(reqArgs->RequestId, std::move(blob));
423
432
  self->m_onRequestSuccess(reqArgs->RequestId);
424
433
  }
425
434
 
@@ -528,8 +537,8 @@ WinRTHttpResource::PerformSendRequest(HttpMethod &&method, Uri &&rtUri, IInspect
528
537
 
529
538
  auto blob = responseHandler->ToResponseData(std::move(responseData));
530
539
 
531
- if (self->m_onDataDynamic && self->m_onRequestSuccess) {
532
- self->m_onDataDynamic(reqArgs->RequestId, std::move(blob));
540
+ if (self->m_onDataObject && self->m_onRequestSuccess) {
541
+ self->m_onDataObject(reqArgs->RequestId, std::move(blob));
533
542
  self->m_onRequestSuccess(reqArgs->RequestId);
534
543
  }
535
544
 
@@ -664,6 +673,14 @@ void WinRTHttpResource::AddResponseHandler(shared_ptr<IResponseHandler> response
664
673
  auto propBag = ReactPropertyBag{inspectableProperties.try_as<IReactPropertyBag>()};
665
674
  auto moduleProxy = weak_ptr<IHttpModuleProxy>{result};
666
675
  propBag.Set(propId, std::move(moduleProxy));
676
+
677
+ // #11439 - Best-effort attempt to set up the HTTP handler after an initial call to addNetworkingHandler failed.
678
+ auto blobRcPropId = ReactPropertyId<ReactNonAbiValue<weak_ptr<Networking::IBlobResource>>>{L"Blob.Resource"};
679
+ if (auto prop = propBag.Get(blobRcPropId)) {
680
+ if (auto blobRc = prop.Value().lock()) {
681
+ blobRc->AddNetworkingHandler();
682
+ }
683
+ }
667
684
  }
668
685
 
669
686
  return result;
@@ -28,7 +28,7 @@ class WinRTHttpResource : public IHttpResource,
28
28
  std::function<void(int64_t requestId)> m_onRequestSuccess;
29
29
  std::function<void(int64_t requestId, Response &&response)> m_onResponse;
30
30
  std::function<void(int64_t requestId, std::string &&responseData)> m_onData;
31
- std::function<void(int64_t requestId, folly::dynamic &&responseData)> m_onDataDynamic;
31
+ std::function<void(int64_t requestId, winrt::Microsoft::ReactNative::JSValueObject &&responseData)> m_onDataObject;
32
32
  std::function<void(int64_t requestId, std::string &&errorMessage, bool isTimeout)> m_onError;
33
33
  std::function<void(int64_t requestId, std::string &&responseData, int64_t progress, int64_t total)>
34
34
  m_onIncrementalData;
@@ -71,7 +71,7 @@ class WinRTHttpResource : public IHttpResource,
71
71
  std::string &&url,
72
72
  int64_t requestId,
73
73
  Headers &&headers,
74
- folly::dynamic &&data,
74
+ winrt::Microsoft::ReactNative::JSValueObject &&data,
75
75
  std::string &&responseType,
76
76
  bool useIncrementalUpdates,
77
77
  int64_t timeout,
@@ -83,7 +83,8 @@ class WinRTHttpResource : public IHttpResource,
83
83
  void SetOnRequestSuccess(std::function<void(int64_t requestId)> &&handler) noexcept override;
84
84
  void SetOnResponse(std::function<void(int64_t requestId, Response &&response)> &&handler) noexcept override;
85
85
  void SetOnData(std::function<void(int64_t requestId, std::string &&responseData)> &&handler) noexcept override;
86
- void SetOnData(std::function<void(int64_t requestId, folly::dynamic &&responseData)> &&handler) noexcept override;
86
+ void SetOnData(std::function<void(int64_t requestId, winrt::Microsoft::ReactNative::JSValueObject &&responseData)>
87
+ &&handler) noexcept override;
87
88
  void SetOnIncrementalData(
88
89
  std::function<void(int64_t requestId, std::string &&responseData, int64_t progress, int64_t total)>
89
90
  &&handler) noexcept override;
@@ -5,8 +5,8 @@
5
5
 
6
6
  #include "IHttpResource.h"
7
7
 
8
- // Folly
9
- #include <folly/dynamic.h>
8
+ // React Native Windows
9
+ #include <JSValue.h>
10
10
 
11
11
  // Windows API
12
12
  #include <winrt/Windows.Web.Http.h>
@@ -19,7 +19,7 @@ namespace Microsoft::React::Networking {
19
19
  struct RequestArgs : public winrt::implements<RequestArgs, winrt::Windows::Foundation::IInspectable> {
20
20
  int64_t RequestId;
21
21
  IHttpResource::Headers Headers;
22
- folly::dynamic Data;
22
+ winrt::Microsoft::ReactNative::JSValueObject Data;
23
23
  bool IncrementalUpdates;
24
24
  bool WithCredentials;
25
25
  std::string ResponseType;
@@ -26,7 +26,6 @@
26
26
  #include <cxxreact/ModuleRegistry.h>
27
27
 
28
28
  #include <Modules/ExceptionsManagerModule.h>
29
- #include <Modules/HttpModule.h>
30
29
  #include <Modules/PlatformConstantsModule.h>
31
30
  #include <Modules/SourceCodeModule.h>
32
31
  #include <Modules/StatusBarManagerModule.h>
@@ -52,13 +51,11 @@
52
51
  #include "HermesRuntimeHolder.h"
53
52
 
54
53
  #if defined(USE_V8)
55
- #include <JSI/NapiJsiV8RuntimeHolder.h>
56
-
57
- #include "BaseScriptStoreImpl.h"
58
- #include "V8JSIRuntimeHolder.h"
54
+ #include <JSI/V8RuntimeHolder.h>
59
55
  #endif
60
56
  #include <ReactCommon/CallInvoker.h>
61
57
  #include <ReactCommon/TurboModuleBinding.h>
58
+ #include "BaseScriptStoreImpl.h"
62
59
  #include "ChakraRuntimeHolder.h"
63
60
 
64
61
  #include <tracing/tracing.h>
@@ -70,15 +67,6 @@ using namespace Microsoft::JSI;
70
67
  using std::make_shared;
71
68
  using winrt::Microsoft::ReactNative::ReactPropertyBagHelper;
72
69
 
73
- namespace Microsoft::React {
74
-
75
- /*extern*/ std::unique_ptr<facebook::xplat::module::CxxModule> CreateHttpModule(
76
- winrt::Windows::Foundation::IInspectable const &inspectableProperties) noexcept {
77
- return std::make_unique<HttpModule>(inspectableProperties);
78
- }
79
-
80
- } // namespace Microsoft::React
81
-
82
70
  namespace facebook {
83
71
  namespace react {
84
72
 
@@ -318,46 +306,32 @@ InstanceImpl::InstanceImpl(
318
306
  } else {
319
307
  assert(m_devSettings->jsiEngineOverride != JSIEngineOverride::Default);
320
308
  switch (m_devSettings->jsiEngineOverride) {
321
- case JSIEngineOverride::Hermes:
322
- m_devSettings->jsiRuntimeHolder = std::make_shared<HermesRuntimeHolder>(m_devSettings, m_jsThread);
323
- break;
324
- case JSIEngineOverride::V8: {
325
- #if defined(USE_V8)
326
- std::unique_ptr<facebook::jsi::ScriptStore> scriptStore = nullptr;
327
- std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore = nullptr;
309
+ case JSIEngineOverride::Hermes: {
310
+ std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore;
328
311
 
329
- char tempPath[MAX_PATH];
330
- if (GetTempPathA(MAX_PATH, tempPath)) {
331
- preparedScriptStore = std::make_unique<facebook::react::BasePreparedScriptStoreImpl>(tempPath);
312
+ wchar_t tempPath[MAX_PATH];
313
+ if (GetTempPathW(MAX_PATH, tempPath)) {
314
+ preparedScriptStore =
315
+ std::make_shared<facebook::react::BasePreparedScriptStoreImpl>(winrt::to_string(tempPath));
332
316
  }
333
317
 
334
- m_devSettings->jsiRuntimeHolder = std::make_shared<facebook::react::V8JSIRuntimeHolder>(
335
- m_devSettings, m_jsThread, std::move(scriptStore), std::move(preparedScriptStore));
318
+ m_devSettings->jsiRuntimeHolder = std::make_shared<Microsoft::ReactNative::HermesRuntimeHolder>(
319
+ m_devSettings, m_jsThread, std::move(preparedScriptStore));
336
320
  break;
337
- #else
338
- assert(false); // V8 is not available in this build, fallthrough
339
- [[fallthrough]];
340
- #endif
341
321
  }
322
+ case JSIEngineOverride::V8:
342
323
  case JSIEngineOverride::V8NodeApi: {
343
324
  #if defined(USE_V8)
344
- std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore;
325
+ std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore;
345
326
 
346
327
  wchar_t tempPath[MAX_PATH];
347
- if (GetTempPathW(static_cast<DWORD>(std::size(tempPath)), tempPath)) {
328
+ if (GetTempPathW(MAX_PATH, tempPath)) {
348
329
  preparedScriptStore =
349
- std::make_unique<facebook::react::BasePreparedScriptStoreImpl>(winrt::to_string(tempPath));
350
- }
351
-
352
- if (!preparedScriptStore) {
353
- if (m_devSettings->errorCallback)
354
- m_devSettings->errorCallback("Could not initialize prepared script store");
355
-
356
- break;
330
+ std::make_shared<facebook::react::BasePreparedScriptStoreImpl>(winrt::to_string(tempPath));
357
331
  }
358
332
 
359
- m_devSettings->jsiRuntimeHolder = make_shared<NapiJsiV8RuntimeHolder>(
360
- m_devSettings, m_jsThread, nullptr /*scriptStore*/, std::move(preparedScriptStore));
333
+ m_devSettings->jsiRuntimeHolder = make_shared<Microsoft::ReactNative::V8RuntimeHolder>(
334
+ m_devSettings, m_jsThread, std::move(preparedScriptStore), false);
361
335
  break;
362
336
  #else
363
337
  if (m_devSettings->errorCallback)
@@ -559,6 +533,10 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
559
533
  std::vector<std::unique_ptr<NativeModule>> modules;
560
534
  auto transitionalProps{ReactPropertyBagHelper::CreatePropertyBag()};
561
535
 
536
+ // These modules are instantiated separately in MSRN (Universal Windows).
537
+ // When there are module name collisions, the last one registered is used.
538
+ // If this code is enabled, we will have unused module instances.
539
+ // Also, MSRN has a different property bag mechanism incompatible with this method's transitionalProps variable.
562
540
  #if (defined(_MSC_VER) && !defined(WINRT))
563
541
  modules.push_back(std::make_unique<CxxNativeModule>(
564
542
  m_innerInstance,
@@ -567,7 +545,6 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
567
545
  return Microsoft::React::CreateHttpModule(transitionalProps);
568
546
  },
569
547
  nativeQueue));
570
- #endif
571
548
 
572
549
  modules.push_back(std::make_unique<CxxNativeModule>(
573
550
  m_innerInstance,
@@ -577,11 +554,18 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
577
554
  },
578
555
  nativeQueue));
579
556
 
580
- // TODO: This is not included for UWP because we have a different module which
581
- // is added later. However, this one is designed
582
- // so that we can base a UWP version on it. We need to do that but is not high
583
- // priority.
584
- #if (defined(_MSC_VER) && !defined(WINRT))
557
+ modules.push_back(std::make_unique<CxxNativeModule>(
558
+ m_innerInstance,
559
+ Microsoft::React::GetBlobModuleName(),
560
+ [transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
561
+ nativeQueue));
562
+
563
+ modules.push_back(std::make_unique<CxxNativeModule>(
564
+ m_innerInstance,
565
+ Microsoft::React::GetFileReaderModuleName(),
566
+ [transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
567
+ nativeQueue));
568
+
585
569
  modules.push_back(std::make_unique<CxxNativeModule>(
586
570
  m_innerInstance,
587
571
  "Timing",
@@ -636,26 +620,6 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
636
620
  []() { return std::make_unique<StatusBarManagerModule>(); },
637
621
  nativeQueue));
638
622
 
639
- // These modules are instantiated separately in MSRN (Universal Windows).
640
- // When there are module name colisions, the last one registered is used.
641
- // If this code is enabled, we will have unused module instances.
642
- // Also, MSRN has a different property bag mechanism incompatible with this method's transitionalProps variable.
643
- #if (defined(_MSC_VER) && !defined(WINRT))
644
- if (Microsoft::React::GetRuntimeOptionBool("Blob.EnableModule")) {
645
- modules.push_back(std::make_unique<CxxNativeModule>(
646
- m_innerInstance,
647
- Microsoft::React::GetBlobModuleName(),
648
- [transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
649
- nativeQueue));
650
-
651
- modules.push_back(std::make_unique<CxxNativeModule>(
652
- m_innerInstance,
653
- Microsoft::React::GetFileReaderModuleName(),
654
- [transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
655
- nativeQueue));
656
- }
657
- #endif
658
-
659
623
  return modules;
660
624
  }
661
625
 
@@ -0,0 +1,41 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #include "SafeLoadLibrary.h"
5
+
6
+ namespace Microsoft::ReactNative {
7
+
8
+ // Unsafe calls to LoadLibrary/LoadLibraryEx.
9
+ // The default behavior of LoadLibrary, or LoadLibraryEx without flags, is to try and find the dependency by iterating
10
+ // through a search order. This search order contains the current working directory. In the classic attack, a malicious
11
+ // DLL is dropped in the likely - controllable current working directory. The malicious DLL has the same name as a
12
+ // missing dependency or dependency that is not in the same directory as the executable. When the call to LoadLibrary
13
+ // is reached, the malicious DLL is loaded preferentially, and code execution occurs.
14
+ //
15
+ // The SafeLoadLibrary is the preferred ways to manually load dependencies.
16
+ // The API does not search the current working directory when resolving dependencies.
17
+ // The implementation is "borrowed" from Office MsoSafeLoadLibrary.
18
+
19
+ /**
20
+ List of new flags that control where to search for DLLs. Requires KB2533623.
21
+ */
22
+ const DWORD SafeLoadLibraryFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
23
+ LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS;
24
+
25
+ HMODULE SafeLoadLibrary(const wchar_t *wzFileName, HANDLE hFile, DWORD dwFlags) noexcept {
26
+ // When calling LoadLibrary, OR in LOAD_LIBRARY_SEARCH_DEFAULT_DIRS which enables all of the
27
+ // safe behaviors. Note that this flag is not compatible with LOAD_WITH_ALTERED_SEARCH_PATH.
28
+ HMODULE module =
29
+ LoadLibraryExW(wzFileName, hFile, (dwFlags | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) & ~LOAD_WITH_ALTERED_SEARCH_PATH);
30
+ if (module == nullptr && GetLastError() == ERROR_INVALID_PARAMETER) {
31
+ // Could have failed with actual bad parameters or an unpatched OS without KB2533623.
32
+ if (GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "AddDllDirectory") == nullptr) {
33
+ // Unpatched OS, remove all new flags.
34
+ module = LoadLibraryExW(wzFileName, hFile, dwFlags & ~SafeLoadLibraryFlags);
35
+ }
36
+ }
37
+
38
+ return module;
39
+ }
40
+
41
+ } // namespace Microsoft::ReactNative
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #ifndef WIN32_LEAN_AND_MEAN
5
+ #define WIN32_LEAN_AND_MEAN
6
+ #endif
7
+
8
+ #include <windows.h>
9
+
10
+ namespace Microsoft::ReactNative {
11
+
12
+ // Safe LoadLibraryEx wrapper that must be used instead of LoadLibrary.
13
+ extern HMODULE SafeLoadLibrary(const wchar_t *wzFileName, HANDLE hFile = nullptr, DWORD dwFlags = 0) noexcept;
14
+
15
+ } // namespace Microsoft::ReactNative
@@ -19,6 +19,7 @@
19
19
  <ClCompile Include="$(MSBuildThisFileDirectory)AsyncStorage\FollyDynamicConverter.cpp" />
20
20
  <ClCompile Include="$(MSBuildThisFileDirectory)AsyncStorage\KeyValueStorage.cpp" />
21
21
  <ClCompile Include="$(MSBuildThisFileDirectory)AsyncStorage\StorageFileIO.cpp" />
22
+ <ClCompile Include="$(MSBuildThisFileDirectory)BaseFileReaderResource.cpp" />
22
23
  <ClCompile Include="$(MSBuildThisFileDirectory)BaseScriptStoreImpl.cpp" />
23
24
  <ClCompile Include="$(MSBuildThisFileDirectory)ChakraRuntimeHolder.cpp" />
24
25
  <ClCompile Include="$(MSBuildThisFileDirectory)CxxMessageQueue.cpp" />
@@ -28,14 +29,13 @@
28
29
  <ClCompile Include="$(MSBuildThisFileDirectory)Hasher.cpp" />
29
30
  <ClCompile Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.cpp" />
30
31
  <ClCompile Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.cpp" />
31
- <ClCompile Include="$(MSBuildThisFileDirectory)HermesShim.cpp" />
32
32
  <ClCompile Include="$(MSBuildThisFileDirectory)InspectorPackagerConnection.cpp" />
33
33
  <ClCompile Include="$(MSBuildThisFileDirectory)InstanceManager.cpp" />
34
34
  <ClCompile Include="$(MSBuildThisFileDirectory)JSBigAbiString.cpp" />
35
35
  <ClCompile Include="$(MSBuildThisFileDirectory)JSI\ChakraApi.cpp" />
36
36
  <ClCompile Include="$(MSBuildThisFileDirectory)JSI\ChakraJsiRuntime_edgemode.cpp" />
37
37
  <ClCompile Include="$(MSBuildThisFileDirectory)JSI\ChakraRuntime.cpp" />
38
- <ClCompile Include="$(MSBuildThisFileDirectory)JSI\NapiJsiV8RuntimeHolder.cpp">
38
+ <ClCompile Include="$(MSBuildThisFileDirectory)JSI\V8RuntimeHolder.cpp">
39
39
  <ExcludedFromBuild Condition="'$(UseV8)' != 'true'">true</ExcludedFromBuild>
40
40
  </ClCompile>
41
41
  <ClCompile Include="$(MSBuildThisFileDirectory)LayoutAnimation.cpp" />
@@ -58,6 +58,7 @@
58
58
  <ClCompile Include="$(MSBuildThisFileDirectory)Modules\SourceCodeModule.cpp" />
59
59
  <ClCompile Include="$(MSBuildThisFileDirectory)Modules\StatusBarManagerModule.cpp" />
60
60
  <ClCompile Include="$(MSBuildThisFileDirectory)Modules\WebSocketModule.cpp" />
61
+ <ClCompile Include="$(MSBuildThisFileDirectory)Networking\DefaultBlobResource.cpp" />
61
62
  <ClCompile Include="$(MSBuildThisFileDirectory)Networking\OriginPolicyHttpFilter.cpp" />
62
63
  <ClCompile Include="$(MSBuildThisFileDirectory)Networking\RedirectHttpFilter.cpp" />
63
64
  <ClCompile Include="$(MSBuildThisFileDirectory)Networking\WinRTHttpResource.cpp" />
@@ -65,6 +66,7 @@
65
66
  <ClCompile Include="$(MSBuildThisFileDirectory)OInstance.cpp" />
66
67
  <ClCompile Include="$(MSBuildThisFileDirectory)PackagerConnection.cpp" />
67
68
  <ClCompile Include="$(MSBuildThisFileDirectory)RuntimeOptions.cpp" />
69
+ <ClCompile Include="$(MSBuildThisFileDirectory)SafeLoadLibrary.cpp" />
68
70
  <ClCompile Include="$(MSBuildThisFileDirectory)Threading\BatchingQueueThread.cpp" />
69
71
  <ClCompile Include="$(MSBuildThisFileDirectory)Threading\MessageDispatchQueue.cpp" />
70
72
  <ClCompile Include="$(MSBuildThisFileDirectory)Threading\MessageQueueThreadFactory.cpp" />
@@ -72,32 +74,31 @@
72
74
  <ClCompile Include="$(MSBuildThisFileDirectory)TurboModuleManager.cpp" />
73
75
  <ClCompile Include="$(MSBuildThisFileDirectory)Utils.cpp" />
74
76
  <ClCompile Include="$(MSBuildThisFileDirectory)Utils\WinRTConversions.cpp" />
75
- <ClCompile Include="$(MSBuildThisFileDirectory)V8JSIRuntimeHolder.cpp">
76
- <ExcludedFromBuild Condition="'$(UseV8)' != 'true'">true</ExcludedFromBuild>
77
- </ClCompile>
78
77
  </ItemGroup>
79
78
  <ItemGroup>
80
79
  <ClInclude Include="$(MSBuildThisFileDirectory)..\include\Shared\cdebug.h" />
80
+ <ClInclude Include="$(MSBuildThisFileDirectory)..\Microsoft.ReactNative\JsiApi.h" />
81
81
  <ClInclude Include="$(MSBuildThisFileDirectory)AbiSafe.h" />
82
82
  <ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorageModule.h" />
83
83
  <ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorage\AsyncStorageManager.h" />
84
84
  <ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorage\FollyDynamicConverter.h" />
85
85
  <ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorage\KeyValueStorage.h" />
86
+ <ClInclude Include="$(MSBuildThisFileDirectory)BaseFileReaderResource.h" />
86
87
  <ClInclude Include="$(MSBuildThisFileDirectory)CppRuntimeOptions.h" />
87
88
  <ClInclude Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.h" />
88
- <ClInclude Include="$(MSBuildThisFileDirectory)HermesShim.h" />
89
+ <ClInclude Include="$(MSBuildThisFileDirectory)IBlobPersistor.h" />
90
+ <ClInclude Include="$(MSBuildThisFileDirectory)IFileReaderResource.h" />
89
91
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ByteArrayBuffer.h" />
90
92
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ChakraApi.h" />
91
93
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ChakraRuntime.h" />
92
94
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ChakraRuntimeArgs.h" />
93
95
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ChakraRuntimeFactory.h" />
94
- <ClInclude Include="$(MSBuildThisFileDirectory)JSI\NapiJsiV8RuntimeHolder.h" />
96
+ <ClInclude Include="$(MSBuildThisFileDirectory)JSI\V8RuntimeHolder.h" />
95
97
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\RuntimeHolder.h" />
96
98
  <ClInclude Include="$(MSBuildThisFileDirectory)JSI\ScriptStore.h" />
97
99
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\BlobModule.h" />
98
100
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\CxxModuleUtilities.h" />
99
101
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\FileReaderModule.h" />
100
- <ClInclude Include="$(MSBuildThisFileDirectory)Modules\IBlobPersistor.h" />
101
102
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\IHttpModuleProxy.h" />
102
103
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\IRequestBodyHandler.h" />
103
104
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\IResponseHandler.h" />
@@ -106,6 +107,9 @@
106
107
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\IWebSocketModuleProxy.h" />
107
108
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\HttpModule.h" />
108
109
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\NetworkingModule.h" />
110
+ <ClInclude Include="$(MSBuildThisFileDirectory)Modules\WebSocketTurboModule.h" />
111
+ <ClInclude Include="$(MSBuildThisFileDirectory)Networking\DefaultBlobResource.h" />
112
+ <ClInclude Include="$(MSBuildThisFileDirectory)Networking\IBlobResource.h" />
109
113
  <ClInclude Include="$(MSBuildThisFileDirectory)Networking\IHttpResource.h" />
110
114
  <ClInclude Include="$(MSBuildThisFileDirectory)Networking\IRedirectEventSource.h" />
111
115
  <ClInclude Include="$(MSBuildThisFileDirectory)Networking\IWebSocketResource.h" />
@@ -146,6 +150,7 @@
146
150
  <ClInclude Include="$(MSBuildThisFileDirectory)NativeModuleProvider.h" />
147
151
  <ClInclude Include="$(MSBuildThisFileDirectory)OInstance.h" />
148
152
  <ClInclude Include="$(MSBuildThisFileDirectory)Pch\pch.h" />
153
+ <ClInclude Include="$(MSBuildThisFileDirectory)SafeLoadLibrary.h" />
149
154
  <ClInclude Include="$(MSBuildThisFileDirectory)ShadowNode.h" />
150
155
  <ClInclude Include="$(MSBuildThisFileDirectory)ShadowNodeRegistry.h" />
151
156
  <ClInclude Include="$(MSBuildThisFileDirectory)targetver.h" />
@@ -160,7 +165,6 @@
160
165
  <ClInclude Include="$(MSBuildThisFileDirectory)Utils.h" />
161
166
  <ClInclude Include="$(MSBuildThisFileDirectory)Utils\CppWinrtLessExceptions.h" />
162
167
  <ClInclude Include="$(MSBuildThisFileDirectory)Utils\WinRTConversions.h" />
163
- <ClInclude Include="$(MSBuildThisFileDirectory)V8JSIRuntimeHolder.h" />
164
168
  <ClInclude Include="$(MSBuildThisFileDirectory)WebSocketJSExecutorFactory.h" />
165
169
  <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Modules\ReactRootViewTagGenerator.cpp" />
166
170
  <ClCompile Include="$(ReactNativeWindowsDir)Microsoft.ReactNative\Utils\ImageUtils.cpp" />
@@ -307,4 +311,18 @@
307
311
  <SubType>Code</SubType>
308
312
  </ClCompile>
309
313
  </ItemGroup>
314
+ <ItemGroup>
315
+ <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.h" />
316
+ <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.inc" />
317
+ <ClCompile Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.cpp">
318
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
319
+ </ClCompile>
320
+ </ItemGroup>
321
+ <ItemGroup Condition="'$(UseV8)' == 'true'">
322
+ <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\V8Api.h" />
323
+ <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\V8Api.inc" />
324
+ <ClCompile Include="$(NodeApiJsiDir)src\ApiLoaders\V8Api.cpp">
325
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
326
+ </ClCompile>
327
+ </ItemGroup>
310
328
  </Project>