Bug 808286 - Use enum instead of JSBool for param to js_ErrorReportNumber. r=Waldo
authorErick Dransch <edransch.contact@gmail.com>
Mon, 10 Dec 2012 18:11:17 -0800
changeset 125269 e283fe34dcb1c2a86b805f1d2762abb5202a1649
parent 125268 c22a2faf56d6c4455ce425e50cd623ff2bd5c93d
child 125270 18bc32f799d15288898e6f94abd7d0e5585a7373
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs808286
milestone20.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 808286 - Use enum instead of JSBool for param to js_ErrorReportNumber. r=Waldo
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
js/src/jsapi.cpp
js/src/jscntxt.cpp
js/src/jscntxt.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -478,17 +478,17 @@ CompileError::~CompileError()
 {
     js_free((void*)report.uclinebuf);
     js_free((void*)report.linebuf);
     js_free((void*)report.ucmessage);
     js_free(message);
     message = NULL;
 
     if (report.messageArgs) {
-        if (hasCharArgs) {
+        if (argumentsType == ArgumentsAreASCII) {
             unsigned i = 0;
             while (report.messageArgs[i])
                 js_free((void*)report.messageArgs[i++]);
         }
         js_free(report.messageArgs);
     }
 
     PodZero(&report);
@@ -510,20 +510,21 @@ TokenStream::reportCompileErrorNumberVA(
     const TokenPos *const tp = pn ? &pn->pn_pos : &currentToken().pos;
 
     err.report.flags = flags;
     err.report.errorNumber = errorNumber;
     err.report.filename = filename;
     err.report.originPrincipals = originPrincipals;
     err.report.lineno = tp->begin.lineno;
 
-    err.hasCharArgs = !(flags & JSREPORT_UC);
+    err.argumentsType = (flags & JSREPORT_UC) ? ArgumentsAreUnicode : ArgumentsAreASCII;
 
-    if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, errorNumber, &err.message, &err.report,
-                                 err.hasCharArgs, args)) {
+    if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL, 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/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -415,19 +415,19 @@ enum TokenStreamFlags
 };
 
 struct Parser;
 
 struct CompileError {
     JSContext *cx;
     JSErrorReport report;
     char *message;
-    bool hasCharArgs;
+    ErrorArgumentsType argumentsType;
     CompileError(JSContext *cx)
-     : cx(cx), message(NULL), hasCharArgs(false)
+      : cx(cx), message(NULL), argumentsType(ArgumentsAreUnicode)
     {
         PodZero(&report);
     }
     ~CompileError();
     void throwError();
 };
 
 inline bool
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -6533,29 +6533,29 @@ JS_ReportErrorNumber(JSContext *cx, JSEr
 
 JS_PUBLIC_API(void)
 JS_ReportErrorNumberVA(JSContext *cx, JSErrorCallback errorCallback,
                        void *userRef, const unsigned errorNumber,
                        va_list ap)
 {
     AssertHeapIsIdle(cx);
     js_ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef,
-                           errorNumber, JS_TRUE, ap);
+                           errorNumber, ArgumentsAreASCII, ap);
 }
 
 JS_PUBLIC_API(void)
 JS_ReportErrorNumberUC(JSContext *cx, JSErrorCallback errorCallback,
                        void *userRef, const unsigned errorNumber, ...)
 {
     va_list ap;
 
     AssertHeapIsIdle(cx);
     va_start(ap, errorNumber);
     js_ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef,
-                           errorNumber, JS_FALSE, ap);
+                           errorNumber, ArgumentsAreUnicode, ap);
     va_end(ap);
 }
 
 JS_PUBLIC_API(void)
 JS_ReportErrorNumberUCArray(JSContext *cx, JSErrorCallback errorCallback,
                             void *userRef, const unsigned errorNumber,
                             const jschar **args)
 {
@@ -6583,33 +6583,33 @@ JS_ReportErrorFlagsAndNumber(JSContext *
                              const unsigned errorNumber, ...)
 {
     va_list ap;
     JSBool ok;
 
     AssertHeapIsIdle(cx);
     va_start(ap, errorNumber);
     ok = js_ReportErrorNumberVA(cx, flags, errorCallback, userRef,
-                                errorNumber, JS_TRUE, ap);
+                                errorNumber, ArgumentsAreASCII, ap);
     va_end(ap);
     return ok;
 }
 
 JS_PUBLIC_API(JSBool)
 JS_ReportErrorFlagsAndNumberUC(JSContext *cx, unsigned flags,
                                JSErrorCallback errorCallback, void *userRef,
                                const unsigned errorNumber, ...)
 {
     va_list ap;
     JSBool ok;
 
     AssertHeapIsIdle(cx);
     va_start(ap, errorNumber);
     ok = js_ReportErrorNumberVA(cx, flags, errorCallback, userRef,
-                                errorNumber, JS_FALSE, ap);
+                                errorNumber, ArgumentsAreUnicode, ap);
     va_end(ap);
     return ok;
 }
 
 JS_PUBLIC_API(void)
 JS_ReportOutOfMemory(JSContext *cx)
 {
     js_ReportOutOfMemory(cx);
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -676,17 +676,17 @@ js::PrintError(JSContext *cx, FILE *file
  * message is placed into reportp->ucmessage converted to a JSString.
  *
  * Returns true if the expansion succeeds (can fail if out of memory).
  */
 JSBool
 js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
                         void *userRef, const unsigned errorNumber,
                         char **messagep, JSErrorReport *reportp,
-                        bool charArgs, va_list ap)
+                        ErrorArgumentsType argumentsType, va_list ap)
 {
     const JSErrorFormatString *efs;
     int i;
     int argCount;
     bool messageArgsPassed = !!reportp->messageArgs;
 
     *messagep = NULL;
 
@@ -716,17 +716,17 @@ js_ExpandErrorArguments(JSContext *cx, J
                 if (!reportp->messageArgs)
                     return JS_FALSE;
                 /* NULL-terminate for easy copying. */
                 reportp->messageArgs[argCount] = NULL;
             }
             for (i = 0; i < argCount; i++) {
                 if (messageArgsPassed) {
                     /* Do nothing. */
-                } else if (charArgs) {
+                } else if (argumentsType == ArgumentsAreASCII) {
                     char *charArg = va_arg(ap, char *);
                     size_t charArgLength = strlen(charArg);
                     reportp->messageArgs[i] = InflateString(cx, charArg, &charArgLength);
                     if (!reportp->messageArgs[i])
                         goto error;
                 } else {
                     reportp->messageArgs[i] = va_arg(ap, jschar *);
                 }
@@ -813,17 +813,17 @@ js_ExpandErrorArguments(JSContext *cx, J
             goto error;
         JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber);
     }
     return JS_TRUE;
 
 error:
     if (!messageArgsPassed && reportp->messageArgs) {
         /* free the arguments only if we allocated them */
-        if (charArgs) {
+        if (argumentsType == ArgumentsAreASCII) {
             i = 0;
             while (reportp->messageArgs[i])
                 js_free((void *)reportp->messageArgs[i++]);
         }
         js_free((void *)reportp->messageArgs);
         reportp->messageArgs = NULL;
     }
     if (reportp->ucmessage) {
@@ -835,46 +835,46 @@ error:
         *messagep = NULL;
     }
     return JS_FALSE;
 }
 
 JSBool
 js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
                        void *userRef, const unsigned errorNumber,
-                       JSBool charArgs, va_list ap)
+                       ErrorArgumentsType argumentsType, va_list ap)
 {
     JSErrorReport report;
     char *message;
     JSBool warning;
 
     if (checkReportFlags(cx, &flags))
         return JS_TRUE;
     warning = JSREPORT_IS_WARNING(flags);
 
     PodZero(&report);
     report.flags = flags;
     report.errorNumber = errorNumber;
     PopulateReportBlame(cx, &report);
 
     if (!js_ExpandErrorArguments(cx, callback, userRef, errorNumber,
-                                 &message, &report, !!charArgs, ap)) {
+                                 &message, &report, argumentsType, ap)) {
         return JS_FALSE;
     }
 
     ReportError(cx, message, &report, callback, userRef);
 
     if (message)
         js_free(message);
     if (report.messageArgs) {
         /*
          * js_ExpandErrorArguments owns its messageArgs only if it had to
          * inflate the arguments (from regular |char *|s).
          */
-        if (charArgs) {
+        if (argumentsType == ArgumentsAreASCII) {
             int i = 0;
             while (report.messageArgs[i])
                 js_free((void *)report.messageArgs[i++]);
         }
         js_free((void *)report.messageArgs);
     }
     if (report.ucmessage)
         js_free((void *)report.ucmessage);
@@ -896,17 +896,17 @@ js_ReportErrorNumberUCArray(JSContext *c
     report.flags = flags;
     report.errorNumber = errorNumber;
     PopulateReportBlame(cx, &report);
     report.messageArgs = args;
 
     char *message;
     va_list dummy;
     if (!js_ExpandErrorArguments(cx, callback, userRef, errorNumber,
-                                 &message, &report, JS_FALSE, dummy)) {
+                                 &message, &report, ArgumentsAreUnicode, dummy)) {
         return false;
     }
 
     ReportError(cx, message, &report, callback, userRef);
 
     if (message)
         js_free(message);
     if (report.ucmessage)
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -1897,37 +1897,42 @@ enum DestroyContextMode {
     DCM_NO_GC,
     DCM_FORCE_GC,
     DCM_NEW_FAILED
 };
 
 extern void
 DestroyContext(JSContext *cx, DestroyContextMode mode);
 
+enum ErrorArgumentsType {
+    ArgumentsAreUnicode,
+    ArgumentsAreASCII
+};
+
 } /* namespace js */
 
 #ifdef va_start
 extern JSBool
 js_ReportErrorVA(JSContext *cx, unsigned flags, const char *format, va_list ap);
 
 extern JSBool
 js_ReportErrorNumberVA(JSContext *cx, unsigned flags, JSErrorCallback callback,
                        void *userRef, const unsigned errorNumber,
-                       JSBool charArgs, va_list ap);
+                       js::ErrorArgumentsType argumentsType, va_list ap);
 
 extern bool
 js_ReportErrorNumberUCArray(JSContext *cx, unsigned flags, JSErrorCallback callback,
                             void *userRef, const unsigned errorNumber,
                             const jschar **args);
 
 extern JSBool
 js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
                         void *userRef, const unsigned errorNumber,
                         char **message, JSErrorReport *reportp,
-                        bool charArgs, va_list ap);
+                        js::ErrorArgumentsType argumentsType, va_list ap);
 #endif
 
 namespace js {
 
 /* |callee| requires a usage string provided by JS_DefineFunctionsWithHelp. */
 extern void
 ReportUsageError(JSContext *cx, HandleObject callee, const char *msg);