react-native-windows 0.71.35 → 0.71.37

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 (48) hide show
  1. package/Directory.Build.props +0 -5
  2. package/Microsoft.ReactNative/IReactDispatcher.cpp +0 -4
  3. package/Microsoft.ReactNative/IReactDispatcher.h +0 -1
  4. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +4 -2
  5. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +23 -36
  6. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +2 -0
  7. package/Microsoft.ReactNative/Views/DevMenu.cpp +3 -3
  8. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +2103 -0
  9. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +73 -0
  10. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +12 -43
  11. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +6 -17
  12. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +1 -1
  13. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -1
  14. package/PropertySheets/External/Microsoft.ReactNative.WinAppSDK.CSharpApp.targets +1 -1
  15. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  16. package/PropertySheets/JSEngine.props +4 -4
  17. package/PropertySheets/React.Cpp.props +0 -1
  18. package/PropertySheets/Warnings.props +0 -6
  19. package/ReactCommon/ReactCommon.vcxproj +1 -53
  20. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +0 -36
  21. package/Shared/DevSettings.h +3 -0
  22. package/Shared/DevSupportManager.cpp +9 -2
  23. package/Shared/DevSupportManager.h +6 -2
  24. package/Shared/HermesRuntimeHolder.cpp +84 -344
  25. package/Shared/HermesRuntimeHolder.h +21 -32
  26. package/Shared/HermesSamplingProfiler.cpp +14 -66
  27. package/Shared/HermesSamplingProfiler.h +3 -5
  28. package/Shared/HermesShim.cpp +118 -0
  29. package/Shared/HermesShim.h +21 -0
  30. package/Shared/InspectorPackagerConnection.cpp +108 -62
  31. package/Shared/InspectorPackagerConnection.h +21 -9
  32. package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +209 -0
  33. package/Shared/JSI/NapiJsiV8RuntimeHolder.h +44 -0
  34. package/Shared/JSI/RuntimeHolder.h +2 -2
  35. package/Shared/JSI/ScriptStore.h +20 -18
  36. package/Shared/OInstance.cpp +56 -41
  37. package/Shared/Shared.vcxitems +8 -19
  38. package/Shared/Shared.vcxitems.filters +30 -23
  39. package/Shared/V8JSIRuntimeHolder.cpp +70 -0
  40. package/Shared/V8JSIRuntimeHolder.h +53 -0
  41. package/package.json +2 -2
  42. package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
  43. package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +0 -16
  44. package/ReactCommon/cgmanifest.json +0 -15
  45. package/Shared/JSI/V8RuntimeHolder.cpp +0 -260
  46. package/Shared/JSI/V8RuntimeHolder.h +0 -37
  47. package/Shared/SafeLoadLibrary.cpp +0 -77
  48. package/Shared/SafeLoadLibrary.h +0 -19
@@ -43,6 +43,9 @@
43
43
  <ClCompile Include="$(MSBuildThisFileDirectory)CxxMessageQueue.cpp">
44
44
  <Filter>Source Files</Filter>
45
45
  </ClCompile>
46
+ <ClCompile Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.cpp">
47
+ <Filter>Source Files</Filter>
48
+ </ClCompile>
46
49
  <ClCompile Include="$(MSBuildThisFileDirectory)JSBigAbiString.cpp">
47
50
  <Filter>Source Files</Filter>
48
51
  </ClCompile>
@@ -55,6 +58,9 @@
55
58
  <ClCompile Include="$(MSBuildThisFileDirectory)Utils.cpp">
56
59
  <Filter>Source Files</Filter>
57
60
  </ClCompile>
61
+ <ClCompile Include="$(MSBuildThisFileDirectory)V8JSIRuntimeHolder.cpp">
62
+ <Filter>Source Files</Filter>
63
+ </ClCompile>
58
64
  <ClCompile Include="$(MSBuildThisFileDirectory)Modules\AsyncStorageModuleWin32.cpp">
59
65
  <Filter>Source Files\Modules</Filter>
60
66
  </ClCompile>
@@ -112,6 +118,15 @@
112
118
  <ClCompile Include="$(MSBuildThisFileDirectory)InspectorPackagerConnection.cpp">
113
119
  <Filter>Source Files</Filter>
114
120
  </ClCompile>
