Bug 1622562 - Remove ErrorReport flags everywhere. r=mccr8
authorTom Schuster <evilpies@gmail.com>
Tue, 24 Mar 2020 10:13:15 +0000
changeset 520205 a5228fc5e5b371bc46963553e6365c27089f3932
parent 520204 d70d72a60f12791b7f5c5aef535c7a09be089d12
child 520206 7ccf355bd17eddde68097a1d8833cb57d36734bf
push id37245
push useropoprus@mozilla.com
push dateTue, 24 Mar 2020 21:46:41 +0000
treeherdermozilla-central@dbabf2e388fa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1622562
milestone76.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 1622562 - Remove ErrorReport flags everywhere. r=mccr8 Depends on D67143 Differential Revision: https://phabricator.services.mozilla.com/D67783
dom/bindings/nsScriptError.cpp
dom/serviceworkers/ServiceWorkerPrivateImpl.cpp
dom/workers/WorkerError.cpp
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCConvert.cpp
js/xpconnect/src/nsXPConnect.cpp
js/xpconnect/src/xpcpublic.h
--- a/dom/bindings/nsScriptError.cpp
+++ b/dom/bindings/nsScriptError.cpp
@@ -15,21 +15,16 @@
 #include "nsContentUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
 #include "nsIMutableArray.h"
 #include "nsIScriptError.h"
 #include "mozilla/BasePrincipal.h"
 
-static_assert(nsIScriptError::errorFlag == JSREPORT_ERROR &&
-                  nsIScriptError::warningFlag == JSREPORT_WARNING &&
-                  nsIScriptError::infoFlag == JSREPORT_USER_1,
-              "flags should be consistent");
-
 nsScriptErrorBase::nsScriptErrorBase()
     : mMessage(),
       mMessageName(),
       mSourceName(),
       mCssSelectors(),
       mSourceId(0),
       mLineNumber(0),
       mSourceLine(),
@@ -332,17 +327,18 @@ static nsresult ToStringHelper(const cha
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScriptErrorBase::ToString(nsACString& /*UTF8*/ aResult) {
   static const char error[] = "JavaScript Error";
   static const char warning[] = "JavaScript Warning";
 
-  const char* severity = !(mFlags & JSREPORT_WARNING) ? error : warning;
+  const char* severity =
+      !(mFlags & nsIScriptError::warningFlag) ? error : warning;
 
   return ToStringHelper(severity, mMessage, mSourceName, &mSourceLine,
                         mLineNumber, mColumnNumber, aResult);
 }
 
 NS_IMETHODIMP
 nsScriptErrorBase::GetOuterWindowID(uint64_t* aOuterWindowID) {
   NS_WARNING_ASSERTION(NS_IsMainThread() || mInitializedOnMainThread,
--- a/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp
+++ b/dom/serviceworkers/ServiceWorkerPrivateImpl.cpp
@@ -11,16 +11,17 @@
 #include "MainThreadUtils.h"
 #include "js/ErrorReport.h"
 #include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsError.h"
 #include "nsIChannel.h"
 #include "nsINetworkInterceptController.h"
 #include "nsIObserverService.h"
+#include "nsIScriptError.h"
 #include "nsIURI.h"
 #include "nsThreadUtils.h"
 
 #include "ServiceWorkerManager.h"
 #include "ServiceWorkerRegistrationInfo.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Maybe.h"
@@ -786,18 +787,18 @@ void ServiceWorkerPrivateImpl::ErrorRece
 
   RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
   MOZ_ASSERT(swm);
 
   ServiceWorkerInfo* info = mOuter->mInfo;
 
   swm->HandleError(nullptr, info->Principal(), info->Scope(),
                    NS_ConvertUTF8toUTF16(info->ScriptSpec()), EmptyString(),
-                   EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR,
-                   JSEXN_ERR);
+                   EmptyString(), EmptyString(), 0, 0,
+                   nsIScriptError::errorFlag, JSEXN_ERR);
 }
 
 void ServiceWorkerPrivateImpl::Terminated() {
   AssertIsOnMainThread();
   MOZ_ASSERT(mOuter);
   MOZ_ASSERT(mControllerChild);
 
   Shutdown();
--- a/dom/workers/WorkerError.cpp
+++ b/dom/workers/WorkerError.cpp
@@ -93,18 +93,18 @@ class ReportErrorRunnable final : public
 
         } else {
           RefPtr<ServiceWorkerManager> swm =
               ServiceWorkerManager::GetInstance();
           if (swm) {
             swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(),
                              aWorkerPrivate->ServiceWorkerScope(),
                              aWorkerPrivate->ScriptURL(), EmptyString(),
-                             EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR,
-                             JSEXN_ERR);
+                             EmptyString(), EmptyString(), 0, 0,
+                             nsIScriptError::errorFlag, JSEXN_ERR);
           }
         }
 
         return true;
       }
 
       // The innerWindowId is only required if we are going to ReportError
       // below, which is gated on this condition. The inner window correctness
