From 892231545bc50fcb59d1e5ae598a10b19ab95d60 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 18 Nov 2016 06:25:27 -0800 Subject: [PATCH] Remove duplicate definition of nativeLoggingHook Reviewed By: lexs Differential Revision: D4160267 fbshipit-source-id: 8e23ea355095f1f94610068010b7cdf385d69e40 --- .../src/main/jni/xreact/jni/JSLogging.cpp | 7 +++-- .../src/main/jni/xreact/jni/JSLogging.h | 2 ++ .../src/main/jni/xreact/jni/OnLoad.cpp | 26 ++----------------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp b/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp index bc83837f98..5fdc9a8b27 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp @@ -19,7 +19,7 @@ JSValueRef nativeLoggingHook( const JSValueRef arguments[], JSValueRef *exception) { android_LogPriority logLevel = ANDROID_LOG_DEBUG; if (argumentCount > 1) { - int level = (int) JSValueToNumber(ctx, arguments[1], NULL); + int level = (int)Value(ctx, arguments[1]).asNumber(); // 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( @@ -27,11 +27,10 @@ JSValueRef nativeLoggingHook( ANDROID_LOG_FATAL); } if (argumentCount > 0) { - JSStringRef jsString = JSValueToStringCopy(ctx, arguments[0], NULL); - String message = String::adopt(jsString); + String message = Value(ctx, arguments[0]).toString(); FBLOG_PRI(logLevel, "ReactNativeJS", "%s", message.str().c_str()); } - return JSValueMakeUndefined(ctx); + return Value::makeUndefined(ctx); } }}; diff --git a/ReactAndroid/src/main/jni/xreact/jni/JSLogging.h b/ReactAndroid/src/main/jni/xreact/jni/JSLogging.h index 27756b6650..2a38aaf313 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/JSLogging.h +++ b/ReactAndroid/src/main/jni/xreact/jni/JSLogging.h @@ -6,10 +6,12 @@ namespace facebook { namespace react { + JSValueRef nativeLoggingHook( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception); + }} diff --git a/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp index 84f0175580..5abf1c94a0 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp @@ -15,6 +15,7 @@ #include "ProxyExecutor.h" #include "WebWorkers.h" #include "JCallback.h" +#include "JSLogging.h" #ifdef WITH_INSPECTOR #include "JInspector.h" @@ -63,29 +64,6 @@ static std::string getApplicationPersistentDir() { return getApplicationDir("getFilesDir"); } -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(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, @@ -99,7 +77,7 @@ static JSValueRef nativePerformanceNow( struct timespec now; clock_gettime(CLOCK_MONOTONIC_RAW, &now); int64_t nano = now.tv_sec * NANOSECONDS_IN_SECOND + now.tv_nsec; - return JSValueMakeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND)); + return Value::makeNumber(ctx, (nano / (double)NANOSECONDS_IN_MILLISECOND)); } class JSCJavaScriptExecutorHolder : public HybridClass