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); }