react-native-windows 0.80.1 → 0.80.6
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 +1 -1
- package/Microsoft.ReactNative/Fabric/Composition/DebuggerUIIsland.cpp +169 -0
- package/Microsoft.ReactNative/Fabric/Composition/DebuggerUIIsland.h +42 -0
- package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -1
- package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +60 -33
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +68 -1
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +9 -0
- package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +5 -3
- package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +6 -1
- package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +14 -1
- package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.cpp +75 -24
- package/Microsoft.ReactNative/Fabric/platform/react/threading/TaskDispatchThread.h +4 -25
- package/Microsoft.ReactNative/JsiApi.cpp +1 -1
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -0
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +3 -0
- package/Microsoft.ReactNative/ReactHost/DebuggerNotifications.h +54 -0
- package/Microsoft.ReactNative/ReactHost/React.h +11 -4
- package/Microsoft.ReactNative/ReactHost/ReactHost.cpp +195 -29
- package/Microsoft.ReactNative/ReactHost/ReactHost.h +22 -4
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +24 -5
- package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
- package/Microsoft.ReactNative/ReactRootView.cpp +108 -0
- package/Microsoft.ReactNative/ReactRootView.h +6 -0
- package/Microsoft.ReactNative/Views/DevMenu.cpp +1 -1
- package/Microsoft.ReactNative.Cxx/JSI/decorator.h +41 -0
- package/Microsoft.ReactNative.Cxx/JSI/jsi-inl.h +16 -0
- package/Microsoft.ReactNative.Cxx/JSI/jsi.cpp +125 -0
- package/Microsoft.ReactNative.Cxx/JSI/jsi.h +167 -1
- package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +1 -1
- package/Microsoft.ReactNative.Cxx/NodeApiJsiRuntime.cpp +110 -38
- package/Microsoft.ReactNative.Cxx/node-api/js_native_api.h +44 -31
- package/Microsoft.ReactNative.Cxx/node-api/js_native_api_types.h +13 -14
- package/Microsoft.ReactNative.Cxx/node-api/js_runtime_api.h +19 -4
- package/Microsoft.ReactNative.Cxx/node-api/node_api.h +270 -0
- package/Microsoft.ReactNative.Cxx/node-api/node_api_types.h +52 -0
- package/PropertySheets/Generated/PackageVersion.g.props +3 -3
- package/PropertySheets/JSEngine.props +1 -1
- package/PropertySheets/React.Cpp.props +2 -2
- package/ReactCommon/ReactCommon.vcxproj +18 -1
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +1 -1
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +4 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.cpp +23 -9
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.h +16 -0
- package/ReactCommon/cgmanifest.json +1 -1
- package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +2 -0
- package/Shared/DevServerHelper.h +13 -3
- package/Shared/DevSettings.h +7 -0
- package/Shared/DevSupportManager.cpp +79 -20
- package/Shared/DevSupportManager.h +7 -19
- package/Shared/Hermes/HermesRuntimeAgentDelegate.cpp +99 -0
- package/Shared/Hermes/HermesRuntimeAgentDelegate.h +81 -0
- package/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +263 -0
- package/Shared/Hermes/HermesRuntimeTargetDelegate.h +77 -0
- package/Shared/HermesRuntimeHolder.cpp +29 -111
- package/Shared/HermesRuntimeHolder.h +214 -32
- package/Shared/IDevSupportManager.h +5 -2
- package/Shared/Inspector/ReactInspectorPackagerConnectionDelegate.cpp +108 -0
- package/Shared/Inspector/ReactInspectorPackagerConnectionDelegate.h +19 -0
- package/Shared/Inspector/ReactInspectorThread.h +18 -0
- package/Shared/JSI/RuntimeHolder.h +5 -2
- package/Shared/OInstance.cpp +44 -27
- package/Shared/Shared.vcxitems +27 -17
- package/Shared/Shared.vcxitems.filters +33 -15
- package/package.json +5 -5
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +0 -78
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.h +0 -196
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jserrorhandler/JsErrorHandler.cpp +0 -429
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsitooling/react/runtime/JSRuntimeFactory.cpp +0 -45
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsitooling/react/runtime/JSRuntimeFactory.h +0 -91
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +0 -670
- package/Shared/InspectorPackagerConnection.cpp +0 -232
- package/Shared/InspectorPackagerConnection.h +0 -61
- /package/Shared/{HermesSamplingProfiler.cpp → Hermes/HermesSamplingProfiler.cpp} +0 -0
- /package/Shared/{HermesSamplingProfiler.h → Hermes/HermesSamplingProfiler.h} +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// This file must match the code in React Native folder:
|
|
12
|
+
// ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.cpp
|
|
13
|
+
// Unlike the code in React Native sources, this class delegates calls to Hermes C-based API.
|
|
14
|
+
// We use different namespace for this class comparing with the RN code.
|
|
15
|
+
|
|
16
|
+
#include "HermesRuntimeTargetDelegate.h"
|
|
17
|
+
#include <jsinspector-modern/RuntimeTarget.h>
|
|
18
|
+
#include <utility>
|
|
19
|
+
#include "HermesRuntimeAgentDelegate.h"
|
|
20
|
+
|
|
21
|
+
using namespace facebook::react::jsinspector_modern;
|
|
22
|
+
|
|
23
|
+
namespace Microsoft::ReactNative {
|
|
24
|
+
|
|
25
|
+
namespace {
|
|
26
|
+
|
|
27
|
+
const uint16_t HERMES_SAMPLING_FREQUENCY_HZ = 10000;
|
|
28
|
+
|
|
29
|
+
class HermesStackTraceWrapper : public StackTrace {
|
|
30
|
+
public:
|
|
31
|
+
explicit HermesStackTraceWrapper(HermesUniqueStackTrace &&hermesStackTrace)
|
|
32
|
+
: hermesStackTrace_{std::move(hermesStackTrace)} {}
|
|
33
|
+
|
|
34
|
+
HermesUniqueStackTrace &operator*() {
|
|
35
|
+
return hermesStackTrace_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
HermesUniqueStackTrace *operator->() {
|
|
39
|
+
return &hermesStackTrace_;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private:
|
|
43
|
+
HermesUniqueStackTrace hermesStackTrace_;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
} // namespace
|
|
47
|
+
|
|
48
|
+
HermesRuntimeTargetDelegate::HermesRuntimeTargetDelegate(std::shared_ptr<HermesRuntimeHolder> &&hermesRuntimeHolder)
|
|
49
|
+
: hermesRuntimeHolder_(std::move(hermesRuntimeHolder)),
|
|
50
|
+
hermesCdpDebugApi_(HermesInspectorApi::createCdpDebugApi(hermesRuntimeHolder_->getHermesRuntime())) {}
|
|
51
|
+
|
|
52
|
+
HermesRuntimeTargetDelegate::~HermesRuntimeTargetDelegate() = default;
|
|
53
|
+
|
|
54
|
+
hermes_cdp_debug_api HermesRuntimeTargetDelegate::getCdpDebugApi() {
|
|
55
|
+
return hermesCdpDebugApi_.get();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
std::unique_ptr<RuntimeAgentDelegate> HermesRuntimeTargetDelegate::createAgentDelegate(
|
|
59
|
+
FrontendChannel frontendChannel,
|
|
60
|
+
SessionState &sessionState,
|
|
61
|
+
std::unique_ptr<RuntimeAgentDelegate::ExportedState> previouslyExportedState,
|
|
62
|
+
const ExecutionContextDescription &executionContextDescription,
|
|
63
|
+
facebook::react::RuntimeExecutor runtimeExecutor) {
|
|
64
|
+
return std::unique_ptr<RuntimeAgentDelegate>(new HermesRuntimeAgentDelegate(
|
|
65
|
+
frontendChannel,
|
|
66
|
+
sessionState,
|
|
67
|
+
std::move(previouslyExportedState),
|
|
68
|
+
executionContextDescription,
|
|
69
|
+
hermesRuntimeHolder_->getHermesRuntime(),
|
|
70
|
+
*this,
|
|
71
|
+
std::move(runtimeExecutor)));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
void HermesRuntimeTargetDelegate::addConsoleMessage(facebook::jsi::Runtime &runtime, ConsoleMessage message) {
|
|
75
|
+
// Convert ConsoleAPIType to hermes_console_api_type
|
|
76
|
+
hermes_console_api_type type{};
|
|
77
|
+
switch (message.type) {
|
|
78
|
+
case ConsoleAPIType::kLog:
|
|
79
|
+
type = hermes_console_api_type_log;
|
|
80
|
+
break;
|
|
81
|
+
case ConsoleAPIType::kDebug:
|
|
82
|
+
type = hermes_console_api_type_debug;
|
|
83
|
+
break;
|
|
84
|
+
case ConsoleAPIType::kInfo:
|
|
85
|
+
type = hermes_console_api_type_info;
|
|
86
|
+
break;
|
|
87
|
+
case ConsoleAPIType::kError:
|
|
88
|
+
type = hermes_console_api_type_error;
|
|
89
|
+
break;
|
|
90
|
+
case ConsoleAPIType::kWarning:
|
|
91
|
+
type = hermes_console_api_type_warning;
|
|
92
|
+
break;
|
|
93
|
+
case ConsoleAPIType::kDir:
|
|
94
|
+
type = hermes_console_api_type_dir;
|
|
95
|
+
break;
|
|
96
|
+
case ConsoleAPIType::kDirXML:
|
|
97
|
+
type = hermes_console_api_type_dir_xml;
|
|
98
|
+
break;
|
|
99
|
+
case ConsoleAPIType::kTable:
|
|
100
|
+
type = hermes_console_api_type_table;
|
|
101
|
+
break;
|
|
102
|
+
case ConsoleAPIType::kTrace:
|
|
103
|
+
type = hermes_console_api_type_trace;
|
|
104
|
+
break;
|
|
105
|
+
case ConsoleAPIType::kStartGroup:
|
|
106
|
+
type = hermes_console_api_type_start_group;
|
|
107
|
+
break;
|
|
108
|
+
case ConsoleAPIType::kStartGroupCollapsed:
|
|
109
|
+
type = hermes_console_api_type_start_group_collapsed;
|
|
110
|
+
break;
|
|
111
|
+
case ConsoleAPIType::kEndGroup:
|
|
112
|
+
type = hermes_console_api_type_end_group;
|
|
113
|
+
break;
|
|
114
|
+
case ConsoleAPIType::kClear:
|
|
115
|
+
type = hermes_console_api_type_clear;
|
|
116
|
+
break;
|
|
117
|
+
case ConsoleAPIType::kAssert:
|
|
118
|
+
type = hermes_console_api_type_assert;
|
|
119
|
+
break;
|
|
120
|
+
case ConsoleAPIType::kTimeEnd:
|
|
121
|
+
type = hermes_console_api_type_time_end;
|
|
122
|
+
break;
|
|
123
|
+
case ConsoleAPIType::kCount:
|
|
124
|
+
type = hermes_console_api_type_count;
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
throw std::logic_error{"Unknown console message type"};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Create a jsi::Array from the vector of jsi::Values
|
|
131
|
+
facebook::jsi::Array argsArray(runtime, message.args.size());
|
|
132
|
+
for (size_t i = 0; i < message.args.size(); ++i) {
|
|
133
|
+
argsArray.setValueAtIndex(runtime, i, std::move(message.args[i]));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Store array as a temporary global property
|
|
137
|
+
// Using a property name that's unlikely to collide with user code
|
|
138
|
+
const char *propName = "__rnw_cdp_console_args";
|
|
139
|
+
runtime.global().setProperty(runtime, propName, argsArray);
|
|
140
|
+
|
|
141
|
+
// Convert stack trace to HermesUniqueStackTrace if available
|
|
142
|
+
HermesUniqueStackTrace hermesStackTrace{};
|
|
143
|
+
if (auto hermesStackTraceWrapper = dynamic_cast<HermesStackTraceWrapper *>(message.stackTrace.get())) {
|
|
144
|
+
hermesStackTrace = std::move(**hermesStackTraceWrapper);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Call C API with property name instead of serialized args
|
|
148
|
+
// The property will be cleaned up by the Hermes side
|
|
149
|
+
HermesInspectorApi::addConsoleMessage(
|
|
150
|
+
hermesCdpDebugApi_.get(), message.timestamp, type, propName, hermesStackTrace.get());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
bool HermesRuntimeTargetDelegate::supportsConsole() const {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
std::unique_ptr<StackTrace> HermesRuntimeTargetDelegate::captureStackTrace(
|
|
158
|
+
facebook::jsi::Runtime & /*runtime*/,
|
|
159
|
+
size_t /*framesToSkip*/) {
|
|
160
|
+
return std::make_unique<HermesStackTraceWrapper>(
|
|
161
|
+
HermesInspectorApi::captureStackTrace(hermesRuntimeHolder_->getHermesRuntime()));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void HermesRuntimeTargetDelegate::enableSamplingProfiler() {
|
|
165
|
+
HermesInspectorApi::enableSamplingProfiler(hermesRuntimeHolder_->getHermesRuntime());
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void HermesRuntimeTargetDelegate::disableSamplingProfiler() {
|
|
169
|
+
HermesInspectorApi::disableSamplingProfiler(hermesRuntimeHolder_->getHermesRuntime());
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
namespace {
|
|
173
|
+
|
|
174
|
+
// Helper class to hold state while reading the sampling profile
|
|
175
|
+
struct SamplingProfileReaderState {
|
|
176
|
+
std::vector<tracing::RuntimeSamplingProfile::Sample> samples;
|
|
177
|
+
std::vector<tracing::RuntimeSamplingProfile::SampleCallStackFrame> frames;
|
|
178
|
+
uint64_t timestamp;
|
|
179
|
+
uint64_t threadId;
|
|
180
|
+
bool hasCurrentSample;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
static void NAPI_CDECL onInfo(void *cb_data, size_t sample_count) {
|
|
184
|
+
SamplingProfileReaderState *readerState = reinterpret_cast<SamplingProfileReaderState *>(cb_data);
|
|
185
|
+
readerState->samples.reserve(sample_count);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Callback invoked for each sample
|
|
189
|
+
static void NAPI_CDECL onSample(void *cb_data, uint64_t timestamp, uint64_t threadId, size_t frame_count) {
|
|
190
|
+
SamplingProfileReaderState *readerState = reinterpret_cast<SamplingProfileReaderState *>(cb_data);
|
|
191
|
+
if (readerState->hasCurrentSample) {
|
|
192
|
+
// Save the previous sample
|
|
193
|
+
readerState->samples.emplace_back(readerState->timestamp, readerState->threadId, std::move(readerState->frames));
|
|
194
|
+
}
|
|
195
|
+
std::vector<tracing::RuntimeSamplingProfile::SampleCallStackFrame> frames;
|
|
196
|
+
frames.reserve(frame_count);
|
|
197
|
+
readerState->frames = std::move(frames);
|
|
198
|
+
readerState->timestamp = timestamp;
|
|
199
|
+
readerState->threadId = threadId;
|
|
200
|
+
readerState->hasCurrentSample = true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Callback invoked for each frame within a sample
|
|
204
|
+
static void NAPI_CDECL onFrame(
|
|
205
|
+
void *cb_data,
|
|
206
|
+
hermes_call_stack_frame_kind kind,
|
|
207
|
+
uint32_t scriptId,
|
|
208
|
+
const char *functionName,
|
|
209
|
+
size_t functionNameSize,
|
|
210
|
+
const char *scriptUrl,
|
|
211
|
+
size_t scriptUrlSize,
|
|
212
|
+
uint32_t lineNumber,
|
|
213
|
+
uint32_t columnNumber) {
|
|
214
|
+
SamplingProfileReaderState *readerState = reinterpret_cast<SamplingProfileReaderState *>(cb_data);
|
|
215
|
+
|
|
216
|
+
using Kind = tracing::RuntimeSamplingProfile::SampleCallStackFrame::Kind;
|
|
217
|
+
|
|
218
|
+
Kind frameKind;
|
|
219
|
+
switch (kind) {
|
|
220
|
+
case hermes_call_stack_frame_kind_js_function:
|
|
221
|
+
frameKind = Kind::JSFunction;
|
|
222
|
+
break;
|
|
223
|
+
case hermes_call_stack_frame_kind_native_function:
|
|
224
|
+
frameKind = Kind::NativeFunction;
|
|
225
|
+
break;
|
|
226
|
+
case hermes_call_stack_frame_kind_host_function:
|
|
227
|
+
frameKind = Kind::HostFunction;
|
|
228
|
+
break;
|
|
229
|
+
case hermes_call_stack_frame_kind_gc:
|
|
230
|
+
frameKind = Kind::GarbageCollector;
|
|
231
|
+
break;
|
|
232
|
+
default:
|
|
233
|
+
return; // Unknown frame kind, skip
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
std::string funcName(functionName, functionNameSize);
|
|
237
|
+
std::optional<std::string> url = scriptUrl ? std::optional{std::string(scriptUrl, scriptUrlSize)} : std::nullopt;
|
|
238
|
+
std::optional<uint32_t> line = lineNumber > 0 ? std::optional{lineNumber} : std::nullopt;
|
|
239
|
+
std::optional<uint32_t> column = columnNumber > 0 ? std::optional{columnNumber} : std::nullopt;
|
|
240
|
+
|
|
241
|
+
readerState->frames.emplace_back(frameKind, scriptId, std::move(funcName), std::move(url), line, column);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
} // namespace
|
|
245
|
+
|
|
246
|
+
tracing::RuntimeSamplingProfile HermesRuntimeTargetDelegate::collectSamplingProfile() {
|
|
247
|
+
// Create a readerState state to gather samples and frames
|
|
248
|
+
SamplingProfileReaderState readerState{};
|
|
249
|
+
|
|
250
|
+
// Collect the profile from Hermes
|
|
251
|
+
HermesUniqueSamplingProfile profile = HermesInspectorApi::collectSamplingProfile(
|
|
252
|
+
hermesRuntimeHolder_->getHermesRuntime(), &readerState, onInfo, onSample, onFrame);
|
|
253
|
+
|
|
254
|
+
if (readerState.hasCurrentSample) {
|
|
255
|
+
// Save the last sample
|
|
256
|
+
readerState.samples.emplace_back(readerState.timestamp, readerState.threadId, std::move(readerState.frames));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Return the complete profile with samples. Wrap the raw profile since it owns the strings.
|
|
260
|
+
return tracing::RuntimeSamplingProfile("Hermes", std::move(readerState.samples));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
} // namespace Microsoft::ReactNative
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// This file must match the code in React Native folder:
|
|
12
|
+
// ReactCommon/hermes/inspector-modern/chrome/HermesRuntimeTargetDelegate.h
|
|
13
|
+
// Unlike the code in React Native sources, this class delegates calls to Hermes C-based API.
|
|
14
|
+
// We use different namespace for this class comparing with the RN code.
|
|
15
|
+
|
|
16
|
+
#pragma once
|
|
17
|
+
|
|
18
|
+
#include <ReactCommon/RuntimeExecutor.h>
|
|
19
|
+
|
|
20
|
+
#include <cxxreact/MessageQueueThread.h>
|
|
21
|
+
#include <jsinspector-modern/ReactCdp.h>
|
|
22
|
+
|
|
23
|
+
#include <memory>
|
|
24
|
+
#include "HermesRuntimeHolder.h"
|
|
25
|
+
|
|
26
|
+
namespace Microsoft::ReactNative {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A RuntimeTargetDelegate that enables debugging a Hermes runtime over CDP.
|
|
30
|
+
*/
|
|
31
|
+
class HermesRuntimeTargetDelegate : public facebook::react::jsinspector_modern::RuntimeTargetDelegate {
|
|
32
|
+
public:
|
|
33
|
+
explicit HermesRuntimeTargetDelegate(std::shared_ptr<HermesRuntimeHolder> &&hermesRuntimeHolder);
|
|
34
|
+
|
|
35
|
+
~HermesRuntimeTargetDelegate() override;
|
|
36
|
+
|
|
37
|
+
// Our C-API specific helper method to be used internally instead of RN getCDPDebugAPI() private function.
|
|
38
|
+
hermes_cdp_debug_api getCdpDebugApi();
|
|
39
|
+
|
|
40
|
+
public: // RuntimeTargetDelegate implementation
|
|
41
|
+
std::unique_ptr<facebook::react::jsinspector_modern::RuntimeAgentDelegate> createAgentDelegate(
|
|
42
|
+
facebook::react::jsinspector_modern::FrontendChannel frontendChannel,
|
|
43
|
+
facebook::react::jsinspector_modern::SessionState &sessionState,
|
|
44
|
+
std::unique_ptr<facebook::react::jsinspector_modern::RuntimeAgentDelegate::ExportedState> previouslyExportedState,
|
|
45
|
+
const facebook::react::jsinspector_modern::ExecutionContextDescription &executionContextDescription,
|
|
46
|
+
facebook::react::RuntimeExecutor runtimeExecutor) override;
|
|
47
|
+
|
|
48
|
+
void addConsoleMessage(facebook::jsi::Runtime &runtime, facebook::react::jsinspector_modern::ConsoleMessage message)
|
|
49
|
+
override;
|
|
50
|
+
|
|
51
|
+
bool supportsConsole() const override;
|
|
52
|
+
|
|
53
|
+
std::unique_ptr<facebook::react::jsinspector_modern::StackTrace> captureStackTrace(
|
|
54
|
+
facebook::jsi::Runtime &runtime,
|
|
55
|
+
size_t framesToSkip) override;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Start sampling profiler.
|
|
59
|
+
*/
|
|
60
|
+
void enableSamplingProfiler() override;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Stop sampling profiler.
|
|
64
|
+
*/
|
|
65
|
+
void disableSamplingProfiler() override;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Return recorded sampling profile for the previous sampling session.
|
|
69
|
+
*/
|
|
70
|
+
facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile collectSamplingProfile() override;
|
|
71
|
+
|
|
72
|
+
private:
|
|
73
|
+
std::shared_ptr<HermesRuntimeHolder> hermesRuntimeHolder_;
|
|
74
|
+
const HermesUniqueCdpDebugApi hermesCdpDebugApi_;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} // namespace Microsoft::ReactNative
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
#include <jsinspector-modern/InspectorInterfaces.h>
|
|
15
15
|
#include <jsinspector-modern/tracing/InstanceTracingProfile.h>
|
|
16
16
|
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
|
17
|
+
#include <cstdio>
|
|
17
18
|
#include <mutex>
|
|
19
|
+
#include "Hermes/HermesRuntimeTargetDelegate.h"
|
|
18
20
|
#include "SafeLoadLibrary.h"
|
|
19
21
|
|
|
20
22
|
#define CRASH_ON_ERROR(result) VerifyElseCrash(result == napi_ok);
|
|
@@ -27,6 +29,12 @@ using namespace Microsoft::NodeApiJsi;
|
|
|
27
29
|
|
|
28
30
|
namespace Microsoft::ReactNative {
|
|
29
31
|
|
|
32
|
+
/*static*/ const hermes_inspector_vtable *HermesInspectorApi::vtable = nullptr;
|
|
33
|
+
|
|
34
|
+
void setHermesInspectorVTable(const hermes_inspector_vtable *vtable) {
|
|
35
|
+
HermesInspectorApi::vtable = vtable;
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
React::ReactPropertyId<React::ReactNonAbiValue<std::shared_ptr<HermesRuntimeHolder>>>
|
|
31
39
|
HermesRuntimeHolderProperty() noexcept {
|
|
32
40
|
static React::ReactPropertyId<React::ReactNonAbiValue<std::shared_ptr<HermesRuntimeHolder>>> propId{
|
|
@@ -36,9 +44,6 @@ HermesRuntimeHolderProperty() noexcept {
|
|
|
36
44
|
|
|
37
45
|
namespace {
|
|
38
46
|
|
|
39
|
-
int32_t NAPI_CDECL addInspectorPage(const char *title, const char *vm, void *connectFunc) noexcept;
|
|
40
|
-
void NAPI_CDECL removeInspectorPage(int32_t pageId) noexcept;
|
|
41
|
-
|
|
42
47
|
class HermesFuncResolver : public IFuncResolver {
|
|
43
48
|
public:
|
|
44
49
|
HermesFuncResolver() : libHandle_(LoadLibraryAsPeerFirst(L"hermes.dll")) {}
|
|
@@ -55,7 +60,9 @@ HermesApi &initHermesApi() noexcept {
|
|
|
55
60
|
static HermesFuncResolver funcResolver;
|
|
56
61
|
static HermesApi s_hermesApi(&funcResolver);
|
|
57
62
|
HermesApi::setCurrent(&s_hermesApi);
|
|
58
|
-
|
|
63
|
+
const hermes_inspector_vtable *inspectorVTable{};
|
|
64
|
+
s_hermesApi.hermes_get_inspector_vtable(&inspectorVTable);
|
|
65
|
+
setHermesInspectorVTable(inspectorVTable);
|
|
59
66
|
return s_hermesApi;
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -233,65 +240,6 @@ class HermesScriptCache {
|
|
|
233
240
|
std::shared_ptr<facebook::jsi::PreparedScriptStore> scriptStore_;
|
|
234
241
|
};
|
|
235
242
|
|
|
236
|
-
class HermesLocalConnection : public facebook::react::jsinspector_modern::ILocalConnection {
|
|
237
|
-
public:
|
|
238
|
-
HermesLocalConnection(
|
|
239
|
-
std::unique_ptr<facebook::react::jsinspector_modern::IRemoteConnection> remoteConnection,
|
|
240
|
-
void *connectFunc) noexcept {
|
|
241
|
-
CRASH_ON_ERROR(getHermesApi().hermes_create_local_connection(
|
|
242
|
-
connectFunc,
|
|
243
|
-
reinterpret_cast<hermes_remote_connection>(remoteConnection.release()),
|
|
244
|
-
&OnRemoteConnectionSendMessage,
|
|
245
|
-
&OnRemoteConnectionDisconnect,
|
|
246
|
-
&OnRemoteConnectionDelete,
|
|
247
|
-
nullptr,
|
|
248
|
-
&localConnection_));
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
~HermesLocalConnection() override {
|
|
252
|
-
CRASH_ON_ERROR(getHermesApi().hermes_delete_local_connection(localConnection_));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
void sendMessage(std::string message) {
|
|
256
|
-
CRASH_ON_ERROR(getHermesApi().hermes_local_connection_send_message(localConnection_, message.c_str()));
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
void disconnect() {
|
|
260
|
-
CRASH_ON_ERROR(getHermesApi().hermes_local_connection_disconnect(localConnection_));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private:
|
|
264
|
-
static void NAPI_CDECL OnRemoteConnectionSendMessage(hermes_remote_connection remoteConnection, const char *message) {
|
|
265
|
-
reinterpret_cast<facebook::react::jsinspector_modern::IRemoteConnection *>(remoteConnection)->onMessage(message);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
static void NAPI_CDECL OnRemoteConnectionDisconnect(hermes_remote_connection remoteConnection) {
|
|
269
|
-
reinterpret_cast<facebook::react::jsinspector_modern::IRemoteConnection *>(remoteConnection)->onDisconnect();
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
static void NAPI_CDECL OnRemoteConnectionDelete(void *remoteConnection, void * /*deleterData*/) {
|
|
273
|
-
delete reinterpret_cast<facebook::react::jsinspector_modern::IRemoteConnection *>(remoteConnection);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private:
|
|
277
|
-
hermes_local_connection localConnection_{};
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
int32_t NAPI_CDECL addInspectorPage(const char *title, const char *vm, void *connectFunc) noexcept {
|
|
281
|
-
return facebook::react::jsinspector_modern::getInspectorInstance().addPage(
|
|
282
|
-
title,
|
|
283
|
-
vm,
|
|
284
|
-
[connectFunc, hermesApi = HermesApi::current()](
|
|
285
|
-
std::unique_ptr<facebook::react::jsinspector_modern::IRemoteConnection> remoteConnection) {
|
|
286
|
-
HermesApi::Scope apiScope(hermesApi);
|
|
287
|
-
return std::make_unique<HermesLocalConnection>(std::move(remoteConnection), connectFunc);
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
void NAPI_CDECL removeInspectorPage(int32_t pageId) noexcept {
|
|
292
|
-
facebook::react::jsinspector_modern::getInspectorInstance().removePage(pageId);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
243
|
} // namespace
|
|
296
244
|
|
|
297
245
|
//==============================================================================
|
|
@@ -307,9 +255,9 @@ HermesRuntimeHolder::HermesRuntimeHolder(
|
|
|
307
255
|
m_preparedScriptStore(std::move(preparedScriptStore)) {}
|
|
308
256
|
|
|
309
257
|
HermesRuntimeHolder::~HermesRuntimeHolder() {
|
|
310
|
-
if (m_runtime) {
|
|
311
|
-
|
|
312
|
-
}
|
|
258
|
+
// if (m_runtime) {
|
|
259
|
+
// CRASH_ON_ERROR(getHermesApi().jsr_delete_runtime(m_runtime));
|
|
260
|
+
// }
|
|
313
261
|
}
|
|
314
262
|
|
|
315
263
|
void HermesRuntimeHolder::initRuntime() noexcept {
|
|
@@ -323,9 +271,6 @@ void HermesRuntimeHolder::initRuntime() noexcept {
|
|
|
323
271
|
CRASH_ON_ERROR(api.jsr_create_config(&config));
|
|
324
272
|
CRASH_ON_ERROR(api.hermes_config_enable_default_crash_handler(config, devSettings->enableDefaultCrashHandler));
|
|
325
273
|
CRASH_ON_ERROR(api.jsr_config_enable_inspector(config, devSettings->useDirectDebugger));
|
|
326
|
-
CRASH_ON_ERROR(api.jsr_config_set_inspector_runtime_name(config, devSettings->debuggerRuntimeName.c_str()));
|
|
327
|
-
CRASH_ON_ERROR(api.jsr_config_set_inspector_port(config, devSettings->debuggerPort));
|
|
328
|
-
CRASH_ON_ERROR(api.jsr_config_set_inspector_break_on_start(config, devSettings->debuggerBreakOnNextLine));
|
|
329
274
|
CRASH_ON_ERROR(api.jsr_config_set_explicit_microtasks(
|
|
330
275
|
config, facebook::react::ReactNativeFeatureFlags::enableBridgelessArchitecture()));
|
|
331
276
|
|
|
@@ -338,6 +283,7 @@ void HermesRuntimeHolder::initRuntime() noexcept {
|
|
|
338
283
|
jsr_runtime runtime{};
|
|
339
284
|
CRASH_ON_ERROR(api.jsr_create_runtime(config, &runtime));
|
|
340
285
|
CRASH_ON_ERROR(api.jsr_delete_config(config));
|
|
286
|
+
m_runtime = runtime;
|
|
341
287
|
|
|
342
288
|
napi_env env{};
|
|
343
289
|
CRASH_ON_ERROR(api.jsr_runtime_get_node_api_env(runtime, &env));
|
|
@@ -364,12 +310,13 @@ std::shared_ptr<facebook::jsi::Runtime> HermesRuntimeHolder::getRuntime() noexce
|
|
|
364
310
|
return m_jsiRuntime;
|
|
365
311
|
}
|
|
366
312
|
|
|
367
|
-
|
|
368
|
-
|
|
313
|
+
std::shared_ptr<facebook::react::jsinspector_modern::RuntimeTargetDelegate>
|
|
314
|
+
HermesRuntimeHolder::createRuntimeTargetDelegate() {
|
|
315
|
+
return std::make_shared<Microsoft::ReactNative::HermesRuntimeTargetDelegate>(shared_from_this());
|
|
369
316
|
}
|
|
370
317
|
|
|
371
|
-
void HermesRuntimeHolder::
|
|
372
|
-
|
|
318
|
+
void HermesRuntimeHolder::crashHandler(int fileDescriptor) noexcept {
|
|
319
|
+
CRASH_ON_ERROR(getHermesApi().hermes_dump_crash_data(m_runtime, fileDescriptor));
|
|
373
320
|
}
|
|
374
321
|
|
|
375
322
|
std::shared_ptr<HermesRuntimeHolder> HermesRuntimeHolder::loadFrom(
|
|
@@ -403,6 +350,10 @@ void HermesRuntimeHolder::removeFromProfiling() const noexcept {
|
|
|
403
350
|
CRASH_ON_ERROR(getHermesApi().hermes_sampling_profiler_dump_to_file(fileName.c_str()));
|
|
404
351
|
}
|
|
405
352
|
|
|
353
|
+
hermes_runtime HermesRuntimeHolder::getHermesRuntime() noexcept {
|
|
354
|
+
return reinterpret_cast<hermes_runtime>(m_runtime);
|
|
355
|
+
}
|
|
356
|
+
|
|
406
357
|
//==============================================================================
|
|
407
358
|
// HermesJSRuntime implementation
|
|
408
359
|
//==============================================================================
|
|
@@ -414,44 +365,11 @@ facebook::jsi::Runtime &HermesJSRuntime::getRuntime() noexcept {
|
|
|
414
365
|
return *m_holder->getRuntime();
|
|
415
366
|
}
|
|
416
367
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
bool HermesJSRuntime::supportsConsole() const {
|
|
424
|
-
return false;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
std::unique_ptr<facebook::react::jsinspector_modern::StackTrace> HermesJSRuntime::captureStackTrace(
|
|
428
|
-
facebook::jsi::Runtime &runtime,
|
|
429
|
-
size_t framesToSkip) {
|
|
430
|
-
return std::make_unique<facebook::react::jsinspector_modern::StackTrace>();
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
void HermesJSRuntime::enableSamplingProfiler() {
|
|
434
|
-
return; // [Windows TODO: stubbed implementation #14700]
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
void HermesJSRuntime::disableSamplingProfiler() {
|
|
438
|
-
return; // [Windows TODO: stubbed implementation #14700]
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile HermesJSRuntime::collectSamplingProfile() {
|
|
442
|
-
return facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile(
|
|
443
|
-
"stubbed_impl", {}); // [Windows TODO: stubbed implementation #14700]
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
std::unique_ptr<facebook::react::jsinspector_modern::RuntimeAgentDelegate> HermesJSRuntime::createAgentDelegate(
|
|
447
|
-
facebook::react::jsinspector_modern::FrontendChannel frontendChannel,
|
|
448
|
-
facebook::react::jsinspector_modern::SessionState &sessionState,
|
|
449
|
-
std::unique_ptr<facebook::react::jsinspector_modern::RuntimeAgentDelegate::ExportedState> previouslyExportedState,
|
|
450
|
-
const facebook::react::jsinspector_modern::ExecutionContextDescription &executionContextDescription,
|
|
451
|
-
facebook::react::RuntimeExecutor runtimeExecutor) {
|
|
452
|
-
(void)frontendChannel;
|
|
453
|
-
(void)sessionState;
|
|
454
|
-
return nullptr;
|
|
368
|
+
facebook::react::jsinspector_modern::RuntimeTargetDelegate &HermesJSRuntime::getRuntimeTargetDelegate() {
|
|
369
|
+
if (!m_runtimeTargetDelegate) {
|
|
370
|
+
m_runtimeTargetDelegate = m_holder->createRuntimeTargetDelegate();
|
|
371
|
+
}
|
|
372
|
+
return *m_runtimeTargetDelegate;
|
|
455
373
|
}
|
|
456
374
|
|
|
457
375
|
} // namespace Microsoft::ReactNative
|