diff --git a/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp b/ReactAndroid/src/main/jni/xreact/jni/JSLogging.cpp index bc83837f9..5fdc9a8b2 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 27756b665..2a38aaf31 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 84f017558..5abf1c94a 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