@@ -184,18 +184,18 @@ class ReportGenericErrorRunnable final :
         }
 
       } else {
         RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
         if (swm) {
           swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(),
                            aWorkerPrivate->ServiceWorkerScope(),
                            aWorkerPrivate->ScriptURL(), EmptyString(),
-                           EmptyString(), EmptyString(), 0, 0, JSREPORT_ERROR,
-                           JSEXN_ERR);
+                           EmptyString(), EmptyString(), 0, 0,
+                           nsIScriptError::errorFlag, JSEXN_ERR);
         }
       }
 
       return true;
     }
 
     if (!aWorkerPrivate->IsAcceptingEvents()) {
       return true;
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -1408,24 +1408,26 @@ nsXPCComponents_Utils::ReportError(Handl
   if (err) {
     // It's a proper JS Error
     nsAutoString fileUni;
     CopyUTF8toUTF16(mozilla::MakeStringSpan(err->filename), fileUni);
 
     uint32_t column = err->tokenOffset();
 
     const char16_t* linebuf = err->linebuf();
+    uint32_t flags = err->isWarning() ? nsIScriptError::warningFlag
+                                      : nsIScriptError::errorFlag;
 
     nsresult rv = scripterr->InitWithWindowID(
         err->message() ? NS_ConvertUTF8toUTF16(err->message().c_str())
                        : EmptyString(),
         fileUni,
         linebuf ? nsDependentString(linebuf, err->linebufLength())
                 : EmptyString(),
-        err->lineno, column, err->flags, "XPConnect JavaScript", innerWindowID,
+        err->lineno, column, flags, "XPConnect JavaScript", innerWindowID,
         innerWindowID == 0 ? true : false);
     NS_ENSURE_SUCCESS(rv, NS_OK);
 
     console->LogMessage(scripterr);
     return NS_OK;
   }
 
   // It's not a JS Error object, so we synthesize as best we're able.
--- a/js/xpconnect/src/XPCConvert.cpp
+++ b/js/xpconnect/src/XPCConvert.cpp
@@ -1197,33 +1197,35 @@ static nsresult JSErrorToXPCException(JS
                                       const char* ifaceName,
                                       const char* methodName,
                                       const JSErrorReport* report,
                                       Exception** exceptn) {
   nsresult rv = NS_ERROR_FAILURE;
   RefPtr<nsScriptError> data;
   if (report) {
     nsAutoString bestMessage;
-    if (report && report->message()) {
+    if (report->message()) {
       CopyUTF8toUTF16(mozilla::MakeStringSpan(report->message().c_str()),
                       bestMessage);
     } else if (toStringResult) {
       CopyUTF8toUTF16(mozilla::MakeStringSpan(toStringResult), bestMessage);
     } else {
       bestMessage.AssignLiteral("JavaScript Error");
     }
 
     const char16_t* linebuf = report->linebuf();
+    uint32_t flags = report->isWarning() ? nsIScriptError::warningFlag
+                                         : nsIScriptError::errorFlag;
 
     data = new nsScriptError();
     data->nsIScriptError::InitWithWindowID(
         bestMessage, NS_ConvertASCIItoUTF16(report->filename),
         linebuf ? nsDependentString(linebuf, report->linebufLength())
                 : EmptyString(),
-        report->lineno, report->tokenOffset(), report->flags,
+        report->lineno, report->tokenOffset(), flags,
         NS_LITERAL_CSTRING("XPConnect JavaScript"),
         nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx));
   }
 
   if (data) {
     // Pass nullptr for the message: ConstructException will get a message
     // from the nsIScriptError.
     rv = XPCConvert::ConstructException(
--- a/js/xpconnect/src/nsXPConnect.cpp
+++ b/js/xpconnect/src/nsXPConnect.cpp
@@ -211,17 +211,17 @@ void xpc::ErrorReport::Init(JSErrorRepor
   mSourceLine.Assign(aReport->linebuf(), aReport->linebufLength());
 
   if (aReport->errorMessageName) {
     mErrorMsgName.AssignASCII(aReport->errorMessageName);
   } else {
     mErrorMsgName.Truncate();
   }
 
-  mFlags = aReport->flags;
+  mIsWarning = aReport->isWarning();
   mIsMuted = aReport->isMuted;
 
   if (aReport->notes) {
     if (!mNotes.SetLength(aReport->notes->length(), fallible)) {
       return;
     }
 
     size_t i = 0;
@@ -242,18 +242,16 @@ void xpc::ErrorReport::Init(JSContext* a
 
   aException->GetFilename(aCx, mFileName);
   if (mFileName.IsEmpty()) {
     mFileName.SetIsVoid(true);
   }
   mSourceId = aException->SourceId(aCx);
   mLineNumber = aException->LineNumber(aCx);
   mColumn = aException->ColumnNumber();
-
-  mFlags = JSREPORT_ERROR;
 }
 
 static LazyLogModule gJSDiagnostics("JSDiagnostics");
 
 void xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error) {
   AppendUTF16toUTF8(mFileName, error);
   error.AppendLiteral(", line ");
   error.AppendInt(mLineNumber, 10);
@@ -331,20 +329,21 @@ void xpc::ErrorReport::LogToConsoleWithS
     // we have to ensure not leaking them after the related
     // context is destroyed and we only track document lifecycle for now.
     errorObject = new nsScriptErrorWithStack(aStack, aStackGlobal);
   } else {
     errorObject = new nsScriptError();
   }
   errorObject->SetErrorMessageName(mErrorMsgName);
 
+  uint32_t flags =
+      mIsWarning ? nsIScriptError::warningFlag : nsIScriptError::errorFlag;
   nsresult rv = errorObject->InitWithWindowID(
-      mErrorMsg, mFileName, mSourceLine, mLineNumber, mColumn, mFlags,
-      mCategory, mWindowID,
-      mCategory.Equals(NS_LITERAL_CSTRING("chrome javascript")));
+      mErrorMsg, mFileName, mSourceLine, mLineNumber, mColumn, flags, mCategory,
+      mWindowID, mCategory.Equals(NS_LITERAL_CSTRING("chrome javascript")));
   NS_ENSURE_SUCCESS_VOID(rv);
 
   rv = errorObject->InitSourceId(mSourceId);
   NS_ENSURE_SUCCESS_VOID(rv);
 
   for (size_t i = 0, len = mNotes.Length(); i < len; i++) {
     ErrorNote& note = mNotes[i];
 
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -577,20 +577,20 @@ class ErrorReport : public ErrorBase {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ErrorReport);
 
   nsTArray<ErrorNote> mNotes;
 
   nsCString mCategory;
   nsString mSourceLine;
   nsString mErrorMsgName;
   uint64_t mWindowID;
-  uint32_t mFlags;
+  bool mIsWarning;
   bool mIsMuted;
 
-  ErrorReport() : mWindowID(0), mFlags(0), mIsMuted(false) {}
+  ErrorReport() : mWindowID(0), mIsWarning(false), mIsMuted(false) {}
 
   void Init(JSErrorReport* aReport, const char* aToStringResult, bool aIsChrome,
             uint64_t aWindowID);
   void Init(JSContext* aCx, mozilla::dom::Exception* aException, bool aIsChrome,
             uint64_t aWindowID);
 
   // Log the error report to the console.  Which console will depend on the
   // window id it was initialized with.
@@ -607,17 +607,17 @@ class ErrorReport : public ErrorBase {
   // that this may produce an empty string if aReport doesn't have a
   // message attached.
   static void ErrorReportToMessageString(JSErrorReport* aReport,
                                          nsAString& aString);
 
   // Log the error report to the stderr.
   void LogToStderr();
 
-  bool IsWarning() const { return !!(mFlags & JSREPORT_WARNING); };
+  bool IsWarning() const { return mIsWarning; };
 
  private:
   ~ErrorReport() = default;
 };
 
 void DispatchScriptErrorEvent(nsPIDOMWindowInner* win,
                               JS::RootingContext* rootingCx,
                               xpc::ErrorReport* xpcReport,