react-native-windows 0.72.0-preview.7 → 0.72.0-preview.9
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.
- package/Directory.Build.props +24 -19
- package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +0 -1
- package/Libraries/Components/TextInput/TextInput.d.ts +121 -86
- package/Libraries/Components/TextInput/TextInput.flow.js +121 -135
- package/Libraries/Components/TextInput/TextInput.js +126 -155
- package/Libraries/Components/TextInput/TextInput.windows.js +126 -155
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/PermissionsAndroid/PermissionsAndroid.js +0 -2
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -13
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +2 -4
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +2 -57
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +22 -17
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +0 -2
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +16 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +41 -12
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +17 -6
- package/Microsoft.ReactNative.Managed/packages.lock.json +6 -6
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CSharpApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppApp.targets +1 -1
- package/PropertySheets/External/Microsoft.ReactNative.WinAppSDK.CSharpApp.targets +1 -1
- package/PropertySheets/Generated/PackageVersion.g.props +2 -2
- package/PropertySheets/JSEngine.props +4 -4
- package/PropertySheets/Warnings.props +6 -0
- package/ReactCommon/ReactCommon.vcxproj +53 -1
- package/ReactCommon/cgmanifest.json +15 -0
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +36 -0
- package/Shared/DevSupportManager.cpp +2 -9
- package/Shared/DevSupportManager.h +2 -6
- package/Shared/HermesRuntimeHolder.cpp +318 -81
- package/Shared/HermesRuntimeHolder.h +15 -19
- package/Shared/HermesSamplingProfiler.cpp +5 -6
- package/Shared/InspectorPackagerConnection.cpp +62 -108
- package/Shared/InspectorPackagerConnection.h +9 -21
- package/Shared/JSI/ScriptStore.h +18 -20
- package/Shared/JSI/V8RuntimeHolder.cpp +262 -0
- package/Shared/JSI/V8RuntimeHolder.h +37 -0
- package/Shared/OInstance.cpp +16 -36
- package/Shared/SafeLoadLibrary.cpp +41 -0
- package/Shared/SafeLoadLibrary.h +15 -0
- package/Shared/Shared.vcxitems +21 -10
- package/Shared/Shared.vcxitems.filters +23 -30
- package/codegen/rnwcoreJSI.h +2 -2
- package/package.json +15 -14
- package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +0 -2105
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +0 -73
- package/Shared/HermesShim.cpp +0 -122
- package/Shared/HermesShim.h +0 -41
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +0 -209
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +0 -46
- package/Shared/V8JSIRuntimeHolder.cpp +0 -71
- package/Shared/V8JSIRuntimeHolder.h +0 -58
|
@@ -5,28 +5,24 @@
|
|
|
5
5
|
|
|
6
6
|
#include "HermesRuntimeHolder.h"
|
|
7
7
|
|
|
8
|
+
#include <ApiLoaders/HermesApi.h>
|
|
8
9
|
#include <JSI/decorator.h>
|
|
10
|
+
#include <NodeApiJsiRuntime.h>
|
|
9
11
|
#include <crash/verifyElseCrash.h>
|
|
10
|
-
#include <cxxreact/MessageQueueThread.h>
|
|
11
12
|
#include <cxxreact/SystraceSection.h>
|
|
12
|
-
#include <
|
|
13
|
-
#include "HermesShim.h"
|
|
14
|
-
|
|
15
|
-
#if defined(HERMES_ENABLE_DEBUGGER)
|
|
16
|
-
#include <hermes/inspector/chrome/Registration.h>
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
|
-
#include <memory>
|
|
13
|
+
#include <jsinspector/InspectorInterfaces.h>
|
|
20
14
|
#include <mutex>
|
|
15
|
+
#include "SafeLoadLibrary.h"
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
using namespace Microsoft::ReactNative;
|
|
17
|
+
#define CRASH_ON_ERROR(result) VerifyElseCrash(result == napi_ok);
|
|
24
18
|
|
|
25
19
|
namespace React {
|
|
26
20
|
using namespace winrt::Microsoft::ReactNative;
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
namespace
|
|
23
|
+
using namespace Microsoft::NodeApiJsi;
|
|
24
|
+
|
|
25
|
+
namespace Microsoft::ReactNative {
|
|
30
26
|
|
|
31
27
|
React::ReactPropertyId<React::ReactNonAbiValue<std::shared_ptr<HermesRuntimeHolder>>>
|
|
32
28
|
HermesRuntimeHolderProperty() noexcept {
|
|
@@ -37,104 +33,333 @@ HermesRuntimeHolderProperty() noexcept {
|
|
|
37
33
|
|
|
38
34
|
namespace {
|
|
39
35
|
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
int32_t NAPI_CDECL addInspectorPage(const char *title, const char *vm, void *connectFunc) noexcept;
|
|
37
|
+
void NAPI_CDECL removeInspectorPage(int32_t pageId) noexcept;
|
|
38
|
+
|
|
39
|
+
class HermesFuncResolver : public IFuncResolver {
|
|
42
40
|
public:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
HermesFuncResolver() : libHandle_(SafeLoadLibrary(L"hermes.dll")) {}
|
|
42
|
+
|
|
43
|
+
FuncPtr getFuncPtr(const char *funcName) override {
|
|
44
|
+
return reinterpret_cast<FuncPtr>(GetProcAddress(libHandle_, funcName));
|
|
45
|
+
}
|
|
48
46
|
|
|
49
|
-
|
|
47
|
+
private:
|
|
48
|
+
HMODULE libHandle_;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
HermesApi &initHermesApi() noexcept {
|
|
52
|
+
static HermesFuncResolver funcResolver;
|
|
53
|
+
static HermesApi s_hermesApi(&funcResolver);
|
|
54
|
+
HermesApi::setCurrent(&s_hermesApi);
|
|
55
|
+
CRASH_ON_ERROR(s_hermesApi.hermes_set_inspector(&addInspectorPage, &removeInspectorPage));
|
|
56
|
+
return s_hermesApi;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
HermesApi &getHermesApi() noexcept {
|
|
60
|
+
static HermesApi &s_hermesApi = initHermesApi();
|
|
61
|
+
return s_hermesApi;
|
|
62
|
+
}
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
class HermesTask {
|
|
65
|
+
public:
|
|
66
|
+
HermesTask(
|
|
67
|
+
void *taskData,
|
|
68
|
+
jsr_task_run_cb taskRunCallback,
|
|
69
|
+
jsr_data_delete_cb taskDataDeleteCallback,
|
|
70
|
+
void *deleterData)
|
|
71
|
+
: taskData_(taskData),
|
|
72
|
+
taskRunCallback_(taskRunCallback),
|
|
73
|
+
taskDataDeleteCallback_(taskDataDeleteCallback),
|
|
74
|
+
deleterData_(deleterData) {}
|
|
75
|
+
|
|
76
|
+
HermesTask(const HermesTask &other) = delete;
|
|
77
|
+
HermesTask &operator=(const HermesTask &other) = delete;
|
|
78
|
+
|
|
79
|
+
~HermesTask() {
|
|
80
|
+
if (taskDataDeleteCallback_ != nullptr) {
|
|
81
|
+
taskDataDeleteCallback_(taskData_, deleterData_);
|
|
82
|
+
}
|
|
53
83
|
}
|
|
54
84
|
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
void Run() const {
|
|
86
|
+
if (taskRunCallback_ != nullptr) {
|
|
87
|
+
taskRunCallback_(taskData_);
|
|
88
|
+
}
|
|
57
89
|
}
|
|
58
90
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
private:
|
|
92
|
+
void *taskData_;
|
|
93
|
+
jsr_task_run_cb taskRunCallback_;
|
|
94
|
+
jsr_data_delete_cb taskDataDeleteCallback_;
|
|
95
|
+
void *deleterData_;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
class HermesTaskRunner {
|
|
99
|
+
public:
|
|
100
|
+
static void Create(jsr_config config, std::shared_ptr<facebook::react::MessageQueueThread> queue) {
|
|
101
|
+
CRASH_ON_ERROR(getHermesApi().jsr_config_set_task_runner(
|
|
102
|
+
config, new HermesTaskRunner(std::move(queue)), &PostTask, &Delete, nullptr));
|
|
66
103
|
}
|
|
67
104
|
|
|
68
105
|
private:
|
|
69
|
-
std::shared_ptr<
|
|
70
|
-
|
|
106
|
+
HermesTaskRunner(std::shared_ptr<facebook::react::MessageQueueThread> queue) : queue_(std::move(queue)) {}
|
|
107
|
+
|
|
108
|
+
static void NAPI_CDECL PostTask(
|
|
109
|
+
void *taskRunnerData,
|
|
110
|
+
void *taskData,
|
|
111
|
+
jsr_task_run_cb taskRunCallback,
|
|
112
|
+
jsr_data_delete_cb taskDataDeleteCallback,
|
|
113
|
+
void *deleterData) {
|
|
114
|
+
auto task = std::make_shared<HermesTask>(taskData, taskRunCallback, taskDataDeleteCallback, deleterData);
|
|
115
|
+
reinterpret_cast<HermesTaskRunner *>(taskRunnerData)->queue_->runOnQueue([task = std::move(task)] { task->Run(); });
|
|
116
|
+
}
|
|
71
117
|
|
|
72
|
-
|
|
118
|
+
static void NAPI_CDECL Delete(void *taskRunner, void * /*deleterData*/) {
|
|
119
|
+
delete reinterpret_cast<HermesTaskRunner *>(taskRunner);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private:
|
|
123
|
+
std::shared_ptr<facebook::react::MessageQueueThread> queue_;
|
|
73
124
|
};
|
|
74
|
-
#endif
|
|
75
125
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
|
|
81
|
-
return HermesShim::make();
|
|
126
|
+
struct HermesJsiBuffer : facebook::jsi::Buffer {
|
|
127
|
+
static std::shared_ptr<const facebook::jsi::Buffer>
|
|
128
|
+
Create(const uint8_t *buffer, size_t bufferSize, jsr_data_delete_cb bufferDeleteCallback, void *deleterData) {
|
|
129
|
+
return std::shared_ptr<const facebook::jsi::Buffer>(
|
|
130
|
+
new HermesJsiBuffer(buffer, bufferSize, bufferDeleteCallback, deleterData));
|
|
82
131
|
}
|
|
83
|
-
}
|
|
84
132
|
|
|
85
|
-
|
|
133
|
+
HermesJsiBuffer(
|
|
134
|
+
const uint8_t *buffer,
|
|
135
|
+
size_t bufferSize,
|
|
136
|
+
jsr_data_delete_cb bufferDeleteCallback,
|
|
137
|
+
void *deleterData) noexcept
|
|
138
|
+
: buffer_(buffer),
|
|
139
|
+
bufferSize_(bufferSize),
|
|
140
|
+
bufferDeleteCallback_(bufferDeleteCallback),
|
|
141
|
+
deleterData_(deleterData) {}
|
|
142
|
+
|
|
143
|
+
~HermesJsiBuffer() override {
|
|
144
|
+
if (bufferDeleteCallback_) {
|
|
145
|
+
bufferDeleteCallback_(const_cast<uint8_t *>(buffer_), deleterData_);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
86
148
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
149
|
+
const uint8_t *data() const override {
|
|
150
|
+
return buffer_;
|
|
151
|
+
}
|
|
90
152
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (auto devSettings = m_weakDevSettings.lock(); devSettings && devSettings->useDirectDebugger) {
|
|
94
|
-
facebook::hermes::inspector::chrome::disableDebugging(*m_hermesRuntime);
|
|
153
|
+
size_t size() const override {
|
|
154
|
+
return bufferSize_;
|
|
95
155
|
}
|
|
96
|
-
#endif
|
|
97
|
-
}
|
|
98
156
|
|
|
99
|
-
|
|
100
|
-
|
|
157
|
+
private:
|
|
158
|
+
const uint8_t *buffer_;
|
|
159
|
+
size_t bufferSize_;
|
|
160
|
+
jsr_data_delete_cb bufferDeleteCallback_;
|
|
161
|
+
void *deleterData_;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
class HermesScriptCache {
|
|
165
|
+
public:
|
|
166
|
+
static void Create(jsr_config config, std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore) {
|
|
167
|
+
CRASH_ON_ERROR(getHermesApi().jsr_config_set_script_cache(
|
|
168
|
+
config, new HermesScriptCache(std::move(scriptStore)), &LoadScript, &StoreScript, &Delete, nullptr));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private:
|
|
172
|
+
HermesScriptCache(std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore)
|
|
173
|
+
: scriptStore_(std::move(scriptStore)) {}
|
|
174
|
+
|
|
175
|
+
static void NAPI_CDECL LoadScript(
|
|
176
|
+
void *scriptCache,
|
|
177
|
+
const char *sourceUrl,
|
|
178
|
+
uint64_t sourceHash,
|
|
179
|
+
const char *runtimeName,
|
|
180
|
+
uint64_t runtimeVersion,
|
|
181
|
+
const char *cacheTag,
|
|
182
|
+
const uint8_t **buffer,
|
|
183
|
+
size_t *bufferSize,
|
|
184
|
+
jsr_data_delete_cb *bufferDeleteCallback,
|
|
185
|
+
void **deleterData) {
|
|
186
|
+
auto &scriptStore = reinterpret_cast<HermesScriptCache *>(scriptCache)->scriptStore_;
|
|
187
|
+
std::shared_ptr<const facebook::jsi::Buffer> preparedScript = scriptStore->tryGetPreparedScript(
|
|
188
|
+
facebook::jsi::ScriptSignature{sourceUrl, sourceHash},
|
|
189
|
+
facebook::jsi::JSRuntimeSignature{runtimeName, runtimeVersion},
|
|
190
|
+
cacheTag);
|
|
191
|
+
if (preparedScript) {
|
|
192
|
+
*buffer = preparedScript->data();
|
|
193
|
+
*bufferSize = preparedScript->size();
|
|
194
|
+
*bufferDeleteCallback = [](void * /*data*/, void *deleterData) noexcept {
|
|
195
|
+
delete reinterpret_cast<std::shared_ptr<const facebook::jsi::Buffer> *>(deleterData);
|
|
196
|
+
};
|
|
197
|
+
*deleterData = new std::shared_ptr<const facebook::jsi::Buffer>(std::move(preparedScript));
|
|
198
|
+
} else {
|
|
199
|
+
*buffer = nullptr;
|
|
200
|
+
*bufferSize = 0;
|
|
201
|
+
*bufferDeleteCallback = nullptr;
|
|
202
|
+
*deleterData = nullptr;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static void NAPI_CDECL StoreScript(
|
|
207
|
+
void *scriptCache,
|
|
208
|
+
const char *sourceUrl,
|
|
209
|
+
uint64_t sourceHash,
|
|
210
|
+
const char *runtimeName,
|
|
211
|
+
uint64_t runtimeVersion,
|
|
212
|
+
const char *cacheTag,
|
|
213
|
+
const uint8_t *buffer,
|
|
214
|
+
size_t bufferSize,
|
|
215
|
+
jsr_data_delete_cb bufferDeleteCallback,
|
|
216
|
+
void *deleterData) {
|
|
217
|
+
auto &scriptStore = reinterpret_cast<HermesScriptCache *>(scriptCache)->scriptStore_;
|
|
218
|
+
scriptStore->persistPreparedScript(
|
|
219
|
+
HermesJsiBuffer::Create(buffer, bufferSize, bufferDeleteCallback, deleterData),
|
|
220
|
+
facebook::jsi::ScriptSignature{sourceUrl, sourceHash},
|
|
221
|
+
facebook::jsi::JSRuntimeSignature{runtimeName, runtimeVersion},
|
|
222
|
+
cacheTag);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static void NAPI_CDECL Delete(void *scriptCache, void * /*deleterData*/) {
|
|
226
|
+
delete reinterpret_cast<HermesScriptCache *>(scriptCache);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private:
|
|
230
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore_;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
class HermesLocalConnection : public facebook::react::ILocalConnection {
|
|
234
|
+
public:
|
|
235
|
+
HermesLocalConnection(
|
|
236
|
+
std::unique_ptr<facebook::react::IRemoteConnection> remoteConneciton,
|
|
237
|
+
void *connectFunc) noexcept {
|
|
238
|
+
CRASH_ON_ERROR(getHermesApi().hermes_create_local_connection(
|
|
239
|
+
connectFunc,
|
|
240
|
+
reinterpret_cast<hermes_remote_connection>(remoteConneciton.release()),
|
|
241
|
+
&OnRemoteConnectionSendMessage,
|
|
242
|
+
&OnRemoteConnectionDisconnect,
|
|
243
|
+
&OnRemoteConnectionDelete,
|
|
244
|
+
nullptr,
|
|
245
|
+
&localConnection_));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
~HermesLocalConnection() override {
|
|
249
|
+
CRASH_ON_ERROR(getHermesApi().hermes_delete_local_connection(localConnection_));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
void sendMessage(std::string message) {
|
|
253
|
+
CRASH_ON_ERROR(getHermesApi().hermes_local_connection_send_message(localConnection_, message.c_str()));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
void disconnect() {
|
|
257
|
+
CRASH_ON_ERROR(getHermesApi().hermes_local_connection_disconnect(localConnection_));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private:
|
|
261
|
+
static void NAPI_CDECL OnRemoteConnectionSendMessage(hermes_remote_connection remoteConnection, const char *message) {
|
|
262
|
+
reinterpret_cast<facebook::react::IRemoteConnection *>(remoteConnection)->onMessage(message);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static void NAPI_CDECL OnRemoteConnectionDisconnect(hermes_remote_connection remoteConnection) {
|
|
266
|
+
reinterpret_cast<facebook::react::IRemoteConnection *>(remoteConnection)->onDisconnect();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
static void NAPI_CDECL OnRemoteConnectionDelete(void *remoteConnection, void * /*deleterData*/) {
|
|
270
|
+
delete reinterpret_cast<facebook::react::IRemoteConnection *>(remoteConnection);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private:
|
|
274
|
+
hermes_local_connection localConnection_{};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
int32_t NAPI_CDECL addInspectorPage(const char *title, const char *vm, void *connectFunc) noexcept {
|
|
278
|
+
return facebook::react::getInspectorInstance().addPage(
|
|
279
|
+
title,
|
|
280
|
+
vm,
|
|
281
|
+
[connectFunc,
|
|
282
|
+
hermesApi = HermesApi::current()](std::unique_ptr<facebook::react::IRemoteConnection> remoteConneciton) {
|
|
283
|
+
HermesApi::Scope apiScope(hermesApi);
|
|
284
|
+
return std::make_unique<HermesLocalConnection>(std::move(remoteConneciton), connectFunc);
|
|
285
|
+
});
|
|
101
286
|
}
|
|
102
287
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
VerifyElseCrash(m_hermesRuntime);
|
|
106
|
-
VerifyElseCrashSz(m_ownThreadId == std::this_thread::get_id(), "Must be accessed from JS thread.");
|
|
107
|
-
return m_hermesRuntime;
|
|
288
|
+
void NAPI_CDECL removeInspectorPage(int32_t pageId) noexcept {
|
|
289
|
+
facebook::react::getInspectorInstance().removePage(pageId);
|
|
108
290
|
}
|
|
109
291
|
|
|
292
|
+
} // namespace
|
|
293
|
+
|
|
110
294
|
HermesRuntimeHolder::HermesRuntimeHolder(
|
|
111
295
|
std::shared_ptr<facebook::react::DevSettings> devSettings,
|
|
112
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue
|
|
113
|
-
|
|
296
|
+
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
|
|
297
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore) noexcept
|
|
298
|
+
: m_weakDevSettings(devSettings),
|
|
299
|
+
m_jsQueue(std::move(jsQueue)),
|
|
300
|
+
m_preparedScriptStore(std::move(preparedScriptStore)) {}
|
|
301
|
+
|
|
302
|
+
HermesRuntimeHolder::~HermesRuntimeHolder() {
|
|
303
|
+
if (m_runtime) {
|
|
304
|
+
CRASH_ON_ERROR(getHermesApi().jsr_delete_runtime(m_runtime));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
114
307
|
|
|
115
308
|
void HermesRuntimeHolder::initRuntime() noexcept {
|
|
116
|
-
|
|
309
|
+
facebook::react::SystraceSection s("HermesExecutorFactory::makeHermesRuntimeSystraced");
|
|
310
|
+
std::shared_ptr<facebook::react::DevSettings> devSettings = m_weakDevSettings.lock();
|
|
117
311
|
VerifyElseCrash(devSettings);
|
|
118
312
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
313
|
+
HermesApi &api = getHermesApi();
|
|
314
|
+
HermesApi::setCurrent(&api);
|
|
315
|
+
jsr_config config{};
|
|
316
|
+
CRASH_ON_ERROR(api.jsr_create_config(&config));
|
|
317
|
+
CRASH_ON_ERROR(api.hermes_config_enable_default_crash_handler(config, devSettings->enableDefaultCrashHandler));
|
|
318
|
+
CRASH_ON_ERROR(api.jsr_config_enable_inspector(config, devSettings->useDirectDebugger));
|
|
319
|
+
CRASH_ON_ERROR(api.jsr_config_set_inspector_runtime_name(config, devSettings->debuggerRuntimeName.c_str()));
|
|
320
|
+
CRASH_ON_ERROR(api.jsr_config_set_inspector_port(config, devSettings->debuggerPort));
|
|
321
|
+
CRASH_ON_ERROR(api.jsr_config_set_inspector_break_on_start(config, devSettings->debuggerBreakOnNextLine));
|
|
322
|
+
if (m_jsQueue) {
|
|
323
|
+
HermesTaskRunner::Create(config, m_jsQueue);
|
|
324
|
+
}
|
|
325
|
+
if (m_preparedScriptStore) {
|
|
326
|
+
HermesScriptCache::Create(config, m_preparedScriptStore);
|
|
129
327
|
}
|
|
130
|
-
|
|
328
|
+
jsr_runtime runtime{};
|
|
329
|
+
CRASH_ON_ERROR(api.jsr_create_runtime(config, &runtime));
|
|
330
|
+
CRASH_ON_ERROR(api.jsr_delete_config(config));
|
|
331
|
+
|
|
332
|
+
napi_env env{};
|
|
333
|
+
CRASH_ON_ERROR(api.jsr_runtime_get_node_api_env(runtime, &env));
|
|
131
334
|
|
|
132
|
-
|
|
335
|
+
m_jsiRuntime = makeNodeApiJsiRuntime(
|
|
336
|
+
env, &api, [runtime]() { CRASH_ON_ERROR(HermesApi::current()->jsr_delete_runtime(runtime)); });
|
|
337
|
+
m_ownThreadId = std::this_thread::get_id();
|
|
338
|
+
|
|
339
|
+
// Add JS engine information to Error.prototype so in error reporting we
|
|
133
340
|
// can send this information.
|
|
134
|
-
auto errorPrototype =
|
|
135
|
-
.getPropertyAsObject(*
|
|
136
|
-
.getPropertyAsObject(*
|
|
137
|
-
errorPrototype.setProperty(*
|
|
341
|
+
auto errorPrototype = m_jsiRuntime->global()
|
|
342
|
+
.getPropertyAsObject(*m_jsiRuntime, "Error")
|
|
343
|
+
.getPropertyAsObject(*m_jsiRuntime, "prototype");
|
|
344
|
+
errorPrototype.setProperty(*m_jsiRuntime, "jsEngine", "hermes");
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
facebook::react::JSIEngineOverride HermesRuntimeHolder::getRuntimeType() noexcept {
|
|
348
|
+
return facebook::react::JSIEngineOverride::Hermes;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
std::shared_ptr<facebook::jsi::Runtime> HermesRuntimeHolder::getRuntime() noexcept {
|
|
352
|
+
std::call_once(m_onceFlag, [this]() { initRuntime(); });
|
|
353
|
+
VerifyElseCrash(m_jsiRuntime);
|
|
354
|
+
return m_jsiRuntime;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
void HermesRuntimeHolder::crashHandler(int fileDescriptor) noexcept {
|
|
358
|
+
CRASH_ON_ERROR(getHermesApi().hermes_dump_crash_data(m_runtime, fileDescriptor));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
void HermesRuntimeHolder::teardown() noexcept {
|
|
362
|
+
// TODO: (vmoroz) Implement
|
|
138
363
|
}
|
|
139
364
|
|
|
140
365
|
std::shared_ptr<HermesRuntimeHolder> HermesRuntimeHolder::loadFrom(
|
|
@@ -149,11 +374,23 @@ void HermesRuntimeHolder::storeTo(
|
|
|
149
374
|
}
|
|
150
375
|
|
|
151
376
|
void HermesRuntimeHolder::addToProfiling() const noexcept {
|
|
152
|
-
|
|
377
|
+
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_add(m_runtime));
|
|
153
378
|
}
|
|
154
379
|
|
|
155
380
|
void HermesRuntimeHolder::removeFromProfiling() const noexcept {
|
|
156
|
-
|
|
381
|
+
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_remove(m_runtime));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/*static*/ void HermesRuntimeHolder::enableSamplingProfiler() noexcept {
|
|
385
|
+
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_enable());
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/*static*/ void HermesRuntimeHolder::disableSamplingProfiler() noexcept {
|
|
389
|
+
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_disable());
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/*static*/ void HermesRuntimeHolder::dumpSampledTraceToFile(const std::string &fileName) noexcept {
|
|
393
|
+
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_dump_to_file(fileName.c_str()));
|
|
157
394
|
}
|
|
158
395
|
|
|
159
|
-
} // namespace
|
|
396
|
+
} // namespace Microsoft::ReactNative
|
|
@@ -2,25 +2,14 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
|
-
#include <JSI/RuntimeHolder.h>
|
|
6
|
-
|
|
7
|
-
#include <jsi/jsi.h>
|
|
8
|
-
#include <thread>
|
|
9
|
-
|
|
10
5
|
#include <DevSettings.h>
|
|
6
|
+
#include <JSI/RuntimeHolder.h>
|
|
7
|
+
#include <JSI/ScriptStore.h>
|
|
11
8
|
#include <ReactPropertyBag.h>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class HermesRuntime;
|
|
15
|
-
}
|
|
9
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
10
|
+
#include <hermes/hermes_api.h>
|
|
16
11
|
|
|
17
12
|
namespace Microsoft::ReactNative {
|
|
18
|
-
class HermesShim;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
namespace facebook::react {
|
|
22
|
-
|
|
23
|
-
class MessageQueueThread;
|
|
24
13
|
|
|
25
14
|
class HermesRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
|
|
26
15
|
public: // RuntimeHolderLazyInit implementation.
|
|
@@ -32,7 +21,9 @@ class HermesRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
|
|
|
32
21
|
public:
|
|
33
22
|
HermesRuntimeHolder(
|
|
34
23
|
std::shared_ptr<facebook::react::DevSettings> devSettings,
|
|
35
|
-
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue
|
|
24
|
+
std::shared_ptr<facebook::react::MessageQueueThread> jsQueue,
|
|
25
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> preparedScriptStore) noexcept;
|
|
26
|
+
~HermesRuntimeHolder();
|
|
36
27
|
|
|
37
28
|
static std::shared_ptr<HermesRuntimeHolder> loadFrom(
|
|
38
29
|
winrt::Microsoft::ReactNative::ReactPropertyBag const &propertyBag) noexcept;
|
|
@@ -44,16 +35,21 @@ class HermesRuntimeHolder : public Microsoft::JSI::RuntimeHolderLazyInit {
|
|
|
44
35
|
void addToProfiling() const noexcept;
|
|
45
36
|
void removeFromProfiling() const noexcept;
|
|
46
37
|
|
|
38
|
+
static void enableSamplingProfiler() noexcept;
|
|
39
|
+
static void disableSamplingProfiler() noexcept;
|
|
40
|
+
static void dumpSampledTraceToFile(const std::string &fileName) noexcept;
|
|
41
|
+
|
|
47
42
|
private:
|
|
48
43
|
void initRuntime() noexcept;
|
|
49
44
|
|
|
50
45
|
private:
|
|
51
|
-
|
|
52
|
-
std::shared_ptr<facebook::
|
|
46
|
+
jsr_runtime m_runtime{};
|
|
47
|
+
std::shared_ptr<facebook::jsi::Runtime> m_jsiRuntime;
|
|
53
48
|
std::once_flag m_onceFlag{};
|
|
54
49
|
std::thread::id m_ownThreadId{};
|
|
55
50
|
std::weak_ptr<facebook::react::DevSettings> m_weakDevSettings;
|
|
56
51
|
std::shared_ptr<facebook::react::MessageQueueThread> m_jsQueue;
|
|
52
|
+
std::shared_ptr<facebook::jsi::PreparedScriptStore> m_preparedScriptStore;
|
|
57
53
|
};
|
|
58
54
|
|
|
59
|
-
} // namespace
|
|
55
|
+
} // namespace Microsoft::ReactNative
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
#include "pch.h"
|
|
5
5
|
|
|
6
|
-
#include <hermes/
|
|
6
|
+
#include <hermes/hermes_api.h>
|
|
7
7
|
#include <chrono>
|
|
8
8
|
#include <future>
|
|
9
9
|
|
|
10
10
|
#include "HermesRuntimeHolder.h"
|
|
11
11
|
#include "HermesSamplingProfiler.h"
|
|
12
|
-
#include "HermesShim.h"
|
|
13
12
|
#include "IReactDispatcher.h"
|
|
14
13
|
#include "ReactPropertyBag.h"
|
|
15
14
|
#include "Utils.h"
|
|
@@ -48,7 +47,7 @@ auto resume_in_dispatcher(const IReactDispatcher &dispatcher) noexcept {
|
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
std::future<std::string> getTraceFilePath() noexcept {
|
|
51
|
-
|
|
50
|
+
std::string hermesDataPath = co_await Microsoft::React::getApplicationDataPath(L"Hermes");
|
|
52
51
|
std::ostringstream os;
|
|
53
52
|
auto now = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch())
|
|
54
53
|
.count();
|
|
@@ -78,7 +77,7 @@ winrt::fire_and_forget HermesSamplingProfiler::Start(
|
|
|
78
77
|
hermesRuntimeHolder->addToProfiling();
|
|
79
78
|
|
|
80
79
|
co_await winrt::resume_background();
|
|
81
|
-
|
|
80
|
+
HermesRuntimeHolder::enableSamplingProfiler();
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
co_return;
|
|
@@ -92,10 +91,10 @@ std::future<std::string> HermesSamplingProfiler::Stop(
|
|
|
92
91
|
ReactPropertyBag propertyBag = ReactPropertyBag(reactContext->Properties());
|
|
93
92
|
|
|
94
93
|
co_await winrt::resume_background();
|
|
95
|
-
|
|
94
|
+
HermesRuntimeHolder::disableSamplingProfiler();
|
|
96
95
|
|
|
97
96
|
s_lastTraceFilePath = co_await getTraceFilePath();
|
|
98
|
-
|
|
97
|
+
HermesRuntimeHolder::dumpSampledTraceToFile(s_lastTraceFilePath);
|
|
99
98
|
|
|
100
99
|
co_await resume_in_dispatcher(jsDispatcher);
|
|
101
100
|
std::shared_ptr<HermesRuntimeHolder> hermesRuntimeHolder = HermesRuntimeHolder::loadFrom(propertyBag);
|