Bug 1000947 - Console::Methods must not throw exceptions. r=bz, a=lsblakk
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 29 Apr 2014 07:49:57 +0100
changeset 192274 e295406432eb
parent 192273 dcd4cf44e61b
child 192275 acb6d71ba45d
push id3557
push userryanvm@gmail.com
push date2014-05-14 16:23 +0000
treeherdermozilla-beta@c3bcd563e6ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, lsblakk
bugs1000947
milestone30.0
Bug 1000947 - Console::Methods must not throw exceptions. r=bz, a=lsblakk
dom/base/Console.cpp
dom/base/Console.h
dom/webidl/Console.webidl
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -459,20 +459,17 @@ private:
 
       if (!JS_GetElement(cx, argumentsObj, i, &value)) {
         return;
       }
 
       arguments.AppendElement(value);
     }
 
-    console->ProfileMethod(cx, mAction, arguments, error);
-    if (error.Failed()) {
-      NS_WARNING("Failed to call call profile() method to the ConsoleAPI.");
-    }
+    console->ProfileMethod(cx, mAction, arguments);
   }
 
 private:
   nsString mAction;
   Sequence<JS::Value> mArguments;
 
   JSAutoStructuredCloneBuffer mBuffer;
   nsTArray<nsString> mStrings;
@@ -647,73 +644,69 @@ Console::TimeEnd(JSContext* aCx, const J
   if (!aTime.isUndefined()) {
     data.AppendElement(aTime);
   }
 
   Method(aCx, MethodTimeEnd, NS_LITERAL_STRING("timeEnd"), data);
 }
 
 void
-Console::Profile(JSContext* aCx, const Sequence<JS::Value>& aData,
-                 ErrorResult& aRv)
+Console::Profile(JSContext* aCx, const Sequence<JS::Value>& aData)
 {
-  ProfileMethod(aCx, NS_LITERAL_STRING("profile"), aData, aRv);
+  ProfileMethod(aCx, NS_LITERAL_STRING("profile"), aData);
 }
 
 void
-Console::ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData,
-                    ErrorResult& aRv)
+Console::ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData)
 {
-  ProfileMethod(aCx, NS_LITERAL_STRING("profileEnd"), aData, aRv);
+  ProfileMethod(aCx, NS_LITERAL_STRING("profileEnd"), aData);
 }
 
 void
 Console::ProfileMethod(JSContext* aCx, const nsAString& aAction,
-                       const Sequence<JS::Value>& aData,
-                       ErrorResult& aRv)
+                       const Sequence<JS::Value>& aData)
 {
   if (!NS_IsMainThread()) {
     // Here we are in a worker thread.
     nsRefPtr<ConsoleProfileRunnable> runnable =
       new ConsoleProfileRunnable(aAction, aData);
     runnable->Dispatch();
     return;
   }
 
+  ClearException ce(aCx);
+
   RootedDictionary<ConsoleProfileEvent> event(aCx);
   event.mAction = aAction;
 
   event.mArguments.Construct();
   Sequence<JS::Value>& sequence = event.mArguments.Value();
 
   for (uint32_t i = 0; i < aData.Length(); ++i) {
     sequence.AppendElement(aData[i]);
   }
 
   JS::Rooted<JS::Value> eventValue(aCx);
   if (!event.ToObject(aCx, JS::NullPtr(), &eventValue)) {
-    aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
   if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue,
-                         nullptr, nullptr, JSPROP_ENUMERATE)) {
-    aRv.Throw(NS_ERROR_FAILURE);
+      nullptr, nullptr, JSPROP_ENUMERATE)) {
     return;
   }
 
   nsXPConnect*  xpc = nsXPConnect::XPConnect();
   nsCOMPtr<nsISupports> wrapper;
   const nsIID& iid = NS_GET_IID(nsISupports);
 
   if (NS_FAILED(xpc->WrapJS(aCx, eventObj, iid, getter_AddRefs(wrapper)))) {
-    aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   nsCOMPtr<nsIObserverService> obs =
     do_GetService("@mozilla.org/observer-service;1");
   if (obs) {
     obs->NotifyObservers(wrapper, "console-api-profiler", nullptr);
   }
@@ -770,103 +763,97 @@ Console::Method(JSContext* aCx, MethodNa
   private:
     LinkedList<ConsoleCallData>& mList;
     bool mUnfinished;
   };
 
   ConsoleCallData* callData = new ConsoleCallData();
   mQueuedCalls.insertBack(callData);
 
+  ClearException ce(aCx);
+
   callData->Initialize(aCx, aMethodName, aMethodString, aData);
   RAII raii(mQueuedCalls);
 
   if (mWindow) {
     nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(mWindow);
     if (!webNav) {
-      Throw(aCx, NS_ERROR_FAILURE);
       return;
     }
 
     nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
     MOZ_ASSERT(loadContext);
 
     loadContext->GetUsePrivateBrowsing(&callData->mPrivate);
   }
 
   uint32_t maxDepth = aMethodName == MethodTrace ?
                        DEFAULT_MAX_STACKTRACE_DEPTH : 1;
   nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, maxDepth);
 
   if (!stack) {
-    Throw(aCx, NS_ERROR_FAILURE);
     return;
   }
 
   // nsIStackFrame is not thread-safe so we take what we need and we store in
   // an array of ConsoleStackEntry objects.
   do {
     uint32_t language;
     nsresult rv = stack->GetLanguage(&language);
     if (NS_FAILED(rv)) {
-      Throw(aCx, rv);
       return;
     }
 
     if (language == nsIProgrammingLanguage::JAVASCRIPT ||
         language == nsIProgrammingLanguage::JAVASCRIPT2) {
       ConsoleStackEntry& data = *callData->mStack.AppendElement();
 
       nsCString string;
       rv = stack->GetFilename(string);
       if (NS_FAILED(rv)) {
-        Throw(aCx, rv);
         return;
       }
 
       CopyUTF8toUTF16(string, data.mFilename);
 
       int32_t lineNumber;
       rv = stack->GetLineNumber(&lineNumber);
       if (NS_FAILED(rv)) {
-        Throw(aCx, rv);
         return;
       }
 
       data.mLineNumber = lineNumber;
 
       rv = stack->GetName(string);
       if (NS_FAILED(rv)) {
-        Throw(aCx, rv);
         return;
       }
 
       CopyUTF8toUTF16(string, data.mFunctionName);
 
       data.mLanguage = language;
     }
 
     nsCOMPtr<nsIStackFrame> caller;
     rv = stack->GetCaller(getter_AddRefs(caller));
     if (NS_FAILED(rv)) {
-      Throw(aCx, rv);
       return;
     }
 
     stack.swap(caller);
   } while (stack);
 
   // Monotonic timer for 'time' and 'timeEnd'
   if ((aMethodName == MethodTime || aMethodName == MethodTimeEnd) && mWindow) {
     nsGlobalWindow *win = static_cast<nsGlobalWindow*>(mWindow.get());
     MOZ_ASSERT(win);
 
     ErrorResult rv;
     nsRefPtr<nsPerformance> performance = win->GetPerformance(rv);
     if (rv.Failed()) {
-      Throw(aCx, rv.ErrorCode());
       return;
     }
 
     callData->mMonotonicTimer = performance->Now();
   }
 
   // The operation is completed. RAII class has to be disabled.
   raii.Finished();
