mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
move page registration logic in to jsinspector
Reviewed By: pakoito Differential Revision: D6531199 fbshipit-source-id: ed1ae9e2f0c19e7656cd022e438693798320e55a
This commit is contained in:
parent
48019a0c2a
commit
bef7967f9a
@ -49,17 +49,9 @@ private:
|
|||||||
- (instancetype)initWithConnection:(std::unique_ptr<ILocalConnection>)connection;
|
- (instancetype)initWithConnection:(std::unique_ptr<ILocalConnection>)connection;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// Only safe to call with Custom JSC. Custom JSC check must occur earlier
|
|
||||||
// in the stack
|
|
||||||
static IInspector *getInstance()
|
static IInspector *getInstance()
|
||||||
{
|
{
|
||||||
static dispatch_once_t onceToken;
|
return &facebook::react::getInspectorInstance();
|
||||||
static IInspector *s_inspector;
|
|
||||||
dispatch_once(&onceToken, ^{
|
|
||||||
s_inspector = customJSCWrapper()->JSInspectorGetInstance();
|
|
||||||
});
|
|
||||||
|
|
||||||
return s_inspector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation RCTInspector
|
@implementation RCTInspector
|
||||||
|
@ -61,12 +61,8 @@ void JLocalConnection::registerNatives() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static IInspector* getInspectorInstance() {
|
|
||||||
return JSC_JSInspectorGetInstance(true /*useCustomJSC*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
jni::global_ref<JInspector::javaobject> JInspector::instance(jni::alias_ref<jclass>) {
|
jni::global_ref<JInspector::javaobject> JInspector::instance(jni::alias_ref<jclass>) {
|
||||||
static auto instance = jni::make_global(newObjectCxxArgs(getInspectorInstance()/*&Inspector::instance()*/));
|
static auto instance = jni::make_global(newObjectCxxArgs(&getInspectorInstance()));
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,11 +215,12 @@ namespace facebook {
|
|||||||
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "unknown").getString();
|
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "unknown").getString();
|
||||||
const std::string appId = m_jscConfig.getDefault("AppIdentity", "unknown").getString();
|
const std::string appId = m_jscConfig.getDefault("AppIdentity", "unknown").getString();
|
||||||
const std::string deviceId = m_jscConfig.getDefault("DeviceIdentity", "unknown").getString();
|
const std::string deviceId = m_jscConfig.getDefault("DeviceIdentity", "unknown").getString();
|
||||||
const std::function<bool()> checkIsInspectedRemote = [&](){
|
auto checkIsInspectedRemote = [ownerId, appId, deviceId]() {
|
||||||
return isNetworkInspected(ownerId, appId, deviceId);
|
return isNetworkInspected(ownerId, appId, deviceId);
|
||||||
};
|
};
|
||||||
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
|
|
||||||
pInspector->registerGlobalContext(ownerId, checkIsInspectedRemote, m_context);
|
auto& globalInspector = facebook::react::getInspectorInstance();
|
||||||
|
JSC_JSGlobalContextEnableDebugger(m_context, globalInspector, ownerId.c_str(), checkIsInspectedRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate");
|
installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate");
|
||||||
@ -340,8 +341,8 @@ namespace facebook {
|
|||||||
m_nativeModules.reset();
|
m_nativeModules.reset();
|
||||||
|
|
||||||
if (canUseInspector(context)) {
|
if (canUseInspector(context)) {
|
||||||
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
|
auto &globalInspector = facebook::react::getInspectorInstance();
|
||||||
pInspector->unregisterGlobalContext(context);
|
JSC_JSGlobalContextDisableDebugger(context, globalInspector);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSC_JSGlobalContextRelease(context);
|
JSC_JSGlobalContextRelease(context);
|
||||||
|
@ -117,7 +117,7 @@ private:
|
|||||||
folly::Optional<Object> m_callFunctionReturnResultAndFlushedQueueJS;
|
folly::Optional<Object> m_callFunctionReturnResultAndFlushedQueueJS;
|
||||||
|
|
||||||
void initOnJSVMThread() throw(JSException);
|
void initOnJSVMThread() throw(JSException);
|
||||||
bool isNetworkInspected(const std::string &owner, const std::string &app, const std::string &device);
|
static bool isNetworkInspected(const std::string &owner, const std::string &app, const std::string &device);
|
||||||
// This method is experimental, and may be modified or removed.
|
// This method is experimental, and may be modified or removed.
|
||||||
Value callFunctionSyncWithValue(
|
Value callFunctionSyncWithValue(
|
||||||
const std::string& module, const std::string& method, Value value);
|
const std::string& module, const std::string& method, Value value);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <JavaScriptCore/JavaScript.h>
|
#include <JavaScriptCore/JavaScript.h>
|
||||||
|
|
||||||
@ -32,7 +33,14 @@ namespace react {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JSC_IMPORT facebook::react::IInspector* JSInspectorGetInstance();
|
JSC_IMPORT void JSGlobalContextEnableDebugger(
|
||||||
|
JSGlobalContextRef ctx,
|
||||||
|
facebook::react::IInspector &globalInspector,
|
||||||
|
const char *title,
|
||||||
|
const std::function<bool()> &checkIsInspectedRemote);
|
||||||
|
JSC_IMPORT void JSGlobalContextDisableDebugger(
|
||||||
|
JSGlobalContextRef ctx,
|
||||||
|
facebook::react::IInspector &globalInspector);
|
||||||
|
|
||||||
// This is used to substitute an alternate JSC implementation for
|
// This is used to substitute an alternate JSC implementation for
|
||||||
// testing. These calls must all be ABI compatible with the standard JSC.
|
// testing. These calls must all be ABI compatible with the standard JSC.
|
||||||
@ -143,7 +151,8 @@ struct JSCWrapper {
|
|||||||
JSC_WRAPPER_METHOD(JSPokeSamplingProfiler);
|
JSC_WRAPPER_METHOD(JSPokeSamplingProfiler);
|
||||||
JSC_WRAPPER_METHOD(JSStartSamplingProfilingOnMainJSCThread);
|
JSC_WRAPPER_METHOD(JSStartSamplingProfilingOnMainJSCThread);
|
||||||
|
|
||||||
JSC_WRAPPER_METHOD(JSInspectorGetInstance);
|
JSC_WRAPPER_METHOD(JSGlobalContextEnableDebugger);
|
||||||
|
JSC_WRAPPER_METHOD(JSGlobalContextDisableDebugger);
|
||||||
|
|
||||||
JSC_WRAPPER_METHOD(configureJSCForIOS);
|
JSC_WRAPPER_METHOD(configureJSCForIOS);
|
||||||
|
|
||||||
|
@ -191,9 +191,13 @@ jsc_poison(JSObjectMakeArrayBufferWithBytesNoCopy JSObjectMakeTypedArray
|
|||||||
jsc_poison(JSSamplingProfilerEnabled JSPokeSamplingProfiler
|
jsc_poison(JSSamplingProfilerEnabled JSPokeSamplingProfiler
|
||||||
JSStartSamplingProfilingOnMainJSCThread)
|
JSStartSamplingProfilingOnMainJSCThread)
|
||||||
|
|
||||||
#define JSC_JSInspectorGetInstance(...) __jsc_bool_wrapper(JSInspectorGetInstance, __VA_ARGS__)
|
#define JSC_JSGlobalContextEnableDebugger(...) __jsc_wrapper(JSGlobalContextEnableDebugger, __VA_ARGS__)
|
||||||
// no need to poison JSInspectorGetInstance because it's not defined for System JSC / standard SDK header
|
// no need to poison JSGlobalContextEnableDebugger because it's not defined for System JSC / standard SDK header
|
||||||
// jsc_poison(JSInspectorGetInstance)
|
// jsc_poison(JSGlobalContextEnableDebugger)
|
||||||
|
|
||||||
|
#define JSC_JSGlobalContextDisableDebugger(...) __jsc_wrapper(JSGlobalContextDisableDebugger, __VA_ARGS__)
|
||||||
|
// no need to poison JSGlobalContextDisableDebugger because it's not defined for System JSC / standard SDK header
|
||||||
|
// jsc_poison(JSGlobalContextDisableDebugger)
|
||||||
|
|
||||||
|
|
||||||
#define JSC_configureJSCForIOS(...) __jsc_bool_wrapper(configureJSCForIOS, __VA_ARGS__)
|
#define JSC_configureJSCForIOS(...) __jsc_bool_wrapper(configureJSCForIOS, __VA_ARGS__)
|
||||||
|
@ -29,7 +29,8 @@ UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStringCreateWithUTF8CStringExpectAscii)
|
|||||||
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSPokeSamplingProfiler)
|
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSPokeSamplingProfiler)
|
||||||
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStartSamplingProfilingOnMainJSCThread)
|
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSStartSamplingProfilingOnMainJSCThread)
|
||||||
|
|
||||||
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSInspectorGetInstance)
|
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSGlobalContextEnableDebugger)
|
||||||
|
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(JSGlobalContextDisableDebugger)
|
||||||
|
|
||||||
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(configureJSCForIOS)
|
UNIMPLEMENTED_SYSTEM_JSC_FUNCTION(configureJSCForIOS)
|
||||||
|
|
||||||
@ -129,9 +130,12 @@ const JSCWrapper* systemJSCWrapper() {
|
|||||||
(decltype(&JSStartSamplingProfilingOnMainJSCThread))
|
(decltype(&JSStartSamplingProfilingOnMainJSCThread))
|
||||||
Unimplemented_JSStartSamplingProfilingOnMainJSCThread,
|
Unimplemented_JSStartSamplingProfilingOnMainJSCThread,
|
||||||
|
|
||||||
.JSInspectorGetInstance =
|
.JSGlobalContextEnableDebugger =
|
||||||
(decltype(&JSInspectorGetInstance))
|
(decltype(&JSGlobalContextEnableDebugger))
|
||||||
Unimplemented_JSInspectorGetInstance,
|
Unimplemented_JSGlobalContextEnableDebugger,
|
||||||
|
.JSGlobalContextDisableDebugger =
|
||||||
|
(decltype(&JSGlobalContextDisableDebugger))
|
||||||
|
Unimplemented_JSGlobalContextDisableDebugger,
|
||||||
|
|
||||||
.configureJSCForIOS =
|
.configureJSCForIOS =
|
||||||
(decltype(&configureJSCForIOS))Unimplemented_configureJSCForIOS,
|
(decltype(&configureJSCForIOS))Unimplemented_configureJSCForIOS,
|
||||||
|
@ -20,6 +20,7 @@ rn_xplat_cxx_library(
|
|||||||
"-fexceptions",
|
"-fexceptions",
|
||||||
"-std=c++1y",
|
"-std=c++1y",
|
||||||
],
|
],
|
||||||
|
fbandroid_preferred_linkage = "shared",
|
||||||
visibility = [
|
visibility = [
|
||||||
"PUBLIC",
|
"PUBLIC",
|
||||||
],
|
],
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
|
|
||||||
#include "InspectorInterfaces.h"
|
#include "InspectorInterfaces.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
@ -19,5 +22,80 @@ IDestructible::~IDestructible() { }
|
|||||||
ILocalConnection::~ILocalConnection() { }
|
ILocalConnection::~ILocalConnection() { }
|
||||||
IRemoteConnection::~IRemoteConnection() { }
|
IRemoteConnection::~IRemoteConnection() { }
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class InspectorImpl : public IInspector {
|
||||||
|
public:
|
||||||
|
int addPage(const std::string& title, 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::string> titles_;
|
||||||
|
std::unordered_map<int, ConnectFunc> connectFuncs_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int InspectorImpl::addPage(const std::string& title, ConnectFunc connectFunc) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
|
int pageId = nextPageId_++;
|
||||||
|
titles_[pageId] = title;
|
||||||
|
connectFuncs_[pageId] = std::move(connectFunc);
|
||||||
|
|
||||||
|
return pageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InspectorImpl::removePage(int pageId) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
|
titles_.erase(pageId);
|
||||||
|
connectFuncs_.erase(pageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<InspectorPage> InspectorImpl::getPages() const {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
|
std::vector<InspectorPage> inspectorPages;
|
||||||
|
for (auto& it : titles_) {
|
||||||
|
inspectorPages.push_back(InspectorPage{it.first, it.second});
|
||||||
|
}
|
||||||
|
|
||||||
|
return inspectorPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<ILocalConnection> InspectorImpl::connect(
|
||||||
|
int pageId,
|
||||||
|
std::unique_ptr<IRemoteConnection> remote) {
|
||||||
|
IInspector::ConnectFunc connectFunc;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> 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 react
|
||||||
|
} // namespace facebook
|
||||||
|
@ -18,7 +18,7 @@ namespace facebook {
|
|||||||
namespace react {
|
namespace react {
|
||||||
|
|
||||||
class IDestructible {
|
class IDestructible {
|
||||||
public:
|
public:
|
||||||
virtual ~IDestructible() = 0;
|
virtual ~IDestructible() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,29 +27,52 @@ struct InspectorPage {
|
|||||||
const std::string title;
|
const std::string title;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// IRemoteConnection allows the VM to send debugger messages to the client.
|
||||||
class IRemoteConnection : public IDestructible {
|
class IRemoteConnection : public IDestructible {
|
||||||
public:
|
public:
|
||||||
virtual ~IRemoteConnection() = 0;
|
virtual ~IRemoteConnection() = 0;
|
||||||
virtual void onMessage(std::string message) = 0;
|
virtual void onMessage(std::string message) = 0;
|
||||||
virtual void onDisconnect() = 0;
|
virtual void onDisconnect() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// ILocalConnection allows the client to send debugger messages to the VM.
|
||||||
class ILocalConnection : public IDestructible {
|
class ILocalConnection : public IDestructible {
|
||||||
public:
|
public:
|
||||||
virtual ~ILocalConnection() = 0;
|
virtual ~ILocalConnection() = 0;
|
||||||
virtual void sendMessage(std::string message) = 0;
|
virtual void sendMessage(std::string message) = 0;
|
||||||
virtual void disconnect() = 0;
|
virtual void disconnect() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: not destructible!
|
/// IInspector tracks debuggable JavaScript targets (pages).
|
||||||
class IInspector {
|
class IInspector {
|
||||||
public:
|
public:
|
||||||
virtual void registerGlobalContext(const std::string& title, const std::function<bool()> &checkIsInspectedRemote, void* ctx) = 0;
|
using ConnectFunc = std::function<std::unique_ptr<ILocalConnection>(
|
||||||
virtual void unregisterGlobalContext(void* ctx) = 0;
|
std::unique_ptr<IRemoteConnection>)>;
|
||||||
|
|
||||||
|
/// addPage is called by the VM to add a page to the list of debuggable pages.
|
||||||
|
virtual int addPage(const std::string& title, 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;
|
virtual std::vector<InspectorPage> getPages() const = 0;
|
||||||
virtual std::unique_ptr<ILocalConnection> connect(int pageId, std::unique_ptr<IRemoteConnection> remote) = 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 react
|
||||||
|
} // namespace facebook
|
||||||
|
Loading…
x
Reference in New Issue
Block a user