mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Report Inspector page type to client (#42390)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42390 Changelog: [Internal] Add an optional mechanism for inspector pages to be registered with the "modern" or "legacy" type (defaulting to legacy). This is aligned with the inspector-proxy implementation of the `type` property in D50967795. NOTE: This mechanism is experimental, only takes effect if `InspectorPackagerConnection.cpp` is in use, and will likely evolve before the RN 0.74 branch cut. Reviewed By: huntie Differential Revision: D50967794 fbshipit-source-id: e7521267dfc0b0811c4d369e63f4f1756ce22d60
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9535526c14
commit
2c4756c8a3
@@ -31,7 +31,8 @@ class InspectorImpl : public IInspector {
|
||||
int addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) override;
|
||||
ConnectFunc connectFunc,
|
||||
InspectorPageType type) override;
|
||||
void removePage(int pageId) override;
|
||||
|
||||
std::vector<InspectorPageDescription> getPages() const override;
|
||||
@@ -49,7 +50,8 @@ class InspectorImpl : public IInspector {
|
||||
int id,
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc);
|
||||
ConnectFunc connectFunc,
|
||||
InspectorPageType type);
|
||||
operator InspectorPageDescription() const;
|
||||
|
||||
ConnectFunc getConnectFunc() const;
|
||||
@@ -59,6 +61,7 @@ class InspectorImpl : public IInspector {
|
||||
std::string title_;
|
||||
std::string vm_;
|
||||
ConnectFunc connectFunc_;
|
||||
InspectorPageType type_;
|
||||
};
|
||||
mutable std::mutex mutex_;
|
||||
int nextPageId_{1};
|
||||
@@ -70,14 +73,20 @@ InspectorImpl::Page::Page(
|
||||
int id,
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc)
|
||||
: id_(id), title_(title), vm_(vm), connectFunc_(std::move(connectFunc)) {}
|
||||
ConnectFunc connectFunc,
|
||||
InspectorPageType type)
|
||||
: id_(id),
|
||||
title_(title),
|
||||
vm_(vm),
|
||||
connectFunc_(std::move(connectFunc)),
|
||||
type_(type) {}
|
||||
|
||||
InspectorImpl::Page::operator InspectorPageDescription() const {
|
||||
return InspectorPageDescription{
|
||||
.id = id_,
|
||||
.title = title_,
|
||||
.vm = vm_,
|
||||
.type = type_,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -88,12 +97,13 @@ InspectorImpl::ConnectFunc InspectorImpl::Page::getConnectFunc() const {
|
||||
int InspectorImpl::addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) {
|
||||
ConnectFunc connectFunc,
|
||||
InspectorPageType type) {
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
int pageId = nextPageId_++;
|
||||
assert(pages_.count(pageId) == 0 && "Unexpected duplicate page ID");
|
||||
pages_.emplace(pageId, Page{pageId, title, vm, std::move(connectFunc)});
|
||||
pages_.emplace(pageId, Page{pageId, title, vm, std::move(connectFunc), type});
|
||||
|
||||
return pageId;
|
||||
}
|
||||
|
||||
@@ -31,10 +31,25 @@ class IDestructible {
|
||||
virtual ~IDestructible() = 0;
|
||||
};
|
||||
|
||||
enum class InspectorPageType {
|
||||
Legacy,
|
||||
Modern,
|
||||
};
|
||||
|
||||
inline const char* pageTypeToString(InspectorPageType type) {
|
||||
switch (type) {
|
||||
case InspectorPageType::Legacy:
|
||||
return "Legacy";
|
||||
case InspectorPageType::Modern:
|
||||
return "Modern";
|
||||
}
|
||||
}
|
||||
|
||||
struct InspectorPageDescription {
|
||||
const int id;
|
||||
const std::string title;
|
||||
const std::string vm;
|
||||
const InspectorPageType type;
|
||||
};
|
||||
|
||||
// Alias for backwards compatibility.
|
||||
@@ -82,7 +97,8 @@ class JSINSPECTOR_EXPORT IInspector : public IDestructible {
|
||||
virtual int addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) = 0;
|
||||
ConnectFunc connectFunc,
|
||||
InspectorPageType type = InspectorPageType::Legacy) = 0;
|
||||
|
||||
/// removePage is called by the VM to remove a page from the list of
|
||||
/// debuggable pages.
|
||||
|
||||
+2
-1
@@ -148,7 +148,8 @@ folly::dynamic InspectorPackagerConnection::Impl::pages() {
|
||||
|
||||
for (const auto& page : pages) {
|
||||
array.push_back(folly::dynamic::object("id", std::to_string(page.id))(
|
||||
"title", page.title + " [C++ connection]")("app", app_)("vm", page.vm));
|
||||
"title", page.title + " [C++ connection]")(
|
||||
"app", app_)("vm", page.vm)("type", pageTypeToString(page.type)));
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
+2
-1
@@ -216,7 +216,8 @@ TEST_F(InspectorPackagerConnectionTest, TestGetPages) {
|
||||
AtJsonPtr("/app", Eq("my-app")),
|
||||
AtJsonPtr("/title", Eq("mock-title [C++ connection]")),
|
||||
AtJsonPtr("/vm", Eq("mock-vm")),
|
||||
AtJsonPtr("/id", Eq(std::to_string(pageId))))}))))))
|
||||
AtJsonPtr("/id", Eq(std::to_string(pageId))),
|
||||
AtJsonPtr("/type", Eq("Legacy")))}))))))
|
||||
.RetiresOnSaturation();
|
||||
webSockets_[0]->getDelegate().didReceiveMessage(R"({
|
||||
"event": "getPages"
|
||||
|
||||
Reference in New Issue
Block a user