121
+ <ClCompile Include="$(MSBuildThisFileDirectory)JSI\NapiJsiV8RuntimeHolder.cpp">
122
+ <Filter>Source Files\JSI</Filter>
123
+ </ClCompile>
124
+ <ClCompile Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.cpp">
125
+ <Filter>Source Files</Filter>
126
+ </ClCompile>
127
+ <ClCompile Include="$(MSBuildThisFileDirectory)HermesShim.cpp">
128
+ <Filter>Source Files</Filter>
129
+ </ClCompile>
115
130
  <ClCompile Include="$(MSBuildThisFileDirectory)Modules\HttpModule.cpp">
116
131
  <Filter>Source Files\Modules</Filter>
117
132
  </ClCompile>
@@ -148,15 +163,6 @@
148
163
  <ClCompile Include="$(MSBuildThisFileDirectory)Networking\DefaultBlobResource.cpp">
149
164
  <Filter>Source Files\Networking</Filter>
150
165
  </ClCompile>
151
- <ClCompile Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.cpp">
152
- <Filter>Hermes</Filter>
153
- </ClCompile>
154
- <ClCompile Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.cpp">
155
- <Filter>Hermes</Filter>
156
- </ClCompile>
157
- <ClCompile Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.cpp" />
158
- <ClCompile Include="$(MSBuildThisFileDirectory)JSI\V8RuntimeHolder.cpp" />
159
- <ClCompile Include="$(MSBuildThisFileDirectory)SafeLoadLibrary.cpp" />
160
166
  </ItemGroup>
161
167
  <ItemGroup>
162
168
  <Filter Include="Source Files">
@@ -216,9 +222,6 @@
216
222
  <Filter Include="Source Files\Networking">
217
223
  <UniqueIdentifier>{71196e04-aca0-48d6-99e4-f418c957b50f}</UniqueIdentifier>
218
224
  </Filter>
219
- <Filter Include="Hermes">
220
- <UniqueIdentifier>{b32590e6-ae3d-4388-ab98-767345ce38c9}</UniqueIdentifier>
221
- </Filter>
222
225
  </ItemGroup>
223
226
  <ItemGroup>
224
227
  <ClInclude Include="$(MSBuildThisFileDirectory)AsyncStorage\StorageFileIO.h">
@@ -284,6 +287,9 @@
284
287
  <ClInclude Include="$(MSBuildThisFileDirectory)DevSettings.h">
285
288
  <Filter>Header Files</Filter>
286
289
  </ClInclude>
290
+ <ClInclude Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.h">
291
+ <Filter>Header Files</Filter>
292
+ </ClInclude>
287
293
  <ClInclude Include="$(MSBuildThisFileDirectory)IDevSupportManager.h">
288
294
  <Filter>Header Files</Filter>
289
295
  </ClInclude>
@@ -335,6 +341,9 @@
335
341
  <ClInclude Include="$(MSBuildThisFileDirectory)Utils.h">
336
342
  <Filter>Header Files</Filter>
337
343
  </ClInclude>
344
+ <ClInclude Include="$(MSBuildThisFileDirectory)V8JSIRuntimeHolder.h">
345
+ <Filter>Header Files</Filter>
346
+ </ClInclude>
338
347
  <ClInclude Include="$(MSBuildThisFileDirectory)WebSocketJSExecutorFactory.h">
339
348
  <Filter>Header Files</Filter>
340
349
  </ClInclude>
@@ -390,6 +399,15 @@
390
399
  <ClInclude Include="$(MSBuildThisFileDirectory)tracing\tracing.h">
391
400
  <Filter>Header Files\tracing</Filter>
392
401
  </ClInclude>
402
+ <ClInclude Include="$(MSBuildThisFileDirectory)JSI\NapiJsiV8RuntimeHolder.h">
403
+ <Filter>Header Files\JSI</Filter>
404
+ </ClInclude>
405
+ <ClInclude Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.h">
406
+ <Filter>Header Files</Filter>
407
+ </ClInclude>
408
+ <ClInclude Include="$(MSBuildThisFileDirectory)HermesShim.h">
409
+ <Filter>Header Files</Filter>
410
+ </ClInclude>
393
411
  <ClInclude Include="$(MSBuildThisFileDirectory)Modules\HttpModule.h">
394
412
  <Filter>Header Files\Modules</Filter>
