Bug 1283710 - Part 6: Make CompileError subclass of JSErrorReport. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Sun, 14 Aug 2016 20:39:31 +0900
changeset 319006 357f9ca720b4e71c12c75e2325c77e8c3386af88
parent 319005 fe8948da2efd64f8695f00f3dd49437f0945051a
child 319007 c00f9da4f27def5b26dc39bfa6671c0c25f02b7c
push id83057
push userarai_a@mac.com
push dateSat, 22 Oct 2016 16:47:08 +0000
treeherdermozilla-inbound@a6b3f4302b4f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1283710
milestone52.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 1283710 - Part 6: Make CompileError subclass of JSErrorReport. r=jwalden
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
js/src/jscntxt.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -562,37 +562,33 @@ TokenStream::reportStrictModeErrorNumber
         return true;
 
     return reportCompileErrorNumberVA(offset, flags, errorNumber, args);
 }
 
 void
 CompileError::throwError(JSContext* cx)
 {
-    if (JSREPORT_IS_WARNING(report.flags)) {
-        CallWarningReporter(cx, &report);
+    if (JSREPORT_IS_WARNING(flags)) {
+        CallWarningReporter(cx, this);
         return;
     }
 
     // If there's a runtime exception type associated with this error
     // number, set that as the pending exception.  For errors occuring at
     // compile time, this is very likely to be a JSEXN_SYNTAXERR.
     //
     // If an exception is thrown but not caught, the JSREPORT_EXCEPTION
     // flag will be set in report.flags.  Proper behavior for an error
     // reporter is to ignore a report with this flag for all but top-level
     // compilation errors.  The exception will remain pending, and so long
     // as the non-top-level "load", "eval", or "compile" native function
     // returns false, the top-level reporter will eventually receive the
     // uncaught exception report.
-    ErrorToException(cx, &report, nullptr, nullptr);
-}
-
-CompileError::~CompileError()
-{
+    ErrorToException(cx, this, nullptr, nullptr);
 }
 
 bool
 TokenStream::reportCompileErrorNumberVA(uint32_t offset, unsigned flags, unsigned errorNumber,
                                         va_list args)
 {
     bool warning = JSREPORT_IS_WARNING(flags);
 
@@ -604,56 +600,56 @@ TokenStream::reportCompileErrorNumberVA(
     // On the main thread, report the error immediately. When compiling off
     // thread, save the error so that the main thread can report it later.
     CompileError tempErr;
     CompileError* tempErrPtr = &tempErr;
     if (!cx->isJSContext() && !cx->addPendingCompileError(&tempErrPtr))
         return false;
     CompileError& err = *tempErrPtr;
 
-    err.report.flags = flags;
-    err.report.errorNumber = errorNumber;
-    err.report.filename = filename;
-    err.report.isMuted = mutedErrors;
+    err.flags = flags;
+    err.errorNumber = errorNumber;
+    err.filename = filename;
+    err.isMuted = mutedErrors;
     if (offset == NoOffset) {
-        err.report.lineno = 0;
-        err.report.column = 0;
+        err.lineno = 0;
+        err.column = 0;
     } else {
-        err.report.lineno = srcCoords.lineNum(offset);
-        err.report.column = srcCoords.columnIndex(offset);
+        err.lineno = srcCoords.lineNum(offset);
+        err.column = srcCoords.columnIndex(offset);
     }
 
     // If we have no location information, try to get one from the caller.
     bool callerFilename = false;
-    if (offset != NoOffset && !err.report.filename && cx->isJSContext()) {
+    if (offset != NoOffset && !err.filename && cx->isJSContext()) {
         NonBuiltinFrameIter iter(cx->asJSContext(),
                                  FrameIter::FOLLOW_DEBUGGER_EVAL_PREV_LINK,
                                  cx->compartment()->principals());
         if (!iter.done() && iter.filename()) {
             callerFilename = true;
-            err.report.filename = iter.filename();
-            err.report.lineno = iter.computeLine(&err.report.column);
+            err.filename = iter.filename();
+            err.lineno = iter.computeLine(&err.column);
         }
     }
 
     if (!ExpandErrorArgumentsVA(cx, GetErrorMessage, nullptr, errorNumber,
-                                nullptr, ArgumentsAreLatin1, &err.report, args))
+                                nullptr, ArgumentsAreLatin1, &err, 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.
     //
     // So we don't even try, leaving report.linebuf and friends zeroed.  This
     // means that any error involving a multi-line token (e.g. an unterminated
     // multi-line string literal) won't have a context printed.
-    if (offset != NoOffset && err.report.lineno == lineno && !callerFilename) {
+    if (offset != NoOffset && err.lineno == lineno && !callerFilename) {
         // We show only a portion (a "window") of the line around the erroneous
         // token -- the first char in the token, plus |windowRadius| chars
         // before it and |windowRadius - 1| chars after it.  This is because
         // lines can be very long and printing the whole line is (a) not that
         // helpful, and (b) can waste a lot of memory.  See bug 634444.
         static const size_t windowRadius = 60;
 
         // The window must start within the current line, no earlier than
@@ -681,17 +677,17 @@ TokenStream::reportCompileErrorNumberVA(
             return false;
         }
 
         // The window into the offending source line, without final \n.
         UniqueTwoByteChars linebuf(windowBuf.stealChars());
         if (!linebuf)
             return false;
 
-        err.report.initOwnedLinebuf(linebuf.release(), windowLength, offset - windowStart);
+        err.initOwnedLinebuf(linebuf.release(), windowLength, offset - windowStart);
     }
 
     if (cx->isJSContext())
         err.throwError(cx->asJSContext());
 
     return warning;
 }
 
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -232,27 +232,19 @@ struct Token
     }
 
     DecimalPoint decimalPoint() const {
         MOZ_ASSERT(type == TOK_NUMBER);
         return u.number.decimalPoint;
     }
 };
 
-struct CompileError {
-    JSErrorReport report;
-    CompileError() {}
-    ~CompileError();
+class CompileError : public JSErrorReport {
+public:
     void throwError(JSContext* cx);
-
-  private:
-    // CompileError owns raw allocated memory, so disable assignment and copying
-    // for safety.
-    void operator=(const CompileError&) = delete;
-    CompileError(const CompileError&) = delete;
 };
 
 // Ideally, tokenizing would be entirely independent of context.  But the
 // strict mode flag, which is in SharedContext, affects tokenizing, and
 // TokenStream needs to see it.
 //
 // This class is a tiny back-channel from TokenStream to the strict mode flag
 // that avoids exposing the rest of SharedContext to TokenStream.
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -62,17 +62,17 @@ class MOZ_RAII AutoCycleDetector
 };
 
 /* Updates references in the cycle detection set if the GC moves them. */
 extern void
 TraceCycleDetectionSet(JSTracer* trc, AutoCycleDetector::Set& set);
 
 struct AutoResolving;
 
-namespace frontend { struct CompileError; }
+namespace frontend { class CompileError; }
 
 /*
  * Execution Context Overview:
  *
  * Several different structures may be used to provide a context for operations
  * on the VM. Each context is thread local, but varies in what data it can
  * access and what other threads may be running.
  *