react-native-windows 0.71.26 → 0.71.27
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 +0 -5
- package/Microsoft.ReactNative/IReactDispatcher.cpp +0 -4
- package/Microsoft.ReactNative/IReactDispatcher.h +0 -1
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +4 -2
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +11 -31
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +2 -0
- package/Microsoft.ReactNative/Views/DevMenu.cpp +3 -3
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.cpp +2103 -0
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiRuntime.h +73 -0
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +12 -43
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +6 -17
- 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 +0 -1
- package/PropertySheets/Warnings.props +0 -6
- package/ReactCommon/ReactCommon.vcxproj +1 -53
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +0 -36
- package/Shared/DevSupportManager.cpp +9 -2
- package/Shared/DevSupportManager.h +6 -2
- package/Shared/HermesRuntimeHolder.cpp +84 -344
- package/Shared/HermesRuntimeHolder.h +21 -32
- package/Shared/HermesSamplingProfiler.cpp +14 -66
- package/Shared/HermesSamplingProfiler.h +3 -5
- package/Shared/HermesShim.cpp +118 -0
- package/Shared/HermesShim.h +21 -0
- package/Shared/InspectorPackagerConnection.cpp +108 -62
- package/Shared/InspectorPackagerConnection.h +21 -9
- package/Shared/JSI/NapiJsiV8RuntimeHolder.cpp +209 -0
- package/Shared/JSI/NapiJsiV8RuntimeHolder.h +44 -0
- package/Shared/JSI/RuntimeHolder.h +2 -2
- package/Shared/JSI/ScriptStore.h +20 -18
- package/Shared/OInstance.cpp +32 -16
- package/Shared/Shared.vcxitems +8 -19
- package/Shared/Shared.vcxitems.filters +30 -23
- package/Shared/V8JSIRuntimeHolder.cpp +70 -0
- package/Shared/V8JSIRuntimeHolder.h +53 -0
- package/package.json +2 -2
- package/template/cs-app-WinAppSDK/proj/ExperimentalFeatures.props +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/NodeApiJsiLoader.cpp +0 -16
- package/ReactCommon/cgmanifest.json +0 -15
- package/Shared/JSI/V8RuntimeHolder.cpp +0 -260
- package/Shared/JSI/V8RuntimeHolder.h +0 -37
- package/Shared/SafeLoadLibrary.cpp +0 -41
- package/Shared/SafeLoadLibrary.h +0 -15
|
@@ -3,21 +3,19 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
-
#include <ReactHost/React.h>
|
|
7
|
-
#include <atomic>
|
|
8
6
|
#include <string>
|
|
9
7
|
|
|
10
8
|
namespace Microsoft::ReactNative {
|
|
11
9
|
|
|
12
10
|
class HermesSamplingProfiler final {
|
|
13
11
|
public:
|
|
14
|
-
static winrt::fire_and_forget Start(
|
|
15
|
-
static std::future<std::string> Stop(
|
|
12
|
+
static winrt::fire_and_forget Start() noexcept;
|
|
13
|
+
static std::future<std::string> Stop() noexcept;
|
|
16
14
|
static std::string GetLastTraceFilePath() noexcept;
|
|
17
15
|
static bool IsStarted() noexcept;
|
|
18
16
|
|
|
19
17
|
private:
|
|
20
|
-
static
|
|
18
|
+
static bool s_isStarted;
|
|
21
19
|
static std::string s_lastTraceFilePath;
|
|
22
20
|
};
|
|
23
21
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#include "HermesShim.h"
|
|
5
|
+
#include "Crash.h"
|
|
6
|
+
|
|
7
|
+
namespace Microsoft::ReactNative::HermesShim {
|
|
8
|
+
|
|
9
|
+
static HMODULE s_hermesModule{nullptr};
|
|
10
|
+
static decltype(&facebook::hermes::makeHermesRuntime) s_makeHermesRuntime{nullptr};
|
|
11
|
+
static decltype(&facebook::hermes::HermesRuntime::enableSamplingProfiler) s_enableSamplingProfiler{nullptr};
|
|
12
|
+
static decltype(&facebook::hermes::HermesRuntime::disableSamplingProfiler) s_disableSamplingProfiler{nullptr};
|
|
13
|
+
static decltype(&facebook::hermes::HermesRuntime::dumpSampledTraceToFile) s_dumpSampledTraceToFile{nullptr};
|
|
14
|
+
static decltype(&facebook::hermes::makeHermesRuntimeWithWER) s_makeHermesRuntimeWithWER{nullptr};
|
|
15
|
+
static decltype(&facebook::hermes::hermesCrashHandler) s_hermesCrashHandler{nullptr};
|
|
16
|
+
|
|
17
|
+
#if _M_X64
|
|
18
|
+
constexpr const char *makeHermesRuntimeSymbol =
|
|
19
|
+
"?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@AEBVRuntimeConfig@vm@1@@Z";
|
|
20
|
+
constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
21
|
+
constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
22
|
+
constexpr const char *dumpSampledTraceToFileSymbol =
|
|
23
|
+
"?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
|
|
24
|
+
constexpr const char *makeHermesRuntimeWithWERSymbol =
|
|
25
|
+
"?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
|
|
26
|
+
constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAEAVHermesRuntime@12@H@Z";
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#if _M_ARM64
|
|
30
|
+
constexpr const char *makeHermesRuntimeSymbol =
|
|
31
|
+
"?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@AEBVRuntimeConfig@vm@1@@Z";
|
|
32
|
+
constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
33
|
+
constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
34
|
+
constexpr const char *dumpSampledTraceToFileSymbol =
|
|
35
|
+
"?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
|
|
36
|
+
constexpr const char *makeHermesRuntimeWithWERSymbol =
|
|
37
|
+
"?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
|
|
38
|
+
constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAEAVHermesRuntime@12@H@Z";
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#if _M_IX86
|
|
42
|
+
constexpr const char *makeHermesRuntimeSymbol =
|
|
43
|
+
"?makeHermesRuntime@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@ABVRuntimeConfig@vm@1@@Z";
|
|
44
|
+
constexpr const char *enableSamlingProfilerSymbol = "?enableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
45
|
+
constexpr const char *disableSamlingProfilerSymbol = "?disableSamplingProfiler@HermesRuntime@hermes@facebook@@SAXXZ";
|
|
46
|
+
constexpr const char *dumpSampledTraceToFileSymbol =
|
|
47
|
+
"?dumpSampledTraceToFile@HermesRuntime@hermes@facebook@@SAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z";
|
|
48
|
+
constexpr const char *makeHermesRuntimeWithWERSymbol =
|
|
49
|
+
"?makeHermesRuntimeWithWER@hermes@facebook@@YA?AV?$unique_ptr@VHermesRuntime@hermes@facebook@@U?$default_delete@VHermesRuntime@hermes@facebook@@@std@@@std@@XZ";
|
|
50
|
+
constexpr const char *hermesCrashHandlerSymbol = "?hermesCrashHandler@hermes@facebook@@YAXAAVHermesRuntime@12@H@Z";
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
static std::once_flag s_hermesLoading;
|
|
54
|
+
|
|
55
|
+
static void EnsureHermesLoaded() noexcept {
|
|
56
|
+
std::call_once(s_hermesLoading, []() {
|
|
57
|
+
VerifyElseCrashSz(!s_hermesModule, "Invalid state: \"hermes.dll\" being loaded again.");
|
|
58
|
+
|
|
59
|
+
s_hermesModule = LoadLibrary(L"hermes.dll");
|
|
60
|
+
VerifyElseCrashSz(s_hermesModule, "Could not load \"hermes.dll\"");
|
|
61
|
+
|
|
62
|
+
s_makeHermesRuntime =
|
|
63
|
+
reinterpret_cast<decltype(s_makeHermesRuntime)>(GetProcAddress(s_hermesModule, makeHermesRuntimeSymbol));
|
|
64
|
+
VerifyElseCrash(s_makeHermesRuntime);
|
|
65
|
+
|
|
66
|
+
s_enableSamplingProfiler = reinterpret_cast<decltype(s_enableSamplingProfiler)>(
|
|
67
|
+
GetProcAddress(s_hermesModule, enableSamlingProfilerSymbol));
|
|
68
|
+
VerifyElseCrash(s_enableSamplingProfiler);
|
|
69
|
+
|
|
70
|
+
s_disableSamplingProfiler = reinterpret_cast<decltype(s_disableSamplingProfiler)>(
|
|
71
|
+
GetProcAddress(s_hermesModule, disableSamlingProfilerSymbol));
|
|
72
|
+
VerifyElseCrash(s_disableSamplingProfiler);
|
|
73
|
+
|
|
74
|
+
s_dumpSampledTraceToFile = reinterpret_cast<decltype(s_dumpSampledTraceToFile)>(
|
|
75
|
+
GetProcAddress(s_hermesModule, dumpSampledTraceToFileSymbol));
|
|
76
|
+
VerifyElseCrash(s_dumpSampledTraceToFile);
|
|
77
|
+
|
|
78
|
+
s_makeHermesRuntimeWithWER = reinterpret_cast<decltype(s_makeHermesRuntimeWithWER)>(
|
|
79
|
+
GetProcAddress(s_hermesModule, makeHermesRuntimeWithWERSymbol));
|
|
80
|
+
VerifyElseCrash(s_makeHermesRuntimeWithWER);
|
|
81
|
+
|
|
82
|
+
s_hermesCrashHandler =
|
|
83
|
+
reinterpret_cast<decltype(s_hermesCrashHandler)>(GetProcAddress(s_hermesModule, hermesCrashHandlerSymbol));
|
|
84
|
+
VerifyElseCrash(s_hermesCrashHandler);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntime(const hermes::vm::RuntimeConfig &runtimeConfig) {
|
|
89
|
+
EnsureHermesLoaded();
|
|
90
|
+
return s_makeHermesRuntime(runtimeConfig);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void enableSamplingProfiler() {
|
|
94
|
+
EnsureHermesLoaded();
|
|
95
|
+
s_enableSamplingProfiler();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void disableSamplingProfiler() {
|
|
99
|
+
EnsureHermesLoaded();
|
|
100
|
+
s_disableSamplingProfiler();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void dumpSampledTraceToFile(const std::string &fileName) {
|
|
104
|
+
EnsureHermesLoaded();
|
|
105
|
+
s_dumpSampledTraceToFile(fileName);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeWithWER() {
|
|
109
|
+
EnsureHermesLoaded();
|
|
110
|
+
return s_makeHermesRuntimeWithWER();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void hermesCrashHandler(facebook::hermes::HermesRuntime &runtime, int fileDescriptor) {
|
|
114
|
+
EnsureHermesLoaded();
|
|
115
|
+
s_hermesCrashHandler(runtime, fileDescriptor);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
} // namespace Microsoft::ReactNative::HermesShim
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <hermes/hermes_win.h>
|
|
7
|
+
|
|
8
|
+
//! We do not package hermes.dll for projects that do not require it. We cannot
|
|
9
|
+
//! use pure delay-loading to achieve this, since WACK will detect the
|
|
10
|
+
//! non-present DLL. Functions in this namespace shim to the Hermes DLL via
|
|
11
|
+
//! GetProcAddress.
|
|
12
|
+
namespace Microsoft::ReactNative::HermesShim {
|
|
13
|
+
|
|
14
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntime(const hermes::vm::RuntimeConfig &runtimeConfig);
|
|
15
|
+
void enableSamplingProfiler();
|
|
16
|
+
void disableSamplingProfiler();
|
|
17
|
+
void dumpSampledTraceToFile(const std::string &fileName);
|
|
18
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> makeHermesRuntimeWithWER();
|
|
19
|
+
void hermesCrashHandler(facebook::hermes::HermesRuntime &runtime, int fileDescriptor);
|
|
20
|
+
|
|
21
|
+
} // namespace Microsoft::ReactNative::HermesShim
|
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
|
|
4
4
|
#include "pch.h"
|
|
5
5
|
|
|
6
|
+
#ifdef HERMES_ENABLE_DEBUGGER
|
|
7
|
+
|
|
6
8
|
#include <folly/json.h>
|
|
7
9
|
#include <tracing/tracing.h>
|
|
8
10
|
#include "InspectorPackagerConnection.h"
|
|
9
11
|
|
|
12
|
+
namespace facebook {
|
|
13
|
+
namespace react {
|
|
14
|
+
IDestructible::~IDestructible() {}
|
|
15
|
+
} // namespace react
|
|
16
|
+
} // namespace facebook
|
|
17
|
+
|
|
10
18
|
namespace Microsoft::ReactNative {
|
|
11
19
|
|
|
12
20
|
namespace {
|
|
@@ -72,16 +80,35 @@ struct InspectorProtocol {
|
|
|
72
80
|
}
|
|
73
81
|
|
|
74
82
|
static folly::dynamic constructGetPagesResponsePayloadForPackager(
|
|
75
|
-
const std::vector<facebook::react::
|
|
83
|
+
const std::vector<facebook::react::InspectorPage2> &pages,
|
|
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,
|
|
76
102
|
InspectorPackagerConnection::BundleStatus bundleStatus) {
|
|
77
103
|
folly::dynamic payload = folly::dynamic::array;
|
|
78
|
-
for (
|
|
104
|
+
for (int p = 0; p < pages->size(); p++) {
|
|
105
|
+
const facebook::react::InspectorPage2 page = pages->getPage(p);
|
|
79
106
|
folly::dynamic pageDyn = folly::dynamic::object;
|
|
80
107
|
pageDyn["id"] = page.id;
|
|
81
108
|
pageDyn["title"] = page.title;
|
|
82
109
|
pageDyn["vm"] = page.vm;
|
|
83
110
|
|
|
84
|
-
pageDyn["isLastBundleDownloadSuccess"] = bundleStatus.
|
|
111
|
+
pageDyn["isLastBundleDownloadSuccess"] = bundleStatus.m_isLastDownloadSucess;
|
|
85
112
|
pageDyn["bundleUpdateTimestamp"] = bundleStatus.m_updateTimestamp;
|
|
86
113
|
|
|
87
114
|
payload.push_back(pageDyn);
|
|
@@ -89,14 +116,14 @@ struct InspectorProtocol {
|
|
|
89
116
|
return payload;
|
|
90
117
|
}
|
|
91
118
|
|
|
92
|
-
static folly::dynamic constructVMResponsePayloadForPackager(
|
|
119
|
+
static folly::dynamic constructVMResponsePayloadForPackager(int64_t pageId, std::string &&messageFromVM) {
|
|
93
120
|
folly::dynamic payload = folly::dynamic::object;
|
|
94
121
|
payload[InspectorProtocol::Message_eventName_wrappedEvent] = messageFromVM;
|
|
95
122
|
payload[InspectorProtocol::Message_PAGEID] = pageId;
|
|
96
123
|
return payload;
|
|
97
124
|
}
|
|
98
125
|
|
|
99
|
-
static folly::dynamic constructVMResponsePayloadOnDisconnectForPackager(
|
|
126
|
+
static folly::dynamic constructVMResponsePayloadOnDisconnectForPackager(int64_t pageId) {
|
|
100
127
|
folly::dynamic payload = folly::dynamic::object;
|
|
101
128
|
payload[InspectorProtocol::Message_PAGEID] = pageId;
|
|
102
129
|
return payload;
|
|
@@ -105,7 +132,7 @@ struct InspectorProtocol {
|
|
|
105
132
|
|
|
106
133
|
} // namespace
|
|
107
134
|
|
|
108
|
-
RemoteConnection::RemoteConnection(
|
|
135
|
+
RemoteConnection::RemoteConnection(int64_t pageId, const InspectorPackagerConnection &packagerConnection)
|
|
109
136
|
: m_packagerConnection(packagerConnection), m_pageId(pageId) {}
|
|
110
137
|
|
|
111
138
|
void RemoteConnection::onMessage(std::string message) {
|
|
@@ -125,6 +152,26 @@ void RemoteConnection::onDisconnect() {
|
|
|
125
152
|
m_packagerConnection.sendMessageToPackager(std::move(responsestr));
|
|
126
153
|
}
|
|
127
154
|
|
|
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
|
+
|
|
128
175
|
winrt::fire_and_forget InspectorPackagerConnection::sendMessageToPackagerAsync(std::string &&message) const {
|
|
129
176
|
std::string message_(std::move(message));
|
|
130
177
|
co_await winrt::resume_background();
|
|
@@ -136,7 +183,7 @@ void InspectorPackagerConnection::sendMessageToPackager(std::string &&message) c
|
|
|
136
183
|
sendMessageToPackagerAsync(std::move(message));
|
|
137
184
|
}
|
|
138
185
|
|
|
139
|
-
void InspectorPackagerConnection::sendMessageToVM(
|
|
186
|
+
void InspectorPackagerConnection::sendMessageToVM(int64_t pageId, std::string &&message) {
|
|
140
187
|
m_localConnections[pageId]->sendMessage(std::move(message));
|
|
141
188
|
}
|
|
142
189
|
|
|
@@ -167,62 +214,59 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
167
214
|
m_packagerWebSocketConnection->SetOnConnect(
|
|
168
215
|
[]() { facebook::react::tracing::log("Inspector: Websocket connection succeeded."); });
|
|
169
216
|
|
|
170
|
-
m_packagerWebSocketConnection->SetOnMessage(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
m_packagerWebSocketConnection->SetOnMessage(
|
|
218
|
+
[self = shared_from_this()](size_t /*length*/, const std::string &message, bool isBinary) {
|
|
219
|
+
assert(!isBinary && "We don't expect any binary messages !");
|
|
220
|
+
folly::dynamic messageDyn = folly::parseJson(message);
|
|
221
|
+
|
|
222
|
+
InspectorProtocol::EventType eventType = InspectorProtocol::getEventType(messageDyn);
|
|
223
|
+
switch (eventType) {
|
|
224
|
+
case InspectorProtocol::EventType::GetPages: {
|
|
225
|
+
std::unique_ptr<facebook::react::IInspectorPages> inspectorPages = facebook::react::getInspectorPages();
|
|
226
|
+
folly::dynamic response = InspectorProtocol::constructResponseForPackager(
|
|
227
|
+
InspectorProtocol::EventType::GetPages,
|
|
228
|
+
InspectorProtocol::constructGetPagesResponsePayloadForPackager(
|
|
229
|
+
std::move(inspectorPages), self->m_bundleStatusProvider->getBundleStatus()));
|
|
230
|
+
|
|
231
|
+
std::string responsestr = folly::toJson(response);
|
|
232
|
+
self->sendMessageToPackager(std::move(responsestr));
|
|
233
|
+
} break;
|
|
234
|
+
|
|
235
|
+
case InspectorProtocol::EventType::WrappedEvent: {
|
|
236
|
+
folly::dynamic payload = messageDyn[InspectorProtocol::Message_PAYLOAD];
|
|
237
|
+
int64_t pageId = payload[InspectorProtocol::Message_PAGEID].asInt();
|
|
238
|
+
|
|
239
|
+
if (self->m_localConnections.find(pageId) == self->m_localConnections.end()) {
|
|
240
|
+
break;
|
|
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;
|
|
195
268
|
}
|
|
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
|
-
});
|
|
269
|
+
});
|
|
226
270
|
|
|
227
271
|
Microsoft::React::Networking::IWebSocketResource::Protocols protocols;
|
|
228
272
|
Microsoft::React::Networking::IWebSocketResource::Options options;
|
|
@@ -232,3 +276,5 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
232
276
|
}
|
|
233
277
|
|
|
234
278
|
} // namespace Microsoft::ReactNative
|
|
279
|
+
|
|
280
|
+
#endif
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#pragma once
|
|
5
5
|
|
|
6
|
+
#include <InspectorProxy.h>
|
|
6
7
|
#include <Networking/WinRTWebSocketResource.h>
|
|
7
8
|
#include <jsinspector/InspectorInterfaces.h>
|
|
8
9
|
|
|
@@ -15,12 +16,12 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
15
16
|
|
|
16
17
|
class BundleStatus {
|
|
17
18
|
public:
|
|
18
|
-
bool
|
|
19
|
+
bool m_isLastDownloadSucess;
|
|
19
20
|
int64_t m_updateTimestamp = -1;
|
|
20
21
|
|
|
21
|
-
BundleStatus(bool
|
|
22
|
-
:
|
|
23
|
-
BundleStatus() :
|
|
22
|
+
BundleStatus(bool isLastDownloadSucess, long updateTimestamp)
|
|
23
|
+
: m_isLastDownloadSucess(isLastDownloadSucess), m_updateTimestamp(updateTimestamp) {}
|
|
24
|
+
BundleStatus() : m_isLastDownloadSucess(false), m_updateTimestamp(-1) {}
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
struct IBundleStatusProvider {
|
|
@@ -31,16 +32,16 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
31
32
|
|
|
32
33
|
private:
|
|
33
34
|
friend class RemoteConnection;
|
|
35
|
+
friend class RemoteConnection2;
|
|
34
36
|
|
|
35
37
|
winrt::fire_and_forget sendMessageToPackagerAsync(std::string &&message) const;
|
|
36
38
|
void sendMessageToPackager(std::string &&message) const;
|
|
37
39
|
|
|
38
40
|
// Note:: VM side Inspector processes the messages asynchronousely in a sequential executor with dedicated thread.
|
|
39
41
|
// Hence, we don't bother invoking the inspector asynchronously.
|
|
40
|
-
void sendMessageToVM(
|
|
42
|
+
void sendMessageToVM(int64_t pageId, std::string &&message);
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
std::unordered_map<int32_t, std::unique_ptr<facebook::react::ILocalConnection>> m_localConnections;
|
|
44
|
+
std::unordered_map<int64_t, std::unique_ptr<facebook::react::ILocalConnection>> m_localConnections;
|
|
44
45
|
std::shared_ptr<Microsoft::React::Networking::WinRTWebSocketResource> m_packagerWebSocketConnection;
|
|
45
46
|
std::shared_ptr<IBundleStatusProvider> m_bundleStatusProvider;
|
|
46
47
|
std::string m_url;
|
|
@@ -48,12 +49,23 @@ class InspectorPackagerConnection final : public std::enable_shared_from_this<In
|
|
|
48
49
|
|
|
49
50
|
class RemoteConnection final : public facebook::react::IRemoteConnection {
|
|
50
51
|
public:
|
|
51
|
-
RemoteConnection(
|
|
52
|
+
RemoteConnection(int64_t pageId, const InspectorPackagerConnection &packagerConnection);
|
|
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);
|
|
52
64
|
void onMessage(std::string message) override;
|
|
53
65
|
void onDisconnect() override;
|
|
54
66
|
|
|
55
67
|
private:
|
|
56
|
-
|
|
68
|
+
int64_t m_pageId;
|
|
57
69
|
const InspectorPackagerConnection &m_packagerConnection;
|
|
58
70
|
};
|
|
59
71
|
|