395
413
  </ClInclude>
@@ -474,17 +492,6 @@
474
492
  <ClInclude Include="$(MSBuildThisFileDirectory)IBlobPersistor.h">
475
493
  <Filter>Header Files</Filter>
476
494
  </ClInclude>
477
- <ClInclude Include="$(MSBuildThisFileDirectory)HermesRuntimeHolder.h">
478
- <Filter>Hermes</Filter>
479
- </ClInclude>
480
- <ClInclude Include="$(MSBuildThisFileDirectory)HermesSamplingProfiler.h">
481
- <Filter>Hermes</Filter>
482
- </ClInclude>
483
- <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.h" />
484
- <ClInclude Include="$(NodeApiJsiDir)src\ApiLoaders\HermesApi.inc" />
485
- <ClInclude Include="$(MSBuildThisFileDirectory)..\Microsoft.ReactNative\JsiApi.h" />
486
- <ClInclude Include="$(MSBuildThisFileDirectory)JSI\V8RuntimeHolder.h" />
487
- <ClInclude Include="$(MSBuildThisFileDirectory)SafeLoadLibrary.h" />
488
495
  </ItemGroup>
489
496
  <ItemGroup>
490
497
  <None Include="$(MSBuildThisFileDirectory)tracing\rnw.wprp">
@@ -0,0 +1,70 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #include "pch.h"
5
+
6
+ #include <V8JsiRuntime.h>
7
+ #include "V8JSIRuntimeHolder.h"
8
+
9
+ #include <atomic>
10
+ #include <queue>
11
+
12
+ using namespace facebook;
13
+ using namespace facebook::react;
14
+
15
+ namespace facebook {
16
+ namespace react {
17
+
18
+ class TaskRunnerAdapter : public v8runtime::JSITaskRunner {
19
+ public:
20
+ TaskRunnerAdapter(std::shared_ptr<facebook::react::MessageQueueThread> jsQueue) : jsQueue_(std::move(jsQueue)) {}
21
+
22
+ void postTask(std::unique_ptr<v8runtime::JSITask> task) override {
23
+ std::shared_ptr<v8runtime::JSITask> shared_task(task.release());
24
+ jsQueue_->runOnQueue([shared_task2 = std::move(shared_task)]() { shared_task2->run(); });
25
+ }
26
+
27
+ private:
28
+ TaskRunnerAdapter(const TaskRunnerAdapter &) = delete;
29
+ TaskRunnerAdapter &operator=(const TaskRunnerAdapter &) = delete;
30
+
31
+ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue_;
32
+ };
33
+
34
+ facebook::react::JSIEngineOverride V8JSIRuntimeHolder::getRuntimeType() noexcept {
35
+ return facebook::react::JSIEngineOverride::V8;
36
+ }
37
+
38
+ std::shared_ptr<facebook::jsi::Runtime> V8JSIRuntimeHolder::getRuntime() noexcept {
39
+ std::call_once(once_flag_, [this]() { initRuntime(); });
40
+
41
+ if (!runtime_)
42
+ std::terminate();
43
+
44
+ // V8JsiRuntime is not thread safe as of now.
45
+ if (own_thread_id_ != std::this_thread::get_id())
46
+ std::terminate();
47
+
48
+ return runtime_;
49
+ }
50
+
51
+ void V8JSIRuntimeHolder::initRuntime() noexcept {
52
+ v8runtime::V8RuntimeArgs args{};
53
+
54
+ if (debuggerPort_ > 0)
55
+ args.inspectorPort = debuggerPort_;
56
+
57
+ args.flags.enableInspector = useDirectDebugger_;
58
+ args.flags.waitForDebugger = debuggerBreakOnNextLine_;
59
+ args.debuggerRuntimeName = debuggerRuntimeName_;
60
+
61
+ args.foreground_task_runner = std::make_shared<TaskRunnerAdapter>(jsQueue_);
62
+ args.preparedScriptStore = std::move(preparedScriptStore_);
63
+
64
+ runtime_ = v8runtime::makeV8Runtime(std::move(args));
65
+
66
+ own_thread_id_ = std::this_thread::get_id();
67
+ }
68
+
69
+ } // namespace react
70
+ } // namespace facebook
@@ -0,0 +1,53 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ #pragma once
5
+
6
+ #include <DevSettings.h>
7
+
8
+ #include <JSI/RuntimeHolder.h>
9
+ #include <JSI/ScriptStore.h>
10
+
11
+ #include <Logging.h>
12
+
13
+ namespace facebook {
14
+ namespace react {
15
+
16
+ class V8JSIRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
17
+ public:
18
+ std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override;
19
+ facebook::react::JSIEngineOverride getRuntimeType() noexcept override;
20
+
21
+ V8JSIRuntimeHolder(
22
+ std::shared_ptr<facebook::react::DevSettings> devSettings,
23
+ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
24
+ std::unique_ptr<facebook::jsi::ScriptStore> &&scriptStore,
25
+ std::unique_ptr<facebook::jsi::PreparedScriptStore> &&preparedScriptStore) noexcept
26
+ : useDirectDebugger_(devSettings->useDirectDebugger),
27
+ debuggerBreakOnNextLine_(devSettings->debuggerBreakOnNextLine),
28
+ debuggerPort_(devSettings->debuggerPort),
29
+ debuggerRuntimeName_(devSettings->debuggerRuntimeName),
30
+ jsQueue_(std::move(jsQueue)),
31
+ scriptStore_(std::move(scriptStore)),
32
+ preparedScriptStore_(std::move(preparedScriptStore)) {}
33
+
34
+ private:
35
+ void initRuntime() noexcept;
36
+
37
+ std::shared_ptr<facebook::jsi::Runtime> runtime_;
38
+ std::shared_ptr<facebook::react::MessageQueueThread> jsQueue_;
39
+
40
+ std::unique_ptr<facebook::jsi::ScriptStore> scriptStore_;
41
+ std::unique_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore_;
42
+
43
+ std::once_flag once_flag_;
44
+ std::thread::id own_thread_id_;
45
+
46
+ uint16_t debuggerPort_;
47
+ bool useDirectDebugger_;
48
+ bool debuggerBreakOnNextLine_;
49
+ std::string debuggerRuntimeName_;
50
+ };
51
+
52
+ } // namespace react
53
+ } // namespace facebook
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.71.35",
3
+ "version": "0.71.37",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "@react-native-community/cli": "10.2.4",
27
27
  "@react-native-community/cli-platform-android": "10.2.0",
