mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fork jsinspector as jsinspector-modern (#39288)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39288 Forks `ReactCommon/jsinspector` → `ReactCommon/jsinspector-modern`. The Gradle, CocoaPods and Buck builds of React Native have been updated to use `jsinspector` everywhere (outside of `ReactCommon/hermes/inspector`, which is itself dead code as of D48897203). The code in `ReactCommon/jsinspector` is thus deprecated and unused in the open source build, and will be deleted in an upcoming diff (likely before the 0.73 cut). Changelog: [Internal] Reviewed By: blakef Differential Revision: D48966244 fbshipit-source-id: db81739da83ef9be73690d95d010065e3b3441c7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
79b293ea33
commit
a04a91838f
@@ -9,7 +9,7 @@
|
||||
|
||||
#if RCT_DEV || RCT_REMOTE_PROFILE
|
||||
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
#import <React/RCTDefines.h>
|
||||
#import <React/RCTInspectorPackagerConnection.h>
|
||||
@@ -17,6 +17,7 @@
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
using namespace facebook::react::jsinspector_modern;
|
||||
|
||||
// This is a port of the Android impl, at
|
||||
// react-native-github/ReactAndroid/src/main/java/com/facebook/react/bridge/Inspector.java
|
||||
@@ -57,7 +58,7 @@ class RemoteConnection : public IRemoteConnection {
|
||||
|
||||
static IInspector *getInstance()
|
||||
{
|
||||
return &facebook::react::getInspectorInstance();
|
||||
return &facebook::react::jsinspector_modern::getInspectorInstance();
|
||||
}
|
||||
|
||||
@implementation RCTInspector
|
||||
|
||||
@@ -246,7 +246,7 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa
|
||||
),
|
||||
new PrefabPreprocessingEntry(
|
||||
"jsinspector",
|
||||
new Pair("../ReactCommon/jsinspector/", "jsinspector/"),
|
||||
new Pair("../ReactCommon/jsinspector-modern/", "jsinspector-modern/"),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ add_react_common_subdir(jsc)
|
||||
add_react_common_subdir(jsi)
|
||||
add_react_common_subdir(butter)
|
||||
add_react_common_subdir(callinvoker)
|
||||
add_react_common_subdir(jsinspector)
|
||||
add_react_common_subdir(jsinspector-modern)
|
||||
add_react_common_subdir(hermes/executor)
|
||||
add_react_common_subdir(hermes/inspector-modern)
|
||||
add_react_common_subdir(react/renderer/runtimescheduler)
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace facebook::react {
|
||||
|
||||
namespace {
|
||||
|
||||
class RemoteConnection : public IRemoteConnection {
|
||||
class RemoteConnection : public jsinspector_modern::IRemoteConnection {
|
||||
public:
|
||||
RemoteConnection(jni::alias_ref<JRemoteConnection::javaobject> connection)
|
||||
: connection_(jni::make_global(connection)) {}
|
||||
@@ -56,7 +56,8 @@ void JRemoteConnection::onDisconnect() const {
|
||||
method(self());
|
||||
}
|
||||
|
||||
JLocalConnection::JLocalConnection(std::unique_ptr<ILocalConnection> connection)
|
||||
JLocalConnection::JLocalConnection(
|
||||
std::unique_ptr<jsinspector_modern::ILocalConnection> connection)
|
||||
: connection_(std::move(connection)) {}
|
||||
|
||||
void JLocalConnection::sendMessage(std::string message) {
|
||||
@@ -76,13 +77,13 @@ void JLocalConnection::registerNatives() {
|
||||
|
||||
jni::global_ref<JInspector::javaobject> JInspector::instance(
|
||||
jni::alias_ref<jclass>) {
|
||||
static auto instance =
|
||||
jni::make_global(newObjectCxxArgs(&getInspectorInstance()));
|
||||
static auto instance = jni::make_global(
|
||||
newObjectCxxArgs(&jsinspector_modern::getInspectorInstance()));
|
||||
return instance;
|
||||
}
|
||||
|
||||
jni::local_ref<jni::JArrayClass<JPage::javaobject>> JInspector::getPages() {
|
||||
std::vector<InspectorPage> pages = inspector_->getPages();
|
||||
std::vector<jsinspector_modern::InspectorPage> pages = inspector_->getPages();
|
||||
auto array = jni::JArrayClass<JPage::javaobject>::newArray(pages.size());
|
||||
for (size_t i = 0; i < pages.size(); i++) {
|
||||
(*array)[i] = JPage::create(pages[i].id, pages[i].title, pages[i].vm);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#ifdef WITH_INSPECTOR
|
||||
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
|
||||
@@ -40,7 +40,8 @@ class JLocalConnection : public jni::HybridClass<JLocalConnection> {
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/react/bridge/Inspector$LocalConnection;";
|
||||
|
||||
JLocalConnection(std::unique_ptr<ILocalConnection> connection);
|
||||
JLocalConnection(
|
||||
std::unique_ptr<jsinspector_modern::ILocalConnection> connection);
|
||||
|
||||
void sendMessage(std::string message);
|
||||
void disconnect();
|
||||
@@ -48,7 +49,7 @@ class JLocalConnection : public jni::HybridClass<JLocalConnection> {
|
||||
static void registerNatives();
|
||||
|
||||
private:
|
||||
std::unique_ptr<ILocalConnection> connection_;
|
||||
std::unique_ptr<jsinspector_modern::ILocalConnection> connection_;
|
||||
};
|
||||
|
||||
class JInspector : public jni::HybridClass<JInspector> {
|
||||
@@ -69,9 +70,10 @@ class JInspector : public jni::HybridClass<JInspector> {
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
JInspector(IInspector* inspector) : inspector_(inspector) {}
|
||||
JInspector(jsinspector_modern::IInspector* inspector)
|
||||
: inspector_(inspector) {}
|
||||
|
||||
IInspector* inspector_;
|
||||
jsinspector_modern::IInspector* inspector_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -30,8 +30,8 @@ namespace hermes {
|
||||
namespace inspector_modern {
|
||||
namespace chrome {
|
||||
|
||||
using ::facebook::react::ILocalConnection;
|
||||
using ::facebook::react::IRemoteConnection;
|
||||
using ::facebook::react::jsinspector_modern::ILocalConnection;
|
||||
using ::facebook::react::jsinspector_modern::IRemoteConnection;
|
||||
using ::folly::Unit;
|
||||
|
||||
namespace debugger = ::facebook::hermes::debugger;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include <hermes/hermes.h>
|
||||
#include <hermes/inspector-modern/RuntimeAdapter.h>
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace hermes {
|
||||
@@ -45,7 +45,8 @@ class INSPECTOR_EXPORT Connection {
|
||||
/// the debugger sent via send(). Replies and notifications from the debugger
|
||||
/// are sent back to the client via IRemoteConnection::onMessage.
|
||||
bool connect(
|
||||
std::unique_ptr<::facebook::react::IRemoteConnection> remoteConn);
|
||||
std::unique_ptr<::facebook::react::jsinspector_modern::IRemoteConnection>
|
||||
remoteConn);
|
||||
|
||||
/// disconnect disconnects this connection from the runtime's debugger
|
||||
bool disconnect();
|
||||
|
||||
+6
-5
@@ -8,16 +8,16 @@
|
||||
#include "ConnectionDemux.h"
|
||||
#include "Connection.h"
|
||||
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace hermes {
|
||||
namespace inspector_modern {
|
||||
namespace chrome {
|
||||
|
||||
using ::facebook::react::IInspector;
|
||||
using ::facebook::react::ILocalConnection;
|
||||
using ::facebook::react::IRemoteConnection;
|
||||
using ::facebook::react::jsinspector_modern::IInspector;
|
||||
using ::facebook::react::jsinspector_modern::ILocalConnection;
|
||||
using ::facebook::react::jsinspector_modern::IRemoteConnection;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -56,7 +56,8 @@ void LocalConnection::disconnect() {
|
||||
|
||||
} // namespace
|
||||
|
||||
ConnectionDemux::ConnectionDemux(facebook::react::IInspector &inspector)
|
||||
ConnectionDemux::ConnectionDemux(
|
||||
facebook::react::jsinspector_modern::IInspector &inspector)
|
||||
: globalInspector_(inspector),
|
||||
inspectedContexts_(std::make_shared<std::unordered_set<std::string>>()) {}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <hermes/inspector-modern/RuntimeAdapter.h>
|
||||
#include <hermes/inspector-modern/chrome/Connection.h>
|
||||
#include <hermes/inspector-modern/chrome/Registration.h>
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace hermes {
|
||||
@@ -31,7 +31,8 @@ namespace chrome {
|
||||
*/
|
||||
class ConnectionDemux {
|
||||
public:
|
||||
explicit ConnectionDemux(facebook::react::IInspector &inspector);
|
||||
explicit ConnectionDemux(
|
||||
facebook::react::jsinspector_modern::IInspector &inspector);
|
||||
~ConnectionDemux();
|
||||
|
||||
ConnectionDemux(const ConnectionDemux &) = delete;
|
||||
@@ -46,7 +47,7 @@ class ConnectionDemux {
|
||||
int addPage(std::shared_ptr<Connection> conn);
|
||||
void removePage(int pageId);
|
||||
|
||||
facebook::react::IInspector &globalInspector_;
|
||||
facebook::react::jsinspector_modern::IInspector &globalInspector_;
|
||||
|
||||
std::mutex mutex_;
|
||||
std::unordered_map<int, std::shared_ptr<Connection>> conns_;
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace chrome {
|
||||
namespace {
|
||||
|
||||
ConnectionDemux &demux() {
|
||||
static ConnectionDemux instance{facebook::react::getInspectorInstance()};
|
||||
static ConnectionDemux instance{
|
||||
facebook::react::jsinspector_modern::getInspectorInstance()};
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -15,16 +15,16 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <hermes/hermes.h>
|
||||
#include <hermes/inspector-modern/chrome/ConnectionDemux.h>
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace hermes {
|
||||
namespace inspector_modern {
|
||||
namespace chrome {
|
||||
|
||||
using ::facebook::react::IInspector;
|
||||
using ::facebook::react::InspectorPage;
|
||||
using ::facebook::react::IRemoteConnection;
|
||||
using ::facebook::react::jsinspector_modern::IInspector;
|
||||
using ::facebook::react::jsinspector_modern::InspectorPage;
|
||||
using ::facebook::react::jsinspector_modern::IRemoteConnection;
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -93,7 +93,8 @@ TEST(ConnectionDemuxTests, TestEnableDisable) {
|
||||
facebook::hermes::makeHermesRuntime());
|
||||
std::shared_ptr<HermesRuntime> runtime2(
|
||||
facebook::hermes::makeHermesRuntime());
|
||||
auto inspector = facebook::react::makeTestInspectorInstance();
|
||||
auto inspector =
|
||||
facebook::react::jsinspector_modern::makeTestInspectorInstance();
|
||||
|
||||
ConnectionDemux demux{*inspector};
|
||||
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@
|
||||
#include <folly/json.h>
|
||||
#include <glog/logging.h>
|
||||
#include <hermes/inspector-modern/RuntimeAdapter.h>
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
#include <jsinspector-modern/InspectorInterfaces.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace hermes {
|
||||
@@ -21,7 +21,7 @@ namespace inspector_modern {
|
||||
namespace chrome {
|
||||
|
||||
using namespace std::placeholders;
|
||||
using ::facebook::react::IRemoteConnection;
|
||||
using ::facebook::react::jsinspector_modern::IRemoteConnection;
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
Checks: '>
|
||||
clang-diagnostic-*,
|
||||
'
|
||||
InheritParentConfig: true
|
||||
...
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "InspectorInterfaces.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
// pure destructors in C++ are odd. You would think they don't want an
|
||||
// implementation, but in fact the linker requires one. Define them to be
|
||||
// empty so that people don't count on them for any particular behaviour.
|
||||
IDestructible::~IDestructible() {}
|
||||
ILocalConnection::~ILocalConnection() {}
|
||||
IRemoteConnection::~IRemoteConnection() {}
|
||||
IInspector::~IInspector() {}
|
||||
|
||||
namespace {
|
||||
|
||||
class InspectorImpl : public IInspector {
|
||||
public:
|
||||
int addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) override;
|
||||
void removePage(int pageId) override;
|
||||
|
||||
std::vector<InspectorPage> getPages() const override;
|
||||
std::unique_ptr<ILocalConnection> connect(
|
||||
int pageId,
|
||||
std::unique_ptr<IRemoteConnection> remote) override;
|
||||
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
int nextPageId_{1};
|
||||
std::unordered_map<int, std::tuple<std::string, std::string>> titles_;
|
||||
std::unordered_map<int, ConnectFunc> connectFuncs_;
|
||||
};
|
||||
|
||||
int InspectorImpl::addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) {
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
int pageId = nextPageId_++;
|
||||
titles_[pageId] = std::make_tuple(title, vm);
|
||||
connectFuncs_[pageId] = std::move(connectFunc);
|
||||
|
||||
return pageId;
|
||||
}
|
||||
|
||||
void InspectorImpl::removePage(int pageId) {
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
titles_.erase(pageId);
|
||||
connectFuncs_.erase(pageId);
|
||||
}
|
||||
|
||||
std::vector<InspectorPage> InspectorImpl::getPages() const {
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
std::vector<InspectorPage> inspectorPages;
|
||||
for (auto& it : titles_) {
|
||||
inspectorPages.push_back(InspectorPage{
|
||||
it.first, std::get<0>(it.second), std::get<1>(it.second)});
|
||||
}
|
||||
|
||||
return inspectorPages;
|
||||
}
|
||||
|
||||
std::unique_ptr<ILocalConnection> InspectorImpl::connect(
|
||||
int pageId,
|
||||
std::unique_ptr<IRemoteConnection> remote) {
|
||||
IInspector::ConnectFunc connectFunc;
|
||||
|
||||
{
|
||||
std::scoped_lock lock(mutex_);
|
||||
|
||||
auto it = connectFuncs_.find(pageId);
|
||||
if (it != connectFuncs_.end()) {
|
||||
connectFunc = it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return connectFunc ? connectFunc(std::move(remote)) : nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
IInspector& getInspectorInstance() {
|
||||
static InspectorImpl instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::unique_ptr<IInspector> makeTestInspectorInstance() {
|
||||
return std::make_unique<InspectorImpl>();
|
||||
}
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifndef JSINSPECTOR_EXPORT
|
||||
#ifdef _MSC_VER
|
||||
#ifdef CREATE_SHARED_LIBRARY
|
||||
#define JSINSPECTOR_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define JSINSPECTOR_EXPORT
|
||||
#endif // CREATE_SHARED_LIBRARY
|
||||
#else // _MSC_VER
|
||||
#define JSINSPECTOR_EXPORT __attribute__((visibility("default")))
|
||||
#endif // _MSC_VER
|
||||
#endif // !defined(JSINSPECTOR_EXPORT)
|
||||
|
||||
namespace facebook::react::jsinspector_modern {
|
||||
|
||||
class IDestructible {
|
||||
public:
|
||||
virtual ~IDestructible() = 0;
|
||||
};
|
||||
|
||||
struct InspectorPage {
|
||||
const int id;
|
||||
const std::string title;
|
||||
const std::string vm;
|
||||
};
|
||||
|
||||
/// IRemoteConnection allows the VM to send debugger messages to the client.
|
||||
class JSINSPECTOR_EXPORT IRemoteConnection : public IDestructible {
|
||||
public:
|
||||
virtual ~IRemoteConnection() = 0;
|
||||
virtual void onMessage(std::string message) = 0;
|
||||
virtual void onDisconnect() = 0;
|
||||
};
|
||||
|
||||
/// ILocalConnection allows the client to send debugger messages to the VM.
|
||||
class JSINSPECTOR_EXPORT ILocalConnection : public IDestructible {
|
||||
public:
|
||||
virtual ~ILocalConnection() = 0;
|
||||
virtual void sendMessage(std::string message) = 0;
|
||||
virtual void disconnect() = 0;
|
||||
};
|
||||
|
||||
/// IInspector tracks debuggable JavaScript targets (pages).
|
||||
class JSINSPECTOR_EXPORT IInspector : public IDestructible {
|
||||
public:
|
||||
using ConnectFunc = std::function<std::unique_ptr<ILocalConnection>(
|
||||
std::unique_ptr<IRemoteConnection>)>;
|
||||
|
||||
virtual ~IInspector() = 0;
|
||||
|
||||
/// addPage is called by the VM to add a page to the list of debuggable pages.
|
||||
virtual int addPage(
|
||||
const std::string& title,
|
||||
const std::string& vm,
|
||||
ConnectFunc connectFunc) = 0;
|
||||
|
||||
/// removePage is called by the VM to remove a page from the list of
|
||||
/// debuggable pages.
|
||||
virtual void removePage(int pageId) = 0;
|
||||
|
||||
/// getPages is called by the client to list all debuggable pages.
|
||||
virtual std::vector<InspectorPage> getPages() const = 0;
|
||||
|
||||
/// connect is called by the client to initiate a debugging session on the
|
||||
/// given page.
|
||||
virtual std::unique_ptr<ILocalConnection> connect(
|
||||
int pageId,
|
||||
std::unique_ptr<IRemoteConnection> remote) = 0;
|
||||
};
|
||||
|
||||
/// getInspectorInstance retrieves the singleton inspector that tracks all
|
||||
/// debuggable pages in this process.
|
||||
extern IInspector& getInspectorInstance();
|
||||
|
||||
/// makeTestInspectorInstance creates an independent inspector instance that
|
||||
/// should only be used in tests.
|
||||
extern std::unique_ptr<IInspector> makeTestInspectorInstance();
|
||||
|
||||
} // namespace facebook::react::jsinspector_modern
|
||||
@@ -131,7 +131,7 @@ def use_react_native! (
|
||||
end
|
||||
|
||||
pod 'React-jsiexecutor', :path => "#{prefix}/ReactCommon/jsiexecutor"
|
||||
pod 'React-jsinspector', :path => "#{prefix}/ReactCommon/jsinspector"
|
||||
pod 'React-jsinspector', :path => "#{prefix}/ReactCommon/jsinspector-modern"
|
||||
|
||||
pod 'React-callinvoker', :path => "#{prefix}/ReactCommon/callinvoker"
|
||||
pod 'React-runtimeexecutor', :path => "#{prefix}/ReactCommon/runtimeexecutor"
|
||||
|
||||
Reference in New Issue
Block a user