react-native-windows 0.71.37 → 0.71.38
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 +5 -0
- package/Microsoft.ReactNative/IReactDispatcher.cpp +4 -0
- package/Microsoft.ReactNative/IReactDispatcher.h +1 -0
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +2 -4
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +30 -11
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +0 -2
- package/Microsoft.ReactNative/Views/DevMenu.cpp +3 -3
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +16 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +43 -12
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +17 -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 +3 -3
- package/PropertySheets/JSEngine.props +4 -4
- package/PropertySheets/React.Cpp.props +1 -0
- 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 +344 -84
- package/Shared/HermesRuntimeHolder.h +32 -21
- package/Shared/HermesSamplingProfiler.cpp +66 -14
- package/Shared/HermesSamplingProfiler.h +5 -3
- package/Shared/InspectorPackagerConnection.cpp +62 -108
- package/Shared/InspectorPackagerConnection.h +9 -21
- package/Shared/JSI/RuntimeHolder.h +2 -2
- package/Shared/JSI/ScriptStore.h +18 -20
- package/Shared/JSI/V8RuntimeHolder.cpp +260 -0
- package/Shared/JSI/V8RuntimeHolder.h +37 -0
- package/Shared/OInstance.cpp +16 -32
- package/Shared/SafeLoadLibrary.cpp +77 -0
- package/Shared/SafeLoadLibrary.h +19 -0
- package/Shared/Shared.vcxitems +19 -8
- package/Shared/Shared.vcxitems.filters +23 -30
- package/package.json +2 -2
- package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +0 -2103
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +0 -73
- package/Shared/HermesShim.cpp +0 -118
- package/Shared/HermesShim.h +0 -21
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +0 -209
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +0 -44
- package/Shared/V8JSIRuntimeHolder.cpp +0 -70
- package/Shared/V8JSIRuntimeHolder.h +0 -53
|
@@ -3,19 +3,51 @@
|
|
|
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
|
+
#include "HermesRuntimeHolder.h"
|
|
10
11
|
#include "HermesSamplingProfiler.h"
|
|
11
|
-
#include "
|
|
12
|
+
#include "IReactDispatcher.h"
|
|
13
|
+
#include "ReactPropertyBag.h"
|
|
12
14
|
#include "Utils.h"
|
|
13
15
|
|
|
16
|
+
using namespace winrt::Microsoft::ReactNative;
|
|
17
|
+
using namespace facebook::react;
|
|
18
|
+
|
|
14
19
|
namespace Microsoft::ReactNative {
|
|
15
20
|
|
|
16
21
|
namespace {
|
|
22
|
+
|
|
23
|
+
// Implements an awaiter for Mso::DispatchQueue
|
|
24
|
+
auto resume_in_dispatcher(const IReactDispatcher &dispatcher) noexcept {
|
|
25
|
+
struct awaitable {
|
|
26
|
+
awaitable(const IReactDispatcher &dispatcher) noexcept : dispatcher_(dispatcher) {}
|
|
27
|
+
|
|
28
|
+
bool await_ready() const noexcept {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void await_resume() const noexcept {}
|
|
33
|
+
|
|
34
|
+
void await_suspend(std::experimental::coroutine_handle<> resume) noexcept {
|
|
35
|
+
callback_ = [context = resume.address()]() noexcept {
|
|
36
|
+
std::experimental::coroutine_handle<>::from_address(context)();
|
|
37
|
+
};
|
|
38
|
+
dispatcher_.Post(std::move(callback_));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private:
|
|
42
|
+
IReactDispatcher dispatcher_;
|
|
43
|
+
ReactDispatcherCallback callback_;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return awaitable{dispatcher};
|
|
47
|
+
}
|
|
48
|
+
|
|
17
49
|
std::future<std::string> getTraceFilePath() noexcept {
|
|
18
|
-
|
|
50
|
+
std::string hermesDataPath = co_await Microsoft::React::getApplicationDataPath(L"Hermes");
|
|
19
51
|
std::ostringstream os;
|
|
20
52
|
auto now = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch())
|
|
21
53
|
.count();
|
|
@@ -23,39 +55,59 @@ std::future<std::string> getTraceFilePath() noexcept {
|
|
|
23
55
|
os << hermesDataPath << "\\cpu_" << now << ".cpuprofile";
|
|
24
56
|
co_return os.str();
|
|
25
57
|
}
|
|
58
|
+
|
|
26
59
|
} // namespace
|
|
27
60
|
|
|
28
|
-
|
|
61
|
+
std::atomic_bool HermesSamplingProfiler::s_isStarted{false};
|
|
29
62
|
std::string HermesSamplingProfiler::s_lastTraceFilePath;
|
|
30
63
|
|
|
31
64
|
std::string HermesSamplingProfiler::GetLastTraceFilePath() noexcept {
|
|
32
65
|
return s_lastTraceFilePath;
|
|
33
66
|
}
|
|
34
67
|
|
|
35
|
-
winrt::fire_and_forget HermesSamplingProfiler::Start(
|
|
36
|
-
|
|
37
|
-
|
|
68
|
+
winrt::fire_and_forget HermesSamplingProfiler::Start(
|
|
69
|
+
Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
|
|
70
|
+
bool expectedIsStarted = false;
|
|
71
|
+
if (s_isStarted.compare_exchange_strong(expectedIsStarted, true)) {
|
|
72
|
+
IReactDispatcher jsDispatcher = implementation::ReactDispatcher::GetJSDispatcher(reactContext->Properties());
|
|
73
|
+
ReactPropertyBag propertyBag = ReactPropertyBag(reactContext->Properties());
|
|
74
|
+
|
|
75
|
+
co_await resume_in_dispatcher(jsDispatcher);
|
|
76
|
+
std::shared_ptr<HermesRuntimeHolder> hermesRuntimeHolder = HermesRuntimeHolder::loadFrom(propertyBag);
|
|
77
|
+
hermesRuntimeHolder->addToProfiling();
|
|
78
|
+
|
|
38
79
|
co_await winrt::resume_background();
|
|
39
|
-
|
|
80
|
+
HermesRuntimeHolder::enableSamplingProfiler();
|
|
40
81
|
}
|
|
41
82
|
|
|
42
83
|
co_return;
|
|
43
84
|
}
|
|
44
85
|
|
|
45
|
-
std::future<std::string> HermesSamplingProfiler::Stop(
|
|
46
|
-
|
|
47
|
-
|
|
86
|
+
std::future<std::string> HermesSamplingProfiler::Stop(
|
|
87
|
+
Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
|
|
88
|
+
bool expectedIsStarted = true;
|
|
89
|
+
if (s_isStarted.compare_exchange_strong(expectedIsStarted, false)) {
|
|
90
|
+
IReactDispatcher jsDispatcher = implementation::ReactDispatcher::GetJSDispatcher(reactContext->Properties());
|
|
91
|
+
ReactPropertyBag propertyBag = ReactPropertyBag(reactContext->Properties());
|
|
92
|
+
|
|
48
93
|
co_await winrt::resume_background();
|
|
49
|
-
|
|
94
|
+
HermesRuntimeHolder::disableSamplingProfiler();
|
|
95
|
+
|
|
50
96
|
s_lastTraceFilePath = co_await getTraceFilePath();
|
|
51
|
-
|
|
97
|
+
HermesRuntimeHolder::dumpSampledTraceToFile(s_lastTraceFilePath);
|
|
98
|
+
|
|
99
|
+
co_await resume_in_dispatcher(jsDispatcher);
|
|
100
|
+
std::shared_ptr<HermesRuntimeHolder> hermesRuntimeHolder = HermesRuntimeHolder::loadFrom(propertyBag);
|
|
101
|
+
hermesRuntimeHolder->removeFromProfiling();
|
|
102
|
+
|
|
103
|
+
co_await winrt::resume_background();
|
|
52
104
|
}
|
|
53
105
|
|
|
54
106
|
co_return s_lastTraceFilePath;
|
|
55
107
|
}
|
|
56
108
|
|
|
57
109
|
bool HermesSamplingProfiler::IsStarted() noexcept {
|
|
58
|
-
return s_isStarted;
|
|
110
|
+
return s_isStarted.load();
|
|
59
111
|
}
|
|
60
112
|
|
|
61
113
|
} // namespace Microsoft::ReactNative
|
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
+
#include <ReactHost/React.h>
|
|
7
|
+
#include <atomic>
|
|
6
8
|
#include <string>
|
|
7
9
|
|
|
8
10
|
namespace Microsoft::ReactNative {
|
|
9
11
|
|
|
10
12
|
class HermesSamplingProfiler final {
|
|
11
13
|
public:
|
|
12
|
-
static winrt::fire_and_forget Start() noexcept;
|
|
13
|
-
static std::future<std::string> Stop() noexcept;
|
|
14
|
+
static winrt::fire_and_forget Start(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept;
|
|
15
|
+
static std::future<std::string> Stop(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept;
|
|
14
16
|
static std::string GetLastTraceFilePath() noexcept;
|
|
15
17
|
static bool IsStarted() noexcept;
|
|
16
18
|
|
|
17
19
|
private:
|
|
18
|
-
static
|
|
20
|
+
static std::atomic_bool s_isStarted;
|
|
19
21
|
static std::string s_lastTraceFilePath;
|
|
20
22
|
};
|
|
21
23
|
|
|
@@ -3,18 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#include "pch.h"
|
|
5
5
|
|
|
6
|
-
#ifdef HERMES_ENABLE_DEBUGGER
|
|
7
|
-
|
|
8
6
|
#include <folly/json.h>
|
|
9
7
|
#include <tracing/tracing.h>
|
|
10
8
|
#include "InspectorPackagerConnection.h"
|
|
11
9
|
|
|
12
|
-
namespace facebook {
|
|
13
|
-
namespace react {
|
|
14
|
-
IDestructible::~IDestructible() {}
|
|
15
|
-
} // namespace react
|
|
16
|
-
} // namespace facebook
|
|
17
|
-
|
|
18
10
|
namespace Microsoft::ReactNative {
|
|
19
11
|
|
|
20
12
|
namespace {
|
|
@@ -80,35 +72,16 @@ struct InspectorProtocol {
|
|
|
80
72
|
}
|
|
81
73
|
|
|
82
74
|
static folly::dynamic constructGetPagesResponsePayloadForPackager(
|
|
83
|
-
const std::vector<facebook::react::
|
|
84
|
-
InspectorPackagerConnection::BundleStatus bundleStatus) {
|
|
85
|
-
folly::dynamic payload = folly::dynamic::array;
|
|
86
|
-
for (const facebook::react::InspectorPage2 &page : pages) {
|
|
87
|
-
folly::dynamic pageDyn = folly::dynamic::object;
|
|
88
|
-
pageDyn["id"] = page.id;
|
|
89
|
-
pageDyn["title"] = page.title;
|
|
90
|
-
pageDyn["vm"] = page.vm;
|
|
91
|
-
|
|
92
|
-
pageDyn["isLastBundleDownloadSuccess"] = bundleStatus.m_isLastDownloadSucess;
|
|
93
|
-
pageDyn["bundleUpdateTimestamp"] = bundleStatus.m_updateTimestamp;
|
|
94
|
-
|
|
95
|
-
payload.push_back(pageDyn);
|
|
96
|
-
}
|
|
97
|
-
return payload;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
static folly::dynamic constructGetPagesResponsePayloadForPackager(
|
|
101
|
-
std::unique_ptr<facebook::react::IInspectorPages> pages,
|
|
75
|
+
const std::vector<facebook::react::InspectorPage> &pages,
|
|
102
76
|
InspectorPackagerConnection::BundleStatus bundleStatus) {
|
|
103
77
|
folly::dynamic payload = folly::dynamic::array;
|
|
104
|
-
for (
|
|
105
|
-
const facebook::react::InspectorPage2 page = pages->getPage(p);
|
|
78
|
+
for (const facebook::react::InspectorPage &page : pages) {
|
|
106
79
|
folly::dynamic pageDyn = folly::dynamic::object;
|
|
107
80
|
pageDyn["id"] = page.id;
|
|
108
81
|
pageDyn["title"] = page.title;
|
|
109
82
|
pageDyn["vm"] = page.vm;
|
|
110
83
|
|
|
111
|
-
pageDyn["isLastBundleDownloadSuccess"] = bundleStatus.
|
|
84
|
+
pageDyn["isLastBundleDownloadSuccess"] = bundleStatus.m_isLastDownloadSuccess;
|
|
112
85
|
pageDyn["bundleUpdateTimestamp"] = bundleStatus.m_updateTimestamp;
|
|
113
86
|
|
|
114
87
|
payload.push_back(pageDyn);
|
|
@@ -116,14 +89,14 @@ struct InspectorProtocol {
|
|
|
116
89
|
return payload;
|
|
117
90
|
}
|
|
118
91
|
|
|
119
|
-
static folly::dynamic constructVMResponsePayloadForPackager(
|
|
92
|
+
static folly::dynamic constructVMResponsePayloadForPackager(int32_t pageId, std::string &&messageFromVM) {
|
|
120
93
|
folly::dynamic payload = folly::dynamic::object;
|
|
121
94
|
payload[InspectorProtocol::Message_eventName_wrappedEvent] = messageFromVM;
|
|
122
95
|
payload[InspectorProtocol::Message_PAGEID] = pageId;
|
|
123
96
|
return payload;
|
|
124
97
|
}
|
|
125
98
|
|
|
126
|
-
static folly::dynamic constructVMResponsePayloadOnDisconnectForPackager(
|
|
99
|
+
static folly::dynamic constructVMResponsePayloadOnDisconnectForPackager(int32_t pageId) {
|
|
127
100
|
folly::dynamic payload = folly::dynamic::object;
|
|
128
101
|
payload[InspectorProtocol::Message_PAGEID] = pageId;
|
|
129
102
|
return payload;
|
|
@@ -132,7 +105,7 @@ struct InspectorProtocol {
|
|
|
132
105
|
|
|
133
106
|
} // namespace
|
|
134
107
|
|
|
135
|
-
RemoteConnection::RemoteConnection(
|
|
108
|
+
RemoteConnection::RemoteConnection(int32_t pageId, const InspectorPackagerConnection &packagerConnection)
|
|
136
109
|
: m_packagerConnection(packagerConnection), m_pageId(pageId) {}
|
|
137
110
|
|
|
138
111
|
void RemoteConnection::onMessage(std::string message) {
|
|
@@ -152,26 +125,6 @@ void RemoteConnection::onDisconnect() {
|
|
|
152
125
|
m_packagerConnection.sendMessageToPackager(std::move(responsestr));
|
|
153
126
|
}
|
|
154
127
|
|
|
155
|
-
RemoteConnection2::RemoteConnection2(int64_t pageId, const InspectorPackagerConnection &packagerConnection)
|
|
156
|
-
: m_packagerConnection(packagerConnection), m_pageId(pageId) {}
|
|
157
|
-
|
|
158
|
-
void RemoteConnection2::onMessage(std::string message) {
|
|
159
|
-
folly::dynamic response = InspectorProtocol::constructResponseForPackager(
|
|
160
|
-
InspectorProtocol::EventType::WrappedEvent,
|
|
161
|
-
InspectorProtocol::constructVMResponsePayloadForPackager(m_pageId, std::move(message)));
|
|
162
|
-
std::string responsestr = folly::toJson(response);
|
|
163
|
-
m_packagerConnection.sendMessageToPackager(std::move(responsestr));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
void RemoteConnection2::onDisconnect() {
|
|
167
|
-
folly::dynamic response = InspectorProtocol::constructResponseForPackager(
|
|
168
|
-
InspectorProtocol::EventType::Disconnect,
|
|
169
|
-
InspectorProtocol::constructVMResponsePayloadOnDisconnectForPackager(m_pageId));
|
|
170
|
-
|
|
171
|
-
std::string responsestr = folly::toJson(response);
|
|
172
|
-
m_packagerConnection.sendMessageToPackager(std::move(responsestr));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
128
|
winrt::fire_and_forget InspectorPackagerConnection::sendMessageToPackagerAsync(std::string &&message) const {
|
|
176
129
|
std::string message_(std::move(message));
|
|
177
130
|
co_await winrt::resume_background();
|
|
@@ -183,7 +136,7 @@ void InspectorPackagerConnection::sendMessageToPackager(std::string &&message) c
|
|
|
183
136
|
sendMessageToPackagerAsync(std::move(message));
|
|
184
137
|
}
|
|
185
138
|
|
|
186
|
-
void InspectorPackagerConnection::sendMessageToVM(
|
|
139
|
+
void InspectorPackagerConnection::sendMessageToVM(int32_t pageId, std::string &&message) {
|
|
187
140
|
m_localConnections[pageId]->sendMessage(std::move(message));
|
|
188
141
|
}
|
|
189
142
|
|
|
@@ -214,59 +167,62 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
214
167
|
m_packagerWebSocketConnection->SetOnConnect(
|
|
215
168
|
[]() { facebook::react::tracing::log("Inspector: Websocket connection succeeded."); });
|
|
216
169
|
|
|
217
|
-
m_packagerWebSocketConnection->SetOnMessage(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
std::string wrappedEvent = payload[InspectorProtocol::Message_eventName_wrappedEvent].getString();
|
|
244
|
-
self->sendMessageToVM(pageId, std::move(wrappedEvent));
|
|
245
|
-
} break;
|
|
246
|
-
|
|
247
|
-
case InspectorProtocol::EventType::Connect: {
|
|
248
|
-
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
249
|
-
int64_t pageId = payload[InspectorProtocol::Message_PAGEID].asInt();
|
|
250
|
-
|
|
251
|
-
if (self->m_localConnections.find(pageId) != self->m_localConnections.end()) {
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
self->m_localConnections[pageId] = facebook::react::connectInspectorPage(
|
|
256
|
-
static_cast<int>(pageId), std::make_unique<RemoteConnection2>(pageId, *self));
|
|
257
|
-
} break;
|
|
258
|
-
|
|
259
|
-
case InspectorProtocol::EventType::Disconnect: {
|
|
260
|
-
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
261
|
-
int64_t pageId = payload[InspectorProtocol::Message_PAGEID].asInt();
|
|
262
|
-
if (self->m_localConnections.find(pageId) != self->m_localConnections.end()) {
|
|
263
|
-
self->m_localConnections[pageId]->disconnect();
|
|
264
|
-
self->m_localConnections.erase(pageId);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
} break;
|
|
170
|
+
m_packagerWebSocketConnection->SetOnMessage([self = shared_from_this()](
|
|
171
|
+
size_t /*length*/, const std::string &message, bool isBinary) {
|
|
172
|
+
assert(!isBinary && "We don't expect any binary messages !");
|
|
173
|
+
folly::dynamic messageDyn = folly::parseJson(message);
|
|
174
|
+
|
|
175
|
+
InspectorProtocol::EventType eventType = InspectorProtocol::getEventType(messageDyn);
|
|
176
|
+
switch (eventType) {
|
|
177
|
+
case InspectorProtocol::EventType::GetPages: {
|
|
178
|
+
std::vector<facebook::react::InspectorPage> inspectorPages = facebook::react::getInspectorInstance().getPages();
|
|
179
|
+
folly::dynamic response = InspectorProtocol::constructResponseForPackager(
|
|
180
|
+
InspectorProtocol::EventType::GetPages,
|
|
181
|
+
InspectorProtocol::constructGetPagesResponsePayloadForPackager(
|
|
182
|
+
inspectorPages, self->m_bundleStatusProvider->getBundleStatus()));
|
|
183
|
+
|
|
184
|
+
std::string responsestr = folly::toJson(response);
|
|
185
|
+
self->sendMessageToPackager(std::move(responsestr));
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
case InspectorProtocol::EventType::WrappedEvent: {
|
|
190
|
+
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
191
|
+
int32_t pageId = static_cast<int32_t>(payload[InspectorProtocol::Message_PAGEID].asInt());
|
|
192
|
+
|
|
193
|
+
if (self->m_localConnections.find(pageId) == self->m_localConnections.end()) {
|
|
194
|
+
break;
|
|
268
195
|
}
|
|
269
|
-
|
|
196
|
+
|
|
197
|
+
std::string wrappedEvent = payload[InspectorProtocol::Message_eventName_wrappedEvent].getString();
|
|
198
|
+
self->sendMessageToVM(pageId, std::move(wrappedEvent));
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
case InspectorProtocol::EventType::Connect: {
|
|
203
|
+
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
204
|
+
int32_t pageId = static_cast<int32_t>(payload[InspectorProtocol::Message_PAGEID].asInt());
|
|
205
|
+
|
|
206
|
+
if (self->m_localConnections.find(pageId) != self->m_localConnections.end()) {
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
self->m_localConnections[pageId] =
|
|
211
|
+
facebook::react::getInspectorInstance().connect(pageId, std::make_unique<RemoteConnection>(pageId, *self));
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
case InspectorProtocol::EventType::Disconnect: {
|
|
216
|
+
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
217
|
+
int32_t pageId = static_cast<int32_t>(payload[InspectorProtocol::Message_PAGEID].asInt());
|
|
218
|
+
if (self->m_localConnections.find(pageId) != self->m_localConnections.end()) {
|
|
219
|
+
self->m_localConnections[pageId]->disconnect();
|
|
220
|
+
self->m_localConnections.erase(pageId);
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
});
|
|
270
226
|
|
|
271
227
|
Microsoft::React::Networking::IWebSocketResource::Protocols protocols;
|
|
272
228
|
Microsoft::React::Networking::IWebSocketResource::Options options;
|
|
@@ -276,5 +232,3 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
276
232
|
}
|
|
277
233
|
|
|
278
234
|
} // namespace Microsoft::ReactNative
|
|
279
|
-
|
|
280
|
-
#endif
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
-
#include <InspectorProxy.h>
|
|
7
6
|
#include <Networking/WinRTWebSocketResource.h>
|
|
8
7
|
#include <jsinspector/InspectorInterfaces.h>
|
|
9
8
|
|
|
@@ -16,12 +15,12 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
16
15
|
|
|
17
16
|
class BundleStatus {
|
|
18
17
|
public:
|
|
19
|
-
bool
|
|
18
|
+
bool m_isLastDownloadSuccess;
|
|
20
19
|
int64_t m_updateTimestamp = -1;
|
|
21
20
|
|
|
22
|
-
BundleStatus(bool
|
|
23
|
-
:
|
|
24
|
-
BundleStatus() :
|
|
21
|
+
BundleStatus(bool isLastDownloadSuccess, long updateTimestamp)
|
|
22
|
+
: m_isLastDownloadSuccess(isLastDownloadSuccess), m_updateTimestamp(updateTimestamp) {}
|
|
23
|
+
BundleStatus() : m_isLastDownloadSuccess(false), m_updateTimestamp(-1) {}
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
struct IBundleStatusProvider {
|
|
@@ -32,16 +31,16 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
32
31
|
|
|
33
32
|
private:
|
|
34
33
|
friend class RemoteConnection;
|
|
35
|
-
friend class RemoteConnection2;
|
|
36
34
|
|
|
37
35
|
winrt::fire_and_forget sendMessageToPackagerAsync(std::string &&message) const;
|
|
38
36
|
void sendMessageToPackager(std::string &&message) const;
|
|
39
37
|
|
|
40
38
|
// Note:: VM side Inspector processes the messages asynchronousely in a sequential executor with dedicated thread.
|
|
41
39
|
// Hence, we don't bother invoking the inspector asynchronously.
|
|
42
|
-
void sendMessageToVM(
|
|
40
|
+
void sendMessageToVM(int32_t pageId, std::string &&message);
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
private:
|
|
43
|
+
std::unordered_map<int32_t, std::unique_ptr<facebook::react::ILocalConnection>> m_localConnections;
|
|
45
44
|
std::shared_ptr<Microsoft::React::Networking::WinRTWebSocketResource> m_packagerWebSocketConnection;
|
|
46
45
|
std::shared_ptr<IBundleStatusProvider> m_bundleStatusProvider;
|
|
47
46
|
std::string m_url;
|
|
@@ -49,23 +48,12 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
49
48
|
|
|
50
49
|
class RemoteConnection final : public facebook::react::IRemoteConnection {
|
|
51
50
|
public:
|
|
52
|
-
RemoteConnection(
|
|
53
|
-
void onMessage(std::string message) override;
|
|
54
|
-
void onDisconnect() override;
|
|
55
|
-
|
|
56
|
-
private:
|
|
57
|
-
int64_t m_pageId;
|
|
58
|
-
const InspectorPackagerConnection &m_packagerConnection;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
class RemoteConnection2 final : public facebook::react::IRemoteConnection2 {
|
|
62
|
-
public:
|
|
63
|
-
RemoteConnection2(int64_t pageId, const InspectorPackagerConnection &packagerConnection);
|
|
51
|
+
RemoteConnection(int32_t pageId, const InspectorPackagerConnection &packagerConnection);
|
|
64
52
|
void onMessage(std::string message) override;
|
|
65
53
|
void onDisconnect() override;
|
|
66
54
|
|
|
67
55
|
private:
|
|
68
|
-
|
|
56
|
+
int32_t m_pageId;
|
|
69
57
|
const InspectorPackagerConnection &m_packagerConnection;
|
|
70
58
|
};
|
|
71
59
|
|
|
@@ -11,7 +11,7 @@ namespace Microsoft::JSI {
|
|
|
11
11
|
// a. lazily create a JSI Runtime on the first call to getRuntime
|
|
12
12
|
// b. subsequent calls to getRuntime should return the Runtime created in (a)
|
|
13
13
|
|
|
14
|
-
// Note
|
|
14
|
+
// Note: all calls to getRuntime() should happen on the same thread unless you are sure that
|
|
15
15
|
// the underlying Runtime instance is thread safe.
|
|
16
16
|
|
|
17
17
|
struct RuntimeHolderLazyInit {
|
|
@@ -21,7 +21,7 @@ struct RuntimeHolderLazyInit {
|
|
|
21
21
|
virtual void teardown() noexcept {};
|
|
22
22
|
|
|
23
23
|
// You can call this when a crash happens to attempt recording additional data
|
|
24
|
-
// The
|
|
24
|
+
// The fileDescriptor supplied is a raw file stream an implementation might write JSON to.
|
|
25
25
|
virtual void crashHandler(int fileDescriptor) noexcept {};
|
|
26
26
|
};
|
|
27
27
|
|
package/Shared/JSI/ScriptStore.h
CHANGED
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
#include <jsi/jsi.h>
|
|
6
6
|
#include <memory>
|
|
7
7
|
|
|
8
|
-
namespace facebook {
|
|
9
|
-
namespace jsi {
|
|
8
|
+
namespace facebook::jsi {
|
|
10
9
|
|
|
11
|
-
// Integer type as it's persist
|
|
12
|
-
using ScriptVersion_t = uint64_t; // It
|
|
13
|
-
// then, 0 implies versioning not available.
|
|
10
|
+
// Integer type as it's persist friendly.
|
|
11
|
+
using ScriptVersion_t = uint64_t; // It should be std::optional<uint64_t> once we have c++17 available everywhere.
|
|
12
|
+
// Until then, 0 implies versioning not available.
|
|
14
13
|
using JSRuntimeVersion_t = uint64_t; // 0 implies version can't be computed. We assert whenever that happens.
|
|
15
14
|
|
|
16
15
|
struct VersionedBuffer {
|
|
@@ -30,14 +29,14 @@ struct JSRuntimeSignature {
|
|
|
30
29
|
|
|
31
30
|
// Most JSI::Runtime implementation offer some form of prepared JavaScript which offers better performance
|
|
32
31
|
// characteristics when loading comparing to plain JavaScript. Embedders can provide an instance of this interface
|
|
33
|
-
// (through JSI::Runtime implementation's factory method), to enable
|
|
34
|
-
// subsequent evaluation of a script.
|
|
32
|
+
// (through JSI::Runtime implementation's factory method), to enable persistence of the prepared script
|
|
33
|
+
// and retrieval on subsequent evaluation of a script.
|
|
35
34
|
struct PreparedScriptStore {
|
|
36
35
|
virtual ~PreparedScriptStore() = default;
|
|
37
36
|
|
|
38
|
-
// Try to retrieve the prepared
|
|
39
|
-
// scriptSignature :
|
|
40
|
-
// RuntimeSignature :
|
|
37
|
+
// Try to retrieve the prepared JavaScript for a given combination of script & runtime.
|
|
38
|
+
// scriptSignature : JavaScript URL and version
|
|
39
|
+
// RuntimeSignature : JavaScript engine type and version
|
|
41
40
|
// prepareTag : Custom tag to uniquely identify JS engine specific preparation schemes. It is usually useful while
|
|
42
41
|
// experimentation and can be null. It is possible that no prepared script is available for a given script & runtime
|
|
43
42
|
// signature. This method should null if so
|
|
@@ -47,12 +46,12 @@ struct PreparedScriptStore {
|
|
|
47
46
|
const char *prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache.
|
|
48
47
|
) noexcept = 0;
|
|
49
48
|
|
|
50
|
-
// Persist the
|
|
51
|
-
// scriptSignature :
|
|
52
|
-
// RuntimeSignature :
|
|
49
|
+
// Persist the prepared JavaScript for a given combination of script & runtime.
|
|
50
|
+
// scriptSignature : JavaScript URL and version
|
|
51
|
+
// RuntimeSignature : JavaScript engine type and version
|
|
53
52
|
// prepareTag : Custom tag to uniquely identify JS engine specific preparation schemes. It is usually useful while
|
|
54
53
|
// experimentation and can be null. It is possible that no prepared script is available for a given script & runtime
|
|
55
|
-
// signature. This method should null if so Any failure in
|
|
54
|
+
// signature. This method should null if so Any failure in persistence should be identified during the subsequent
|
|
56
55
|
// retrieval through the integrity mechanism which must be put into the storage.
|
|
57
56
|
virtual void persistPreparedScript(
|
|
58
57
|
std::shared_ptr<const facebook::jsi::Buffer> preparedScript,
|
|
@@ -63,17 +62,16 @@ struct PreparedScriptStore {
|
|
|
63
62
|
};
|
|
64
63
|
|
|
65
64
|
// JSI::Runtime implementation must be provided an instance on this interface to enable version sensitive capabilities
|
|
66
|
-
// such as usage of
|
|
67
|
-
//
|
|
65
|
+
// such as usage of prepared JavaScript script. Alternatively, this entity can be used to directly provide the
|
|
66
|
+
// JavaScript buffer and rich meta data to the JSI::Runtime instance.
|
|
68
67
|
struct ScriptStore {
|
|
69
68
|
virtual ~ScriptStore() = default;
|
|
70
69
|
|
|
71
|
-
// Return the
|
|
70
|
+
// Return the JavaScript buffer and version corresponding to a given URL.
|
|
72
71
|
virtual VersionedBuffer getVersionedScript(const std::string &url) noexcept = 0;
|
|
73
72
|
|
|
74
|
-
// Return the version of the
|
|
73
|
+
// Return the version of the JavaScript buffer corresponding to a given URL.
|
|
75
74
|
virtual ScriptVersion_t getScriptVersion(const std::string &url) noexcept = 0;
|
|
76
75
|
};
|
|
77
76
|
|
|
78
|
-
} // namespace jsi
|
|
79
|
-
} // namespace facebook
|
|
77
|
+
} // namespace facebook::jsi
|