Bug 1125698 - Add ExpandErrorArguments() varargs helper function and remove uninitialized `dummy` va_list variable. r=Waldo
authorChris Peterson <cpeterson@mozilla.com>
Sun, 25 Jan 2015 18:38:28 -0800
changeset 236940 f5782f959c94f016afe66ff4523c4a8227e9fb53
parent 236939 11960a87b91854cc352e02903631d021607e44e0
child 236941 d51574a87ed4e5fb87c091bcc6c1968d5211e021
push id57823
push usercpeterson@mozilla.com
push dateWed, 01 Apr 2015 07:39:49 +0000
treeherdermozilla-inbound@f5782f959c94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1125698
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1125698 - Add ExpandErrorArguments() varargs helper function and remove uninitialized `dummy` va_list variable. r=Waldo
js/src/frontend/TokenStream.cpp
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jsexn.cpp
js/src/jsfriendapi.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -636,18 +636,18 @@ TokenStream::reportCompileErrorNumberVA(
             callerFilename = true;
             err.report.filename = iter.scriptFilename();
             err.report.lineno = iter.computeLine(&err.report.column);
         }
     }
 
     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;
     }
 
     // Given a token, T, that we want to complain about: if T's (starting)
     // lineno doesn't match TokenStream's lineno, that means we've scanned past
     // the line that T starts on, which makes it hard to print some or all of
     // T's (starting) line for context.
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -550,20 +550,20 @@ js::PrintError(JSContext* cx, FILE* file
  * The format string addressed by the error number may contain operands
  * identified by the format {N}, where N is a decimal digit. Each of these
  * is to be replaced by the Nth argument from the va_list. The complete
  * message is placed into reportp->ucmessage converted to a JSString.
  *
  * 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;
     int argCount;
     bool messageArgsPassed = !!reportp->messageArgs;
 
     *messagep = nullptr;
 
@@ -731,60 +731,73 @@ js::ReportErrorNumberVA(JSContext* cx, u
     if (checkReportFlags(cx, &flags))
         return true;
     warning = JSREPORT_IS_WARNING(flags);
 
     report.flags = flags;
     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;
     }
 
     ReportError(cx, message, &report, callback, userRef);
 
     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) {
             int i = 0;
             while (report.messageArgs[i])
                 js_free((void*)report.messageArgs[i++]);
         }
         js_free((void*)report.messageArgs);
     }
     js_free((void*)report.ucmessage);
 
     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,
                              const char16_t** args)
 {
     if (checkReportFlags(cx, &flags))
         return true;
     bool warning = JSREPORT_IS_WARNING(flags);
 
     JSErrorReport report;
     report.flags = flags;
     report.errorNumber = errorNumber;
     PopulateReportBlame(cx, &report);
     report.messageArgs = args;
 
     char* message;
-    va_list dummy;
     if (!ExpandErrorArguments(cx, callback, userRef, errorNumber,
-                              &message, &report, ArgumentsAreUnicode, dummy)) {
+                              &message, &report, ArgumentsAreUnicode)) {
         return false;
     }
 
     ReportError(cx, message, &report, callback, userRef);
 
     js_free(message);
     js_free((void*)report.ucmessage);
 
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -550,17 +550,16 @@ enum DestroyContextMode {
 extern void
 DestroyContext(JSContext* cx, DestroyContextMode mode);
 
 enum ErrorArgumentsType {
     ArgumentsAreUnicode,
     ArgumentsAreASCII
 };
 
-
 /*
  * Loads and returns a self-hosted function by name. For performance, define
  * the property name in vm/CommonPropertyNames.h.
  *
  * Defined in SelfHosting.cpp.
  */
 JSFunction*
 SelfHostedFunction(JSContext* cx, HandlePropertyName propName);
@@ -576,20 +575,20 @@ ReportErrorNumberVA(JSContext* cx, unsig
 
 extern bool
 ReportErrorNumberUCArray(JSContext* cx, unsigned flags, JSErrorCallback callback,
                          void* userRef, const unsigned errorNumber,
                          const char16_t** args);
 #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
 ReportUsageError(JSContext* cx, HandleObject callee, const char* msg);
 
 /*
  * Prints a full report and returns true if the given report is non-nullptr
  * and the report doesn't have the JSREPORT_WARNING flag set or reportWarnings
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -658,17 +658,17 @@ ErrorReport::ErrorReport(JSContext* cx)
 ErrorReport::~ErrorReport()
 {
     if (!ownedMessage)
         return;
 
     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.
          */
         size_t i = 0;
         while (ownedReport.messageArgs[i])
             js_free(const_cast<char16_t*>(ownedReport.messageArgs[i++]));
         js_free(ownedReport.messageArgs);
     }
@@ -864,19 +864,19 @@ ErrorReport::populateUncaughtExceptionRe
     // could accept a passed-in stack of some sort instead.
     NonBuiltinFrameIter iter(cx);
     if (!iter.done()) {
         ownedReport.filename = iter.scriptFilename();
         ownedReport.lineno = iter.computeLine(&ownedReport.column);
         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;
     }
 
     reportp = &ownedReport;
     message_ = ownedMessage;
     ownsMessageAndReport = true;
     return true;
 }
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -132,17 +132,16 @@ extern JS_FRIEND_API(void)
 JS_SetCompartmentPrincipals(JSCompartment* compartment, JSPrincipals* principals);
 
 extern JS_FRIEND_API(JSPrincipals*)
 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);
 
 /* Requires obj != nullptr. */
 extern JS_FRIEND_API(JSObject*)
 JS_ObjectToOuterObject(JSContext* cx, JS::HandleObject obj);
 
@@ -1369,19 +1368,19 @@ struct MOZ_STACK_CLASS JS_FRIEND_API(Err
     }
 
     const char* message()
     {
         return message_;
     }
 
   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).
     bool populateUncaughtExceptionReport(JSContext* cx, ...);
     bool populateUncaughtExceptionReportVA(JSContext* cx, va_list ap);
 
     // We may have a provided JSErrorReport, so need a way to represent that.
     JSErrorReport* reportp;
@@ -2538,17 +2537,16 @@ SetDefaultJSContextCallback(JSRuntime* r
 #ifdef DEBUG
 JS_FRIEND_API(void)
 Debug_SetActiveJSContext(JSRuntime* rt, JSContext* cx);
 #else
 inline void
 Debug_SetActiveJSContext(JSRuntime* rt, JSContext* cx) {}
 #endif
 
-
 enum CTypesActivityType {
     CTYPES_CALL_BEGIN,
     CTYPES_CALL_END,
     CTYPES_CALLBACK_BEGIN,
     CTYPES_CALLBACK_END
 };
 
 typedef void