Bug 1125698 - Add ExpandErrorArguments() varargs helper function and remove uninitialized `dummy` va_list variable. r=Waldo

This commit is contained in:
Chris Peterson 2015-01-25 18:38:28 -08:00
Родитель 1bba6ed97c
Коммит 987f3c1f53
5 изменённых файлов: 34 добавлений и 24 удалений

Просмотреть файл

@ -641,8 +641,8 @@ TokenStream::reportCompileErrorNumberVA(uint32_t offset, unsigned flags, unsigne
err.argumentsType = (flags & JSREPORT_UC) ? ArgumentsAreUnicode : ArgumentsAreASCII;
if (!ExpandErrorArguments(cx, GetErrorMessage, nullptr, errorNumber, &err.message,
&err.report, err.argumentsType, args))
if (!ExpandErrorArgumentsVA(cx, GetErrorMessage, nullptr, errorNumber, &err.message,
&err.report, err.argumentsType, args))
{
return false;
}

Просмотреть файл

@ -555,10 +555,10 @@ js::PrintError(JSContext* cx, FILE* file, const char* message, JSErrorReport* re
* Returns true if the expansion succeeds (can fail if out of memory).
*/
bool
js::ExpandErrorArguments(ExclusiveContext* cx, JSErrorCallback callback,
void* userRef, const unsigned errorNumber,
char** messagep, JSErrorReport* reportp,
ErrorArgumentsType argumentsType, va_list ap)
js::ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback,
void* userRef, const unsigned errorNumber,
char** messagep, JSErrorReport* reportp,
ErrorArgumentsType argumentsType, va_list ap)
{
const JSErrorFormatString* efs;
int i;
@ -736,8 +736,8 @@ js::ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback,
report.errorNumber = errorNumber;
PopulateReportBlame(cx, &report);
if (!ExpandErrorArguments(cx, callback, userRef, errorNumber,
&message, &report, argumentsType, ap)) {
if (!ExpandErrorArgumentsVA(cx, callback, userRef, errorNumber,
&message, &report, argumentsType, ap)) {
return false;
}
@ -746,7 +746,7 @@ js::ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback,
js_free(message);
if (report.messageArgs) {
/*
* ExpandErrorArguments owns its messageArgs only if it had to
* ExpandErrorArgumentsVA owns its messageArgs only if it had to
* inflate the arguments (from regular |char*|s).
*/
if (argumentsType == ArgumentsAreASCII) {
@ -761,6 +761,20 @@ js::ReportErrorNumberVA(JSContext* cx, unsigned flags, JSErrorCallback callback,
return warning;
}
static bool
ExpandErrorArguments(ExclusiveContext *cx, JSErrorCallback callback,
void *userRef, const unsigned errorNumber,
char **messagep, JSErrorReport *reportp,
ErrorArgumentsType argumentsType, ...)
{
va_list ap;
va_start(ap, argumentsType);
bool expanded = js::ExpandErrorArgumentsVA(cx, callback, userRef, errorNumber,
messagep, reportp, argumentsType, ap);
va_end(ap);
return expanded;
}
bool
js::ReportErrorNumberUCArray(JSContext* cx, unsigned flags, JSErrorCallback callback,
void* userRef, const unsigned errorNumber,
@ -777,9 +791,8 @@ js::ReportErrorNumberUCArray(JSContext* cx, unsigned flags, JSErrorCallback call
report.messageArgs = args;
char* message;
va_list dummy;
if (!ExpandErrorArguments(cx, callback, userRef, errorNumber,
&message, &report, ArgumentsAreUnicode, dummy)) {
&message, &report, ArgumentsAreUnicode)) {
return false;
}

Просмотреть файл

@ -555,7 +555,6 @@ enum ErrorArgumentsType {
ArgumentsAreASCII
};
/*
* Loads and returns a self-hosted function by name. For performance, define
* the property name in vm/CommonPropertyNames.h.
@ -581,10 +580,10 @@ ReportErrorNumberUCArray(JSContext* cx, unsigned flags, JSErrorCallback callback
#endif
extern bool
ExpandErrorArguments(ExclusiveContext* cx, JSErrorCallback callback,
void* userRef, const unsigned errorNumber,
char** message, JSErrorReport* reportp,
ErrorArgumentsType argumentsType, va_list ap);
ExpandErrorArgumentsVA(ExclusiveContext* cx, JSErrorCallback callback,
void* userRef, const unsigned errorNumber,
char** message, JSErrorReport* reportp,
ErrorArgumentsType argumentsType, va_list ap);
/* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
extern void

Просмотреть файл

@ -663,7 +663,7 @@ ErrorReport::~ErrorReport()
js_free(ownedMessage);
if (ownedReport.messageArgs) {
/*
* ExpandErrorArguments owns its messageArgs only if it had to
* ExpandErrorArgumentsVA owns its messageArgs only if it had to
* inflate the arguments (from regular |char*|s), which is always in
* our case.
*/
@ -869,9 +869,9 @@ ErrorReport::populateUncaughtExceptionReportVA(JSContext* cx, va_list ap)
ownedReport.isMuted = iter.mutedErrors();
}
if (!ExpandErrorArguments(cx, GetErrorMessage, nullptr,
JSMSG_UNCAUGHT_EXCEPTION, &ownedMessage,
&ownedReport, ArgumentsAreASCII, ap)) {
if (!ExpandErrorArgumentsVA(cx, GetErrorMessage, nullptr,
JSMSG_UNCAUGHT_EXCEPTION, &ownedMessage,
&ownedReport, ArgumentsAreASCII, ap)) {
return false;
}

Просмотреть файл

@ -137,7 +137,6 @@ JS_GetScriptPrincipals(JSScript* script);
extern JS_FRIEND_API(bool)
JS_ScriptHasMutedErrors(JSScript* script);
/* Safe to call with input obj == nullptr. Returns non-nullptr iff obj != nullptr. */
extern JS_FRIEND_API(JSObject*)
JS_ObjectToInnerObject(JSContext* cx, JS::HandleObject obj);
@ -1374,9 +1373,9 @@ struct MOZ_STACK_CLASS JS_FRIEND_API(ErrorReport)
}
private:
// More or less an equivalent of JS_ReportErrorNumber/js_ReportErrorNumberVA
// More or less an equivalent of JS_ReportErrorNumber/js::ReportErrorNumberVA
// but fills in an ErrorReport instead of reporting it. Uses varargs to
// make it simpler to call js_ExpandErrorArguments.
// make it simpler to call js::ExpandErrorArgumentsVA.
//
// Returns false if we fail to actually populate the ErrorReport
// for some reason (probably out of memory).
@ -2543,7 +2542,6 @@ inline void
Debug_SetActiveJSContext(JSRuntime* rt, JSContext* cx) {}
#endif
enum CTypesActivityType {
CTYPES_CALL_BEGIN,
CTYPES_CALL_END,