exceptions generated from incorrect arg usage on JSC trace and LegacyProfile functions

Reviewed By: astreet

Differential Revision: D2729015

fb-gh-sync-id: a3f56554ff6e77170e07aaf93934f93522b3a81b
This commit is contained in:
Mike Armstrong 2015-12-08 06:10:58 -08:00 committed by facebook-github-bot-2
parent 5aef380609
commit e7a4b20d75
4 changed files with 48 additions and 12 deletions

View File

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

View File

@ -13,4 +13,8 @@ void installGlobalFunction(
const char* name,
JSObjectCallAsFunctionCallback callback);
JSValueRef makeJSCException(
JSContextRef ctx,
const char* exception_text);
} }

View File

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

View File

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