28
28
  "@react-native-community/cli-platform-ios": "10.2.4",
29
- "@react-native-windows/cli": "0.71.17",
29
+ "@react-native-windows/cli": "0.71.18",
30
30
  "@react-native/assets": "1.0.0",
31
31
  "@react-native/normalize-color": "2.1.0",
32
32
  "@react-native/polyfills": "2.0.0",
@@ -12,7 +12,7 @@
12
12
 
13
13
  <!--
14
14
  Compiles Hermes-related code and sets it to the default JS engine.
15
- Requires the "Microsoft.JavaScript.Hermes" NuGet package.
15
+ Requires the "ReactNative.Hermes.Windows" NuGet package.
16
16
 
17
17
  See https://microsoft.github.io/react-native-windows/docs/0.64/hermes
18
18
  -->
@@ -1,16 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
-
4
- #include "ApiLoaders/NodeApi.h"
5
-
6
- namespace Microsoft::NodeApiJsi {
7
-
8
- LibHandle LibLoader::loadLib(const char * /*libName*/) {
9
- return reinterpret_cast<LibHandle>(0);
10
- }
11
-
12
- FuncPtr LibLoader::getFuncPtr(LibHandle /*libHandle*/, const char * /*funcName*/) {
13
- return reinterpret_cast<FuncPtr>(0);
14
- }
15
-
16
- } // namespace Microsoft::NodeApiJsi
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/component-detection-manifest.json",
3
- "Registrations": [
4
- {
5
- "Component": {
6
- "Type": "git",
7
- "Git": {
8
- "RepositoryUrl": "https://github.com/microsoft/node-api-jsi",
9
- "CommitHash": "53b897b03c1c7e57c3372acc6234447a44e150d6"
10
- }
11
- },
12
- "DevelopmentDependency": false
13
- }
14
- ]
15
- }
@@ -1,260 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
-
4
- #include "V8RuntimeHolder.h"
5
- #include <ApiLoaders/V8Api.h>
6
- #include <NodeApiJsiRuntime.h>
7
- #include <crash/verifyElseCrash.h>
8
- #include "SafeLoadLibrary.h"
9
-
10
- using namespace Microsoft::NodeApiJsi;
11
-
12
- #define CRASH_ON_ERROR(result) VerifyElseCrash(result == napi_ok);
13
-
14
- namespace Microsoft::ReactNative {
15
- namespace {
16
-
17
- class V8FuncResolver : public IFuncResolver {
18
- public:
19
- V8FuncResolver() : libHandle_(LoadLibraryAsPeerFirst(L"v8jsi.dll")) {}
20
-
21
- FuncPtr getFuncPtr(const char *funcName) override {
22
- return reinterpret_cast<FuncPtr>(GetProcAddress(libHandle_, funcName));
23
- }
24
-
25
- private:
26
- HMODULE libHandle_;
27
- };
28
-
29
- V8Api &initV8Api() noexcept {
30
- static V8FuncResolver funcResolver;
31
- static V8Api s_v8Api(&funcResolver);
32
- V8Api::setCurrent(&s_v8Api);
33
- return s_v8Api;
34
- }
35
-
36
- V8Api &getV8Api() noexcept {
37
- static V8Api &s_v8Api = initV8Api();
38
- return s_v8Api;
39
- }
40
-
41
- class V8Task {
42
- public:
43
- V8Task(void *taskData, jsr_task_run_cb taskRunCallback, jsr_data_delete_cb taskDataDeleteCallback, void *deleterData)
44
- : taskData_(taskData),
45
- taskRunCallback_(taskRunCallback),
46
- taskDataDeleteCallback_(taskDataDeleteCallback),
47
- deleterData_(deleterData) {}
48
-
49
- V8Task(const V8Task &other) = delete;
50
- V8Task &operator=(const V8Task &other) = delete;
51
-
52
- ~V8Task() {
53
- if (taskDataDeleteCallback_ != nullptr) {
54
- taskDataDeleteCallback_(taskData_, deleterData_);
55
- }
56
- }
57
-
58
- void Run() const {
59
- if (taskRunCallback_ != nullptr) {
60
- taskRunCallback_(taskData_);
61
- }
62
- }
63
-
64
- private:
65
- void *taskData_;
66
- jsr_task_run_cb taskRunCallback_;
67
- jsr_data_delete_cb taskDataDeleteCallback_;
68
- void *deleterData_;
69
- };
70
-
71
- class V8TaskRunner {
72
- public:
73
- static void Create(jsr_config config, std::shared_ptr<facebook::react::MessageQueueThread> queue) {
74
- CRASH_ON_ERROR(
75
- getV8Api().jsr_config_set_task_runner(config, new V8TaskRunner(std::move(queue)), &PostTask, &Delete, nullptr));
76
- }
77
-
78
- private:
79
- V8TaskRunner(std::shared_ptr<facebook::react::MessageQueueThread> queue) : queue_(std::move(queue)) {}
80
-
81
- static void NAPI_CDECL PostTask(
82
- void *taskRunnerData,
83
- void *taskData,
84
- jsr_task_run_cb taskRunCallback,
85
- jsr_data_delete_cb taskDataDeleteCallback,
86
- void *deleterData) {
87
- auto task = std::make_shared<V8Task>(taskData, taskRunCallback, taskDataDeleteCallback, deleterData);
88
- reinterpret_cast<V8TaskRunner *>(taskRunnerData)->queue_->runOnQueue([task = std::move(task)] { task->Run(); });
89
- }
90
-
91
- static void NAPI_CDECL Delete(void *taskRunner, void * /*deleterData*/) {
92
- delete reinterpret_cast<V8TaskRunner *>(taskRunner);
93
- }
94
-
95
- private:
96
- std::shared_ptr<facebook::react::MessageQueueThread> queue_;
97
- };
98
-
99
- struct V8JsiBuffer : facebook::jsi::Buffer {
100
- static std::shared_ptr<const facebook::jsi::Buffer>
101
- Create(const uint8_t *buffer, size_t bufferSize, jsr_data_delete_cb bufferDeleteCallback, void *deleterData) {
102
- return std::shared_ptr<const facebook::jsi::Buffer>(
103
- new V8JsiBuffer(buffer, bufferSize, bufferDeleteCallback, deleterData));
104
- }
105
-
106
- V8JsiBuffer(
107
- const uint8_t *buffer,
108
- size_t bufferSize,
109
- jsr_data_delete_cb bufferDeleteCallback,
110
- void *deleterData) noexcept
111
- : buffer_(buffer),
112
- bufferSize_(bufferSize),
113
- bufferDeleteCallback_(bufferDeleteCallback),
114
- deleterData_(deleterData) {}
115
-
116
- ~V8JsiBuffer() override {
117
- if (bufferDeleteCallback_) {
118
- bufferDeleteCallback_(const_cast<uint8_t *>(buffer_), deleterData_);
119
- }
120
- }
121
-
122
- const uint8_t *data() const override {
123
- return buffer_;
124
- }
125
-
126
- size_t size() const override {
127
- return bufferSize_;
128
- }
129
-
130
- private:
131
- const uint8_t *buffer_;
132
- size_t bufferSize_;
133
- jsr_data_delete_cb bufferDeleteCallback_;
134
- void *deleterData_;
135
- };
136
-
137
- class V8ScriptCache {
138
- public:
139
- static void Create(jsr_config config, std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore) {
140
- CRASH_ON_ERROR(getV8Api().jsr_config_set_script_cache(
141
- config, new V8ScriptCache(std::move(scriptStore)), &LoadScript, &StoreScript, &Delete, nullptr));
142
- }
143
-
144
- private:
145
- V8ScriptCache(std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore)
146
- : scriptStore_(std::move(scriptStore)) {}
147
-
148
- static void NAPI_CDECL LoadScript(
149
- void *scriptCache,
150
- const char *sourceUrl,
151
- uint64_t sourceHash,
152
- const char *runtimeName,
153
- uint64_t runtimeVersion,
154
- const char *cacheTag,
155
- const uint8_t **buffer,
156
- size_t *bufferSize,
157
- jsr_data_delete_cb *bufferDeleteCallback,
158
- void **deleterData) {
159
- auto &scriptStore = reinterpret_cast<V8ScriptCache *>(scriptCache)->scriptStore_;
160
- std::shared_ptr<const facebook::jsi::Buffer> preparedScript = scriptStore->tryGetPreparedScript(
161
- facebook::jsi::ScriptSignature{sourceUrl, sourceHash},
162
- facebook::jsi::JSRuntimeSignature{runtimeName, runtimeVersion},
163
- cacheTag);
164
- if (preparedScript) {
165
- *buffer = preparedScript->data();
166
- *bufferSize = preparedScript->size();
167
- *bufferDeleteCallback = [](void * /*data*/, void *deleterData) noexcept {
168
- delete reinterpret_cast<std::shared_ptr<const facebook::jsi::Buffer> *>(deleterData);
169
- };
170
- *deleterData = new std::shared_ptr<const facebook::jsi::Buffer>(std::move(preparedScript));
171
- } else {
172
- *buffer = nullptr;
173
- *bufferSize = 0;
174
- *bufferDeleteCallback = nullptr;
175
- *deleterData = nullptr;
176
- }
177
- }
178
-
179
- static void NAPI_CDECL StoreScript(
180
- void *scriptCache,
181
- const char *sourceUrl,
182
- uint64_t sourceHash,
183
- const char *runtimeName,
184
- uint64_t runtimeVersion,
185
- const char *cacheTag,
186
- const uint8_t *buffer,
187
- size_t bufferSize,
188
- jsr_data_delete_cb bufferDeleteCallback,
189
- void *deleterData) {
190
- auto &scriptStore = reinterpret_cast<V8ScriptCache *>(scriptCache)->scriptStore_;
191
- scriptStore->persistPreparedScript(
192
- V8JsiBuffer::Create(buffer, bufferSize, bufferDeleteCallback, deleterData),
193
- facebook::jsi::ScriptSignature{sourceUrl, sourceHash},
194
- facebook::jsi::JSRuntimeSignature{runtimeName, runtimeVersion},
195
- cacheTag);
196
- }
197
-
198
- static void NAPI_CDECL Delete(void *scriptCache, void * /*deleterData*/) {
199
- delete reinterpret_cast<V8ScriptCache *>(scriptCache);
200
- }
201
-
202
- private:
203
- std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore_;
204
- };
205
-
206
- } // namespace
207
-
208
- V8RuntimeHolder::V8RuntimeHolder(
209
- std::shared_ptr<facebook::react::DevSettings> devSettings,
210
- std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
211
- std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore,
212
- bool enableMultiThreadingSupport) noexcept
213
- : m_weakDevSettings(devSettings),
214
- m_jsQueue(std::move(jsQueue)),
215
- m_preparedScriptStore(std::move(preparedScriptStore)),
216
- m_enableMultiThreadingSupport(enableMultiThreadingSupport) {}
217
-
218
- void V8RuntimeHolder::initRuntime() noexcept {
219
- std::shared_ptr<facebook::react::DevSettings> devSettings = m_weakDevSettings.lock();
220
- VerifyElseCrash(devSettings);
221
-
222
- V8Api &api = getV8Api();
223
- V8Api::setCurrent(&api);
224
- jsr_config config{};
225
- CRASH_ON_ERROR(api.jsr_create_config(&config));
226
- CRASH_ON_ERROR(api.jsr_config_enable_inspector(config, devSettings->useDirectDebugger));
227
- CRASH_ON_ERROR(api.jsr_config_set_inspector_runtime_name(config, devSettings->debuggerRuntimeName.c_str()));
228
- CRASH_ON_ERROR(api.jsr_config_set_inspector_port(config, devSettings->debuggerPort));
229
- CRASH_ON_ERROR(api.jsr_config_set_inspector_break_on_start(config, devSettings->debuggerBreakOnNextLine));
230
- CRASH_ON_ERROR(api.v8_config_enable_multithreading(config, m_enableMultiThreadingSupport));
231
-
232
- if (m_jsQueue) {
233
- V8TaskRunner::Create(config, m_jsQueue);
234
- }
235
- if (m_preparedScriptStore) {
236
- V8ScriptCache::Create(config, m_preparedScriptStore);
237
- }
238
- jsr_runtime runtime{};
239
- CRASH_ON_ERROR(api.jsr_create_runtime(config, &runtime));
240
- CRASH_ON_ERROR(api.jsr_delete_config(config));
241
-
242
- napi_env env{};
243
- CRASH_ON_ERROR(api.jsr_runtime_get_node_api_env(runtime, &env));
244
-
245
- m_jsiRuntime =
246
- makeNodeApiJsiRuntime(env, &api, [runtime]() { CRASH_ON_ERROR(V8Api::current()->jsr_delete_runtime(runtime)); });
247
- m_ownThreadId = std::this_thread::get_id();
248
- }
249
-
250
- facebook::react::JSIEngineOverride V8RuntimeHolder::getRuntimeType() noexcept {
251
- return facebook::react::JSIEngineOverride::V8NodeApi;
252
- }
253
-
254
- std::shared_ptr<facebook::jsi::Runtime> V8RuntimeHolder::getRuntime() noexcept {
255
- std::call_once(m_onceFlag, [this]() { initRuntime(); });
256
- VerifyElseCrash(m_jsiRuntime);
257
- return m_jsiRuntime;
258
- }
259
-
260
- } // namespace Microsoft::ReactNative
@@ -1,37 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
-
4
- #pragma once
5
-
6
- #include "RuntimeHolder.h"
7
- #include "ScriptStore.h"
8
-
9
- #include <cxxreact/MessageQueueThread.h>
10
-
11
- namespace Microsoft::ReactNative {
12
-
13
- class V8RuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
14
- public: // RuntimeHolderLazyInit implementation.
15
- std::shared_ptr<facebook::jsi::Runtime> getRuntime() noexcept override;
16
- facebook::react::JSIEngineOverride getRuntimeType() noexcept override;
17
-
18
- V8RuntimeHolder(
19
- std::shared_ptr<facebook::react::DevSettings> devSettings,
20
- std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
21
- std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore,
22
- bool enableMultiThreadingSupport) noexcept;
23
-
24
- private:
25
- void initRuntime() noexcept;
26
-
27
- private:
28
- std::shared_ptr<facebook::jsi::Runtime> m_jsiRuntime;
29
- std::once_flag m_onceFlag{};
30
- std::thread::id m_ownThreadId{};
31
- std::weak_ptr<facebook::react::DevSettings> m_weakDevSettings;
32
- std::shared_ptr<facebook::react::MessageQueueThread> m_jsQueue;
33
- std::shared_ptr<facebook::jsi::PreparedScriptStore> m_preparedScriptStore;
34
- bool m_enableMultiThreadingSupport;
35
- };
36
-
37
- } // namespace Microsoft::ReactNative
@@ -1,77 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
-
4
- #include "SafeLoadLibrary.h"
5
- #include "PathCch.h"
6
-
7
- EXTERN_C IMAGE_DOS_HEADER __ImageBase;
8
-
9
- namespace Microsoft::ReactNative {
10
-
11
- // Unsafe calls to LoadLibrary/LoadLibraryEx.
12
- // The default behavior of LoadLibrary, or LoadLibraryEx without flags, is to try and find the dependency by iterating
13
- // through a search order. This search order contains the current working directory. In the classic attack, a malicious
14
- // DLL is dropped in the likely - controllable current working directory. The malicious DLL has the same name as a
15
- // missing dependency or dependency that is not in the same directory as the executable. When the call to LoadLibrary
16
- // is reached, the malicious DLL is loaded preferentially, and code execution occurs.
17
- //
18
- // The SafeLoadLibrary is the preferred ways to manually load dependencies.
19
- // The API does not search the current working directory when resolving dependencies.
20
- // The implementation is "borrowed" from Office MsoSafeLoadLibrary.
21
-
22
- /**
23
- List of new flags that control where to search for DLLs. Requires KB2533623.
24
- */
25
- const DWORD SafeLoadLibraryFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
26
- LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS;
27
-
28
- HMODULE SafeLoadLibrary(const wchar_t *fileName, DWORD dwFlags) noexcept {
29
- // When calling LoadLibrary, OR in LOAD_LIBRARY_SEARCH_DEFAULT_DIRS which enables all of the
30
- // safe behaviors. Note that this flag is not compatible with LOAD_WITH_ALTERED_SEARCH_PATH.
31
- #pragma push_macro("LoadLibraryExW")
32
- #undef LoadLibraryExW
33
- HMODULE module =
34
- ::LoadLibraryExW(fileName, 0, (dwFlags | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) & ~LOAD_WITH_ALTERED_SEARCH_PATH);
35
- if (module == nullptr && GetLastError() == ERROR_INVALID_PARAMETER) {
36
- // Could have failed with actual bad parameters or an unpatched OS without KB2533623.
37
- if (::GetProcAddress(::GetModuleHandleW(L"kernel32.dll"), "AddDllDirectory") == nullptr) {
38
- // Unpatched OS, remove all new flags.
39
- module = ::LoadLibraryExW(fileName, 0, dwFlags & ~SafeLoadLibraryFlags);
40
- }
41
- }
42
- #pragma pop_macro("LoadLibraryExW")
43
-
44
- return module;
45
- }
46
-
47
- // Gets the full file name in the same directory as the current DLL.
48
- // It returns nullptr if we cannot create the full file name.
49
- wchar_t *GePeerFullFileName(const wchar_t *fileName, wchar_t *buffer, size_t bufferSize) {
50
- size_t nameSize =
51
- ::GetModuleFileNameW(reinterpret_cast<HINSTANCE>(&__ImageBase), buffer, static_cast<DWORD>(bufferSize));
52
- if (nameSize == 0 || nameSize == bufferSize)
53
- return nullptr;
54
-
55
- if (::PathCchRemoveFileSpec(buffer, bufferSize) != S_OK)
56
- return nullptr;
57
- if (::PathCchCombineEx(buffer, bufferSize, buffer, fileName, PATHCCH_ALLOW_LONG_PATHS) != S_OK)
58
- return nullptr;
59
-
60
- return buffer;
61
- }
62
-
63
- HMODULE LoadLibraryAsPeerFirst(const wchar_t *fileName) noexcept {
64
- HMODULE lib{nullptr};
65
- constexpr size_t nameBufferSize = 4096;
66
- wchar_t nameBuffer[nameBufferSize] = L"";
67
-
68
- if (wchar_t *fullFileName = GePeerFullFileName(fileName, nameBuffer, nameBufferSize))
69
- lib = SafeLoadLibrary(fullFileName);
70
-
71
- if (!lib)
72
- lib = SafeLoadLibrary(fileName);
73
-
74
- return lib;
75
- }
76
-
77
- } // namespace Microsoft::ReactNative