Bug 1063241 - Use a constructor instead of manual PodZero to initialize JSErrorReport; r=sfink
authorTerrence Cole <terrence@mozilla.com>
Mon, 20 Oct 2014 10:13:03 -0700
changeset 211351 52b2e7d0c6520e6840067576cfb77c362fe6b6a6
parent 211350 b1c4aac68d3c47920b2222e6e531b595843f39ea
child 211352 fba30348f0c6a53da55e18d261babc466747f97c
push id27673
push userkwierso@gmail.com
push dateTue, 21 Oct 2014 01:57:45 +0000
treeherdermozilla-central@29fbfc1b31aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1063241
milestone36.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 1063241 - Use a constructor instead of manual PodZero to initialize JSErrorReport; r=sfink
js/src/frontend/TokenStream.h
js/src/jsapi.h
js/src/jscntxt.cpp
js/src/jsexn.cpp
js/src/jsfriendapi.h
js/src/jspubtd.h
js/src/vm/ErrorObject.cpp
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -168,21 +168,17 @@ struct Token
         return u.number.decimalPoint;
     }
 };
 
 struct CompileError {
     JSErrorReport report;
     char *message;
     ErrorArgumentsType argumentsType;
-    CompileError()
-      : message(nullptr), argumentsType(ArgumentsAreUnicode)
-    {
-        mozilla::PodZero(&report);
-    }
+    CompileError() : message(nullptr), argumentsType(ArgumentsAreUnicode) {}
     ~CompileError();
     void throwError(JSContext *cx);
 
   private:
     // CompileError owns raw allocated memory, so disable assignment and copying
     // for safety.
     void operator=(const CompileError &) MOZ_DELETE;
     CompileError(const CompileError &) MOZ_DELETE;
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -4670,30 +4670,38 @@ extern JS_PUBLIC_API(void)
 JS_ReportOutOfMemory(JSContext *cx);
 
 /*
  * Complain when an allocation size overflows the maximum supported limit.
  */
 extern JS_PUBLIC_API(void)
 JS_ReportAllocationOverflow(JSContext *cx);
 
-struct JSErrorReport {
+class JSErrorReport
+{
+  public:
+    JSErrorReport()
+      : filename(nullptr), lineno(0), column(0), isMuted(false), linebuf(nullptr),
+        tokenptr(nullptr), uclinebuf(nullptr), uctokenptr(nullptr), flags(0), errorNumber(0),
+        ucmessage(nullptr), messageArgs(nullptr), exnType(0)
+    {}
+
     const char      *filename;      /* source file name, URL, etc., or null */
+    unsigned        lineno;         /* source line number */
+    unsigned        column;         /* zero-based column index in line */
     bool            isMuted;        /* See the comment in ReadOnlyCompileOptions. */
-    unsigned        lineno;         /* source line number */
     const char      *linebuf;       /* offending source line without final \n */
     const char      *tokenptr;      /* pointer to error token in linebuf */
     const char16_t  *uclinebuf;     /* unicode (original) line buffer */
     const char16_t  *uctokenptr;    /* unicode (original) token pointer */
     unsigned        flags;          /* error/warning, etc. */
     unsigned        errorNumber;    /* the error number, e.g. see js.msg */
     const char16_t  *ucmessage;     /* the (default) error message */
     const char16_t  **messageArgs;  /* arguments for the error message */
     int16_t         exnType;        /* One of the JSExnType constants */
-    unsigned        column;         /* zero-based column index in line */
 };
 
 /*
  * JSErrorReport flag values.  These may be freely composed.
  */
 #define JSREPORT_ERROR      0x0     /* pseudo-flag for default case */
 #define JSREPORT_WARNING    0x1     /* reported via JS_ReportWarning */
 #define JSREPORT_EXCEPTION  0x2     /* exception was thrown */
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -50,17 +50,16 @@
 
 #include "vm/Stack-inl.h"
 
 using namespace js;
 using namespace js::gc;
 
 using mozilla::DebugOnly;
 using mozilla::PodArrayZero;
-using mozilla::PodZero;
 using mozilla::PointerRangeSize;
 
 bool
 js::AutoCycleDetector::init()
 {
     ObjectSet &set = cx->cycleDetectorSet;
     hashsetAddPointer = set.lookupForAdd(obj);
     if (!hashsetAddPointer) {
@@ -376,17 +375,16 @@ js_ReportOutOfMemory(ThreadSafeContext *
     }
 
     /* Get the message for this error, but we don't expand any arguments. */
     const JSErrorFormatString *efs = js_GetErrorMessage(nullptr, JSMSG_OUT_OF_MEMORY);
     const char *msg = efs ? efs->format : "Out of memory";
 
     /* Fill out the report, but don't do anything that requires allocation. */
     JSErrorReport report;
-    PodZero(&report);
     report.flags = JSREPORT_ERROR;
     report.errorNumber = JSMSG_OUT_OF_MEMORY;
     PopulateReportBlame(cx, &report);
 
     /* Report the error. */
     if (JSErrorReporter onError = cx->runtime()->errorReporter) {
         AutoSuppressGC suppressGC(cx);
         onError(cx, msg, &report);
@@ -498,17 +496,16 @@ js_ReportErrorVA(JSContext *cx, unsigned
     if (checkReportFlags(cx, &flags))
         return true;
 
     message = JS_vsmprintf(format, ap);
     if (!message)
         return false;
     messagelen = strlen(message);
 
-    PodZero(&report);
     report.flags = flags;
     report.errorNumber = JSMSG_USER_DEFINED_ERROR;
     report.ucmessage = ucmessage = InflateString(cx, message, &messagelen);
     PopulateReportBlame(cx, &report);
 
     warning = JSREPORT_IS_WARNING(report.flags);
 
     ReportError(cx, message, &report, nullptr, nullptr);
@@ -803,17 +800,16 @@ js_ReportErrorNumberVA(JSContext *cx, un
     JSErrorReport report;
     char *message;
     bool warning;
 
     if (checkReportFlags(cx, &flags))
         return 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, argumentsType, ap)) {
         return false;
     }
@@ -843,17 +839,16 @@ js_ReportErrorNumberUCArray(JSContext *c
                             void *userRef, const unsigned errorNumber,
                             const char16_t **args)
 {
     if (checkReportFlags(cx, &flags))
         return true;
     bool warning = JSREPORT_IS_WARNING(flags);
 
     JSErrorReport report;
-    PodZero(&report);
     report.flags = flags;
     report.errorNumber = errorNumber;
     PopulateReportBlame(cx, &report);
     report.messageArgs = args;
 
     char *message;
     va_list dummy;
     if (!js_ExpandErrorArguments(cx, callback, userRef, errorNumber,
--- a/js/src/jsexn.cpp
+++ b/js/src/jsexn.cpp
@@ -35,17 +35,16 @@
 #include "vm/ErrorObject-inl.h"
 
 using namespace js;
 using namespace js::gc;
 using namespace js::types;
 
 using mozilla::ArrayLength;
 using mozilla::PodArrayZero;
-using mozilla::PodZero;
 
 static void
 exn_finalize(FreeOp *fop, JSObject *obj);
 
 bool
 Error(JSContext *cx, unsigned argc, Value *vp);
 
 static bool
@@ -808,17 +807,17 @@ ErrorReport::init(JSContext *cx, HandleV
         if (!JS_GetProperty(cx, exnObject, js_columnNumber_str, &val) ||
             !ToUint32(cx, val, &column))
         {
             cx->clearPendingException();
             column = 0;
         }
 
         reportp = &ownedReport;
-        PodZero(&ownedReport);
+        new (reportp) JSErrorReport();
         ownedReport.filename = filename.ptr();
         ownedReport.lineno = lineno;
         ownedReport.exnType = int16_t(JSEXN_NONE);
         ownedReport.column = column;
         if (str) {
             // Note that using |str| for |ucmessage| here is kind of wrong,
             // because |str| is supposed to be of the format
             // |ErrorName: ErrorMessage|, and |ucmessage| is supposed to
@@ -860,17 +859,17 @@ ErrorReport::populateUncaughtExceptionRe
     va_start(ap, cx);
     populateUncaughtExceptionReportVA(cx, ap);
     va_end(ap);
 }
 
 void
 ErrorReport::populateUncaughtExceptionReportVA(JSContext *cx, va_list ap)
 {
-    PodZero(&ownedReport);
+    new (&ownedReport) JSErrorReport();
     ownedReport.flags = JSREPORT_ERROR;
     ownedReport.errorNumber = JSMSG_UNCAUGHT_EXCEPTION;
     // XXXbz this assumes the stack we have right now is still
     // related to our exception object.  It would be better if we
     // could accept a passed-in stack of some sort instead.
     NonBuiltinFrameIter iter(cx);
     if (!iter.done()) {
         ownedReport.filename = iter.scriptFilename();
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -40,17 +40,17 @@
 #endif
 
 #define JS_CHECK_STACK_SIZE(limit, lval) JS_CHECK_STACK_SIZE_WITH_TOLERANCE(limit, lval, 0)
 
 class JSAtom;
 struct JSErrorFormatString;
 class JSLinearString;
 struct JSJitInfo;
-struct JSErrorReport;
+class JSErrorReport;
 
 namespace JS {
 template <class T>
 class Heap;
 } /* namespace JS */
 
 namespace js {
 class JS_FRIEND_API(BaseProxyHandler);
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -120,17 +120,17 @@ enum JSGCTraceKind {
     JSTRACE_TYPE_OBJECT,
     JSTRACE_LAST = JSTRACE_TYPE_OBJECT
 };
 
 /* Struct forward declarations. */
 struct JSClass;
 struct JSCompartment;
 struct JSCrossCompartmentCall;
-struct JSErrorReport;
+class JSErrorReport;
 struct JSExceptionState;
 struct JSFunctionSpec;
 struct JSIdArray;
 struct JSLocaleCallbacks;
 struct JSObjectMap;
 struct JSPrincipals;
 struct JSPropertyDescriptor;
 struct JSPropertyName;
--- a/js/src/vm/ErrorObject.cpp
+++ b/js/src/vm/ErrorObject.cpp
@@ -12,17 +12,16 @@
 #include "vm/GlobalObject.h"
 
 #include "jsobjinlines.h"
 
 #include "vm/NativeObject-inl.h"
 #include "vm/Shape-inl.h"
 
 using namespace js;
-using mozilla::PodZero;
 
 /* static */ Shape *
 js::ErrorObject::assignInitialShape(ExclusiveContext *cx, Handle<ErrorObject*> obj)
 {
     MOZ_ASSERT(obj->empty());
 
     if (!obj->addDataProperty(cx, cx->names().fileName, FILENAME_SLOT, 0))
         return nullptr;
@@ -111,17 +110,16 @@ JSErrorReport *
 js::ErrorObject::getOrCreateErrorReport(JSContext *cx)
 {
     if (JSErrorReport *r = getErrorReport())
         return r;
 
     // We build an error report on the stack and then use CopyErrorReport to do
     // the nitty-gritty malloc stuff.
     JSErrorReport report;
-    PodZero(&report);
 
     // Type.
     JSExnType type_ = type();
     report.exnType = type_;
 
     // Filename.
     JSAutoByteString filenameStr;
     if (!filenameStr.encodeLatin1(cx, fileName(cx)))