From e7a4b20d7567056ae6e718be90a29b4035158f7e Mon Sep 17 00:00:00 2001 From: Mike Armstrong Date: Tue, 8 Dec 2015 06:10:58 -0800 Subject: [PATCH] exceptions generated from incorrect arg usage on JSC trace and LegacyProfile functions Reviewed By: astreet Differential Revision: D2729015 fb-gh-sync-id: a3f56554ff6e77170e07aaf93934f93522b3a81b --- .../src/main/jni/react/JSCHelpers.cpp | 9 +++++ ReactAndroid/src/main/jni/react/JSCHelpers.h | 4 +++ .../src/main/jni/react/JSCLegacyProfiler.cpp | 12 +++++-- .../src/main/jni/react/JSCTracing.cpp | 35 +++++++++++++------ 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/JSCHelpers.cpp b/ReactAndroid/src/main/jni/react/JSCHelpers.cpp index b3ef3aa57..b1edc73dc 100644 --- a/ReactAndroid/src/main/jni/react/JSCHelpers.cpp +++ b/ReactAndroid/src/main/jni/react/JSCHelpers.cpp @@ -19,4 +19,13 @@ void installGlobalFunction( JSStringRelease(jsName); } +JSValueRef makeJSCException( + JSContextRef ctx, + const char* exception_text) { + JSStringRef message = JSStringCreateWithUTF8CString(exception_text); + JSValueRef exceptionString = JSValueMakeString(ctx, message); + JSStringRelease(message); + return JSValueToObject(ctx, exceptionString, NULL); +} + } } diff --git a/ReactAndroid/src/main/jni/react/JSCHelpers.h b/ReactAndroid/src/main/jni/react/JSCHelpers.h index 7209b2ce3..ba3f8525a 100644 --- a/ReactAndroid/src/main/jni/react/JSCHelpers.h +++ b/ReactAndroid/src/main/jni/react/JSCHelpers.h @@ -13,4 +13,8 @@ void installGlobalFunction( const char* name, JSObjectCallAsFunctionCallback callback); +JSValueRef makeJSCException( + JSContextRef ctx, + const char* exception_text); + } } diff --git a/ReactAndroid/src/main/jni/react/JSCLegacyProfiler.cpp b/ReactAndroid/src/main/jni/react/JSCLegacyProfiler.cpp index 5d2a7e499..74222c2ef 100644 --- a/ReactAndroid/src/main/jni/react/JSCLegacyProfiler.cpp +++ b/ReactAndroid/src/main/jni/react/JSCLegacyProfiler.cpp @@ -17,7 +17,11 @@ static JSValueRef nativeProfilerStart( const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) { - // Could raise an exception here. + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeProfilerStart: requires at least 1 argument"); + } return JSValueMakeUndefined(ctx); } @@ -35,7 +39,11 @@ static JSValueRef nativeProfilerEnd( const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) { - // Could raise an exception here. + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeProfilerEnd: requires at least 1 argument"); + } return JSValueMakeUndefined(ctx); } diff --git a/ReactAndroid/src/main/jni/react/JSCTracing.cpp b/ReactAndroid/src/main/jni/react/JSCTracing.cpp index d0bab2c42..945d6fe72 100644 --- a/ReactAndroid/src/main/jni/react/JSCTracing.cpp +++ b/ReactAndroid/src/main/jni/react/JSCTracing.cpp @@ -92,8 +92,11 @@ static JSValueRef nativeTraceBeginSection( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_UNLIKELY(argumentCount < 2)) { - // Could raise an exception here. - // TODO T9329825 + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeTraceBeginSection: requires at least 2 arguments"); + } return JSValueMakeUndefined(ctx); } @@ -129,8 +132,11 @@ static JSValueRef nativeTraceEndSection( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_UNLIKELY(argumentCount < 1)) { - // Could raise an exception here. - // TODO T9329825 + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeTraceEndSection: requires at least 1 argument"); + } return JSValueMakeUndefined(ctx); } @@ -170,8 +176,11 @@ static JSValueRef beginOrEndAsync( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_UNLIKELY(argumentCount < 3)) { - // Could raise an exception here. - // TODO T9329825 + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "beginOrEndAsync: requires at least 3 arguments"); + } return JSValueMakeUndefined(ctx); } @@ -230,8 +239,11 @@ static JSValueRef stageAsync( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_UNLIKELY(argumentCount < 4)) { - // Could raise an exception here. - // TODO T9329825 + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "stageAsync: requires at least 4 arguments"); + } return JSValueMakeUndefined(ctx); } @@ -373,8 +385,11 @@ static JSValueRef nativeTraceCounter( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_UNLIKELY(argumentCount < 3)) { - // Could raise an exception here. - // TODO T9329825 + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeTraceCounter: requires at least 3 arguments"); + } return JSValueMakeUndefined(ctx); }