Bug 1259290: Part 1 - Remove unnecessary JS_ReportError calls. r=bz
authorKyle Huey <khuey@kylehuey.com>
Mon, 28 Mar 2016 10:28:14 -0700
changeset 290734 a25d3a1c24b73bdfedf2196c0cee3b37bfb606a1
parent 290733 360754dc00f6be0cfef2543f0db4fccfc8dffe11
child 290735 780e64f25e1a2bb3ef072ac83a5bc94d8c31dde2
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1259290
milestone48.0a1
Bug 1259290: Part 1 - Remove unnecessary JS_ReportError calls. r=bz
dom/webidl/WorkerDebuggerGlobalScope.webidl
dom/workers/WorkerPrivate.cpp
dom/workers/WorkerScope.cpp
dom/workers/WorkerScope.h
--- a/dom/webidl/WorkerDebuggerGlobalScope.webidl
+++ b/dom/webidl/WorkerDebuggerGlobalScope.webidl
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 [Global=(WorkerDebugger), Exposed=WorkerDebugger]
 interface WorkerDebuggerGlobalScope : EventTarget {
   [Throws]
   readonly attribute object global;
 
+  [Throws]
   object createSandbox(DOMString name, object prototype);
 
   [Throws]
   void loadSubScript(DOMString url, optional object sandbox);
 
   void enterEventLoop();
 
   void leaveEventLoop();
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -4092,17 +4092,16 @@ WorkerPrivate::Constructor(JSContext* aC
   // NB: This has to be done before creating the WorkerPrivate, because it will
   // attempt to use static variables that are initialized in the RuntimeService
   // constructor.
   RuntimeService* runtimeService;
 
   if (!parent) {
     runtimeService = RuntimeService::GetOrCreateService();
     if (!runtimeService) {
-      JS_ReportError(aCx, "Failed to create runtime service!");
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
   }
   else {
     runtimeService = RuntimeService::GetService();
   }
 
@@ -5871,17 +5870,18 @@ WorkerPrivate::SetTimeout(JSContext* aCx
   {
     MutexAutoLock lock(mMutex);
     currentStatus = mStatus;
   }
 
   // It's a script bug if setTimeout/setInterval are called from a close handler
   // so throw an exception.
   if (currentStatus == Closing) {
-    JS_ReportError(aCx, "Cannot schedule timeouts from the close handler!");
+    aRv.Throw(NS_ERROR_FAILURE);
+    return 0;
   }
 
   // If the worker is trying to call setTimeout/setInterval and the parent
   // thread has initiated the close process then just silently fail.
   if (currentStatus >= Closing) {
     aRv.Throw(NS_ERROR_FAILURE);
     return 0;
   }
--- a/dom/workers/WorkerScope.cpp
+++ b/dom/workers/WorkerScope.cpp
@@ -809,60 +809,59 @@ const js::Class workerdebuggersandbox_cl
       nullptr,
       workerdebuggersandbox_moved
     }, JS_NULL_OBJECT_OPS
 };
 
 void
 WorkerDebuggerGlobalScope::CreateSandbox(JSContext* aCx, const nsAString& aName,
                                          JS::Handle<JSObject*> aPrototype,
-                                         JS::MutableHandle<JSObject*> aResult)
+                                         JS::MutableHandle<JSObject*> aResult,
+                                         ErrorResult& aRv)
 {
   mWorkerPrivate->AssertIsOnWorkerThread();
 
+  aResult.set(nullptr);
+
   JS::CompartmentOptions options;
   options.creationOptions().setInvisibleToDebugger(true);
 
   JS::Rooted<JSObject*> sandbox(aCx,
     JS_NewGlobalObject(aCx, js::Jsvalify(&workerdebuggersandbox_class), nullptr,
                        JS::DontFireOnNewGlobalHook, options));
   if (!sandbox) {
-    JS_ReportError(aCx, "Can't create sandbox!");
-    aResult.set(nullptr);
+    aRv.NoteJSContextException(aCx);
     return;
   }
 
   {
     JSAutoCompartment ac(aCx, sandbox);
 
     JS::Rooted<JSObject*> prototype(aCx, aPrototype);
     if (!JS_WrapObject(aCx, &prototype)) {
-      JS_ReportError(aCx, "Can't wrap sandbox prototype!");
-      aResult.set(nullptr);
+      aRv.NoteJSContextException(aCx);
       return;
     }
 
     if (!JS_SetPrototype(aCx, sandbox, prototype)) {
-      JS_ReportError(aCx, "Can't set sandbox prototype!");
-      aResult.set(nullptr);
+      aRv.NoteJSContextException(aCx);
       return;
     }
 
     nsCOMPtr<nsIGlobalObject> globalObject =
       new WorkerDebuggerSandboxPrivate(sandbox);
 
     // Pass on ownership of globalObject to |sandbox|.
     JS_SetPrivate(sandbox, globalObject.forget().take());
   }
 
   JS_FireOnNewGlobalObject(aCx, sandbox);
 
   if (!JS_WrapObject(aCx, &sandbox)) {
-    JS_ReportError(aCx, "Can't wrap sandbox!");
-    aResult.set(nullptr);
+    aRv.NoteJSContextException(aCx);
     return;
   }
 
   aResult.set(sandbox);
 }
 
 void
 WorkerDebuggerGlobalScope::LoadSubScript(JSContext* aCx,
--- a/dom/workers/WorkerScope.h
+++ b/dom/workers/WorkerScope.h
@@ -305,17 +305,18 @@ public:
 
   void
   GetGlobal(JSContext* aCx, JS::MutableHandle<JSObject*> aGlobal,
             ErrorResult& aRv);
 
   void
   CreateSandbox(JSContext* aCx, const nsAString& aName,
                 JS::Handle<JSObject*> aPrototype,
-                JS::MutableHandle<JSObject*> aResult);
+                JS::MutableHandle<JSObject*> aResult,
+                ErrorResult& aRv);
 
   void
   LoadSubScript(JSContext* aCx, const nsAString& aURL,
                 const Optional<JS::Handle<JSObject*>>& aSandbox,
                 ErrorResult& aRv);
 
   void
   EnterEventLoop();