@@ -997,17 +984,16 @@ Console::ProcessCallData(ConsoleCallData
   }
 
   else if (aData->mMethodName == MethodCount) {
     event.mCounter = IncreaseCounter(cx, frame, aData->mArguments);
   }
 
   JS::Rooted<JS::Value> eventValue(cx);
   if (!event.ToObject(cx, JS::NullPtr(), &eventValue)) {
-    Throw(cx, NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(cx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
   if (!JS_DefineProperty(cx, eventObj, "wrappedJSObject", eventValue,
                          nullptr, nullptr, JSPROP_ENUMERATE)) {
--- a/dom/base/Console.h
+++ b/dom/base/Console.h
@@ -82,22 +82,20 @@ public:
 
   void
   Time(JSContext* aCx, const JS::Handle<JS::Value> aTime);
 
   void
   TimeEnd(JSContext* aCx, const JS::Handle<JS::Value> aTime);
 
   void
-  Profile(JSContext* aCx, const Sequence<JS::Value>& aData,
-          ErrorResult& aRv);
+  Profile(JSContext* aCx, const Sequence<JS::Value>& aData);
 
   void
-  ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData,
-             ErrorResult& aRv);
+  ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
 
   void
   Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
 
   void
   Count(JSContext* aCx, const Sequence<JS::Value>& aData);
 
   void
@@ -169,18 +167,17 @@ private:
 
   // The method populates a Sequence from an array of JS::Value.
   void
   ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData,
                        Sequence<JS::Value>& aSequence);
 
   void
   ProfileMethod(JSContext* aCx, const nsAString& aAction,
-                const Sequence<JS::Value>& aData,
-                ErrorResult& aRv);
+                const Sequence<JS::Value>& aData);
 
   JS::Value
   IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
                    const nsTArray<JS::Heap<JS::Value>>& aArguments);
 
   void
   ClearConsoleData();
 
--- a/dom/webidl/Console.webidl
+++ b/dom/webidl/Console.webidl
@@ -15,20 +15,17 @@ interface Console {
   void trace();
   void dir(any... data);
   void group(any... data);
   void groupCollapsed(any... data);
   void groupEnd(any... data);
   void time(optional any time);
   void timeEnd(optional any time);
 
-  [Throws]
   void profile(any... data);
-
-  [Throws]
   void profileEnd(any... data);
 
   void assert(boolean condition, any... data);
   void count(any... data);
 
   void ___noSuchMethod__();
 };