From 81c2f3b18903d3fcbed5595d46d3d01cef2f0180 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 7 Jun 2017 10:17:58 -0700 Subject: [PATCH] Cleanup Platform Reviewed By: dcaspi Differential Revision: D5185504 fbshipit-source-id: 4f7e9f9068598418b346a7370f6be241a0784b60 --- React/CxxBridge/RCTJSCHelpers.mm | 6 +-- .../src/main/jni/react/jni/OnLoad.cpp | 40 ++++++++++--------- ReactCommon/cxxreact/JSCExecutor.cpp | 6 +-- ReactCommon/cxxreact/Platform.cpp | 12 +++--- ReactCommon/cxxreact/Platform.h | 31 +++++++------- 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/React/CxxBridge/RCTJSCHelpers.mm b/React/CxxBridge/RCTJSCHelpers.mm index e9c379004..399488208 100644 --- a/React/CxxBridge/RCTJSCHelpers.mm +++ b/React/CxxBridge/RCTJSCHelpers.mm @@ -48,7 +48,7 @@ JSValueRef nativePerformanceNow( void RCTPrepareJSCExecutor() { ReactMarker::logTaggedMarker = [](const ReactMarker::ReactMarkerId, const char *tag) {}; - PerfLogging::installNativeHooks = RCTFBQuickPerformanceLoggerConfigureHooks; - JSNativeHooks::loggingHook = nativeLoggingHook; - JSNativeHooks::nowHook = nativePerformanceNow; + JSCNativeHooks::loggingHook = nativeLoggingHook; + JSCNativeHooks::nowHook = nativePerformanceNow; + JSCNativeHooks::installPerfHooks = RCTFBQuickPerformanceLoggerConfigureHooks; } diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index d86c971d1..b6236f584 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -1,30 +1,31 @@ // Copyright 2004-present Facebook. All Rights Reserved. -#include -#include -#include -#include +#include + #include #include #include +#include +#include +#include +#include +#include #include + #include "CatalystInstanceImpl.h" #include "CxxModuleWrapper.h" #include "JavaScriptExecutorHolder.h" -#include "JSCPerfLogging.h" -#include "ProxyExecutor.h" #include "JCallback.h" +#include "JSCPerfLogging.h" #include "JSLogging.h" +#include "ProxyExecutor.h" +#include "WritableNativeArray.h" +#include "WritableNativeMap.h" #ifdef WITH_INSPECTOR #include "JInspector.h" #endif -#include "WritableNativeMap.h" -#include "WritableNativeArray.h" - -#include - using namespace facebook::jni; namespace facebook { @@ -32,6 +33,7 @@ namespace react { namespace { +// TODO: can we avoid these wrapper classes, and instead specialize the logic in CatalystInstanceImpl class JSCJavaScriptExecutorHolder : public HybridClass { public: @@ -151,19 +153,15 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { gloginit::initialize(); // Inject some behavior into react/ ReactMarker::logTaggedMarker = logPerfMarker; - PerfLogging::installNativeHooks = addNativePerfLoggingHooks; - JSNativeHooks::loggingHook = nativeLoggingHook; - JSNativeHooks::nowHook = nativePerformanceNow; + JSCNativeHooks::loggingHook = nativeLoggingHook; + JSCNativeHooks::nowHook = nativePerformanceNow; + JSCNativeHooks::installPerfHooks = addNativePerfLoggingHooks; JSCJavaScriptExecutorHolder::registerNatives(); ProxyJavaScriptExecutorHolder::registerNatives(); CatalystInstanceImpl::registerNatives(); CxxModuleWrapperBase::registerNatives(); CxxModuleWrapper::registerNatives(); JCxxCallbackImpl::registerNatives(); - #ifdef WITH_INSPECTOR - JInspector::registerNatives(); - #endif - NativeArray::registerNatives(); ReadableNativeArray::registerNatives(); WritableNativeArray::registerNatives(); @@ -171,7 +169,11 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { ReadableNativeMap::registerNatives(); WritableNativeMap::registerNatives(); ReadableNativeMapKeySetIterator::registerNatives(); + + #ifdef WITH_INSPECTOR + JInspector::registerNatives(); + #endif }); } -}} +} } diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index b1044d7cd..337ed83f7 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -226,8 +226,8 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate"); installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook"); - installGlobalFunction(m_context, "nativeLoggingHook", JSNativeHooks::loggingHook); - installGlobalFunction(m_context, "nativePerformanceNow", JSNativeHooks::nowHook); + installGlobalFunction(m_context, "nativeLoggingHook", JSCNativeHooks::loggingHook); + installGlobalFunction(m_context, "nativePerformanceNow", JSCNativeHooks::nowHook); #if DEBUG installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate); @@ -242,7 +242,7 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { addNativeTracingLegacyHooks(m_context); #endif - PerfLogging::installNativeHooks(m_context); + JSCNativeHooks::installPerfHooks(m_context); #if defined(__APPLE__) || defined(WITH_JSC_EXTRA_TRACING) if (JSC_JSSamplingProfilerEnabled(m_context)) { diff --git a/ReactCommon/cxxreact/Platform.cpp b/ReactCommon/cxxreact/Platform.cpp index d95ea08c3..b1a069d48 100644 --- a/ReactCommon/cxxreact/Platform.cpp +++ b/ReactCommon/cxxreact/Platform.cpp @@ -11,20 +11,20 @@ namespace react { #endif namespace ReactMarker { -LogTaggedMarker logTaggedMarker = nullptr; +LogTaggedMarker logTaggedMarker = nullptr; void logMarker(const ReactMarkerId markerId) { logTaggedMarker(markerId, nullptr); } -}; -namespace PerfLogging { -InstallNativeHooks installNativeHooks = nullptr; -}; +} + +namespace JSCNativeHooks { -namespace JSNativeHooks { Hook loggingHook = nullptr; Hook nowHook = nullptr; +ConfigurationHook installPerfHooks = nullptr; + } #if __clang__ diff --git a/ReactCommon/cxxreact/Platform.h b/ReactCommon/cxxreact/Platform.h index 011d20401..800e1208f 100644 --- a/ReactCommon/cxxreact/Platform.h +++ b/ReactCommon/cxxreact/Platform.h @@ -14,6 +14,7 @@ namespace facebook { namespace react { namespace ReactMarker { + enum ReactMarkerId { NATIVE_REQUIRE_START, NATIVE_REQUIRE_STOP, @@ -29,23 +30,23 @@ extern LogTaggedMarker logTaggedMarker; extern void logMarker(const ReactMarkerId markerId); -}; +} -namespace PerfLogging { -using InstallNativeHooks = std::function; -extern InstallNativeHooks installNativeHooks; -}; +namespace JSCNativeHooks { + +using Hook = JSValueRef(*)( + JSContextRef ctx, + JSObjectRef function, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef *exception); +extern Hook loggingHook; +extern Hook nowHook; + +using ConfigurationHook = std::function; +extern ConfigurationHook installPerfHooks; -namespace JSNativeHooks { - using Hook = JSValueRef (*) ( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception); - extern Hook loggingHook; - extern Hook nowHook; } } }