mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Inject some behavior from react/jni/ to react/
Summary: So, this makes it so a set of behaviors that require accessing java can be injected from the jni/ folder. The behaviors are logging, perf logging, log markers and loading script from assets. I'd argue that these should all actually be encapsulated by interfaces that are passed to the JSCExecutor/others (and I'd say that's regardless of whether they are injected from jni/ or not), but I wanted to stick to the least disruptive pattern for these changes. public Reviewed By: astreet Differential Revision: D2905168 fb-gh-sync-id: 7c8c16cb77b8fc3d42750dacc6574259ad512ac2
This commit is contained in:
committed by
facebook-github-bot-2
parent
2c8802f316
commit
75ca46e332
@@ -15,6 +15,7 @@
|
||||
#include "jni/JMessageQueueThread.h"
|
||||
#include "jni/OnLoad.h"
|
||||
#include <react/JSCHelpers.h>
|
||||
#include "Platform.h"
|
||||
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
#include <react/JSCTracing.h>
|
||||
@@ -31,9 +32,6 @@
|
||||
using fbsystrace::FbSystraceSection;
|
||||
#endif
|
||||
|
||||
// Add native performance markers support
|
||||
#include <react/JSCPerfLogging.h>
|
||||
|
||||
#ifdef WITH_FB_MEMORY_PROFILING
|
||||
#include <react/JSCMemory.h>
|
||||
#endif
|
||||
@@ -59,13 +57,6 @@ static JSValueRef nativeFlushQueueImmediate(
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef *exception);
|
||||
static JSValueRef nativeLoggingHook(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef *exception);
|
||||
static JSValueRef nativePerformanceNow(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
@@ -103,12 +94,13 @@ JSCExecutor::JSCExecutor(FlushImmediateCallback cb) :
|
||||
m_messageQueueThread = JMessageQueueThread::currentMessageQueueThread();
|
||||
s_globalContextRefToJSCExecutor[m_context] = this;
|
||||
installGlobalFunction(m_context, "nativeFlushQueueImmediate", nativeFlushQueueImmediate);
|
||||
installGlobalFunction(m_context, "nativeLoggingHook", nativeLoggingHook);
|
||||
installGlobalFunction(m_context, "nativePerformanceNow", nativePerformanceNow);
|
||||
installGlobalFunction(m_context, "nativeStartWorker", nativeStartWorker);
|
||||
installGlobalFunction(m_context, "nativePostMessageToWorker", nativePostMessageToWorker);
|
||||
installGlobalFunction(m_context, "nativeTerminateWorker", nativeTerminateWorker);
|
||||
|
||||
installGlobalFunction(m_context, "nativeLoggingHook", JSLogging::nativeHook);
|
||||
|
||||
#ifdef WITH_FB_JSC_TUNING
|
||||
configureJSCForAndroid();
|
||||
#endif
|
||||
@@ -116,7 +108,7 @@ JSCExecutor::JSCExecutor(FlushImmediateCallback cb) :
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
addNativeTracingHooks(m_context);
|
||||
addNativeProfilingHooks(m_context);
|
||||
addNativePerfLoggingHooks(m_context);
|
||||
PerfLogging::installNativeHooks(m_context);
|
||||
#endif
|
||||
|
||||
#ifdef WITH_FB_MEMORY_PROFILING
|
||||
@@ -164,17 +156,9 @@ std::string JSCExecutor::getDeviceCacheDir(){
|
||||
void JSCExecutor::executeApplicationScript(
|
||||
const std::string& script,
|
||||
const std::string& sourceURL) {
|
||||
JNIEnv* env = Environment::current();
|
||||
jclass markerClass = env->FindClass("com/facebook/react/bridge/ReactMarker");
|
||||
jmethodID logMarkerMethod = facebook::react::getLogMarkerMethod();
|
||||
jstring startStringMarker = env->NewStringUTF("executeApplicationScript_startStringConvert");
|
||||
jstring endStringMarker = env->NewStringUTF("executeApplicationScript_endStringConvert");
|
||||
|
||||
env->CallStaticVoidMethod(markerClass, logMarkerMethod, startStringMarker);
|
||||
ReactMarker::logMarker("executeApplicationScript_startStringConvert");
|
||||
String jsScript = String::createExpectingAscii(script);
|
||||
env->CallStaticVoidMethod(markerClass, logMarkerMethod, endStringMarker);
|
||||
env->DeleteLocalRef(startStringMarker);
|
||||
env->DeleteLocalRef(endStringMarker);
|
||||
ReactMarker::logMarker("executeApplicationScript_endStringConvert");
|
||||
|
||||
String jsSourceURL(sourceURL.c_str());
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
@@ -504,29 +488,6 @@ JSValueRef JSCExecutor::nativeTerminateWorker(
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativeLoggingHook(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[], JSValueRef *exception) {
|
||||
android_LogPriority logLevel = ANDROID_LOG_DEBUG;
|
||||
if (argumentCount > 1) {
|
||||
int level = (int) JSValueToNumber(ctx, arguments[1], NULL);
|
||||
// The lowest log level we get from JS is 0. We shift and cap it to be
|
||||
// in the range the Android logging method expects.
|
||||
logLevel = std::min(
|
||||
static_cast<android_LogPriority>(level + ANDROID_LOG_DEBUG),
|
||||
ANDROID_LOG_FATAL);
|
||||
}
|
||||
if (argumentCount > 0) {
|
||||
JSStringRef jsString = JSValueToStringCopy(ctx, arguments[0], NULL);
|
||||
String message = String::adopt(jsString);
|
||||
FBLOG_PRI(logLevel, "ReactNativeJS", "%s", message.str().c_str());
|
||||
}
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativePerformanceNow(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
|
||||
Reference in New Issue
Block a user