Bug 1000947 - Console::Methods must not throw exceptions, r=bz
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 29 Apr 2014 07:49:57 +0100
changeset 181063 05babc6dd906cc356b4572e7aa7fabbc254dc375
parent 181062 64ce640f432e28a628b2a21ff7e392a475e87f0c
child 181064 2141c8507506db7dc01ed15dffe5aa94dc574c1c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbz
bugs1000947
milestone32.0a1
Bug 1000947 - Console::Methods must not throw exceptions, r=bz
dom/base/Console.cpp
dom/base/Console.h
dom/webidl/Console.webidl
--- a/dom/base/Console.cpp
+++ b/dom/base/Console.cpp
@@ -471,20 +471,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;
@@ -657,72 +654,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, &eventValue)) {
-    aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(aCx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
-  if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue, JSPROP_ENUMERATE)) {
-    aRv.Throw(NS_ERROR_FAILURE);
+  if (!JS_DefineProperty(aCx, eventObj, "wrappedJSObject", eventValue,
+      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);
   }
@@ -831,96 +825,91 @@ 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 = ShouldIncludeStackrace(aMethodName) ?
                       DEFAULT_MAX_STACKTRACE_DEPTH : 1;
   nsCOMPtr<nsIStackFrame> stack = CreateStack(aCx, maxDepth);
 
   if (!stack) {
-    Throw(aCx, NS_ERROR_FAILURE);
     return;
   }
 
   // Walk up to the first JS stack frame and save it if we find it.
   do {
     uint32_t language;
     nsresult rv = stack->GetLanguage(&language);
     if (NS_FAILED(rv)) {
-      Throw(aCx, rv);
       return;
     }
 
     if (language == nsIProgrammingLanguage::JAVASCRIPT ||
         language == nsIProgrammingLanguage::JAVASCRIPT2) {
       callData->mTopStackFrame.construct();
       nsresult rv = StackFrameToStackEntry(stack,
                                            callData->mTopStackFrame.ref(),
                                            language);
       if (NS_FAILED(rv)) {
-        Throw(aCx, rv);
         return;
       }
 
       break;
     }
 
     nsCOMPtr<nsIStackFrame> caller;
     rv = stack->GetCaller(getter_AddRefs(caller));
     if (NS_FAILED(rv)) {
-      Throw(aCx, rv);
       return;
     }
 
     stack.swap(caller);
   } while (stack);
 
   if (NS_IsMainThread()) {
     callData->mStack = stack;
   } else {
     // nsIStackFrame is not threadsafe, so we need to snapshot it now,
     // before we post our runnable to the main thread.
     callData->mReifiedStack.construct();
     nsresult rv = ReifyStack(stack, callData->mReifiedStack.ref());
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      Throw(aCx, rv);
       return;
     }
   }
 
   // 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();
@@ -1106,17 +1095,16 @@ Console::ProcessCallData(ConsoleCallData
   // which one?  We could cheat and try to get the underlying JSObject* of
   // mStorage, but that's a bit fragile.  Instead, we just use the junk scope,
   // with explicit permission from the XPConnect module owner.  If you're
   // tempted to do that anywhere else, talk to said module owner first.
   JSAutoCompartment ac2(cx, xpc::GetJunkScope());
 
   JS::Rooted<JS::Value> eventValue(cx);
   if (!event.ToObject(cx, &eventValue)) {
-    Throw(cx, NS_ERROR_FAILURE);
     return;
   }
 
   JS::Rooted<JSObject*> eventObj(cx, &eventValue.toObject());
   MOZ_ASSERT(eventObj);
 
   if (!JS_DefineProperty(cx, eventObj, "wrappedJSObject", eventValue, JSPROP_ENUMERATE)) {
     return;
--- 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
@@ -176,18 +174,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__();
 };