Bug 1224596 part 11. Switch WorkerNavigator to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 24 Nov 2015 00:04:21 -0500
changeset 273877 a9f7956706f47f9d03bee0f1288919a1d3d3d281
parent 273876 123a397f5b7bbe0979ee2dc3146f4e12e46690d9
child 273878 318b72381dcb5f28830339f770370ba57a8730ed
push id68416
push userbzbarsky@mozilla.com
push dateTue, 24 Nov 2015 05:04:42 +0000
treeherdermozilla-inbound@227989411ad6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1224596
milestone45.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 1224596 part 11. Switch WorkerNavigator to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey
dom/webidl/Navigator.webidl
dom/workers/Navigator.cpp
dom/workers/Navigator.h
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -36,17 +36,17 @@ interface NavigatorID {
   [Constant, Cached]
   readonly attribute DOMString appCodeName; // constant "Mozilla"
   [Constant, Cached]
   readonly attribute DOMString appName;
   [Constant, Cached]
   readonly attribute DOMString appVersion;
   [Constant, Cached]
   readonly attribute DOMString platform;
-  [Constant, Cached]
+  [Constant, Cached, Throws=Workers]
   readonly attribute DOMString userAgent;
   [Constant, Cached]
   readonly attribute DOMString product; // constant "Gecko"
 
   // Everyone but WebKit/Blink supports this.  See bug 679971.
   [Exposed=Window]
   boolean taintEnabled(); // constant false
 };
--- a/dom/workers/Navigator.cpp
+++ b/dom/workers/Navigator.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "DataStore.h"
 
+#include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/DataStore.h"
 #include "mozilla/dom/DataStoreBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/PromiseWorkerProxy.h"
 #include "mozilla/dom/WorkerNavigatorBinding.h"
 
 #include "Navigator.h"
 #include "nsProxyRelease.h"
@@ -129,17 +130,21 @@ GetDataStoresProxyCloneCallbacksRead(JSC
     RefPtr<DataStoreChangeEventProxy> eventProxy =
       new DataStoreChangeEventProxy(workerPrivate, workerStore);
 
     // Add the DataStoreChangeEventProxy as an event listener on the main thread.
     RefPtr<DataStoreAddEventListenerRunnable> runnable =
       new DataStoreAddEventListenerRunnable(workerPrivate,
                                             backingStore,
                                             eventProxy);
-    runnable->Dispatch(aCx);
+    ErrorResult rv;
+    runnable->Dispatch(rv);
+    if (rv.MaybeSetPendingException(aCx)) {
+      return nullptr;
+    }
 
     // Point WorkerDataStore to DataStore.
     workerStore->SetBackingDataStore(backingStore);
 
     JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
     if (!global) {
       MOZ_ASSERT(false, "cannot get global!");
     } else {
@@ -223,26 +228,25 @@ public:
 
     // this might return null if the worker has started the close handler.
     mPromiseWorkerProxy =
       PromiseWorkerProxy::Create(aWorkerPrivate,
                                  aWorkerPromise,
                                  &kGetDataStoresCloneCallbacks);
   }
 
-  bool Dispatch(JSContext* aCx)
+  void Dispatch(ErrorResult& aRv)
   {
     if (mPromiseWorkerProxy) {
-      return WorkerMainThreadRunnable::Dispatch(aCx);
+      WorkerMainThreadRunnable::Dispatch(aRv);
     }
 
     // If the creation of mProxyWorkerProxy failed, the worker is terminating.
     // In this case we don't want to dispatch the runnable and we should stop
     // the promise chain here.
-    return true;
   }
 
 
 protected:
   virtual bool
   MainThreadRun() override
   {
     AssertIsOnMainThread();
@@ -280,17 +284,20 @@ WorkerNavigator::GetDataStores(JSContext
 
   RefPtr<Promise> promise = Promise::Create(workerPrivate->GlobalScope(), aRv);
   if (aRv.Failed()) {
     return nullptr;
   }
 
   RefPtr<NavigatorGetDataStoresRunnable> runnable =
     new NavigatorGetDataStoresRunnable(workerPrivate, promise, aName, aOwner, aRv);
-  runnable->Dispatch(aCx);
+  runnable->Dispatch(aRv);
+  if (aRv.Failed()) {
+    return nullptr;
+  }
 
   return promise.forget();
 }
 
 void
 WorkerNavigator::SetLanguages(const nsTArray<nsString>& aLanguages)
 {
   WorkerNavigatorBinding_workers::ClearCachedLanguagesValue(this);
@@ -376,22 +383,20 @@ public:
 
     return true;
   }
 };
 
 } // namespace
 
 void
-WorkerNavigator::GetUserAgent(nsString& aUserAgent) const
+WorkerNavigator::GetUserAgent(nsString& aUserAgent, ErrorResult& aRv) const
 {
   WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
   MOZ_ASSERT(workerPrivate);
 
   RefPtr<GetUserAgentRunnable> runnable =
     new GetUserAgentRunnable(workerPrivate, aUserAgent);
 
-  if (!runnable->Dispatch(workerPrivate->GetJSContext())) {
-    JS_ReportPendingException(workerPrivate->GetJSContext());
-  }
+  runnable->Dispatch(aRv);
 }
 
 END_WORKERS_NAMESPACE
--- a/dom/workers/Navigator.h
+++ b/dom/workers/Navigator.h
@@ -88,17 +88,17 @@ public:
     }
   }
 
   void GetLanguages(nsTArray<nsString>& aLanguages) const
   {
     aLanguages = mProperties.mLanguages;
   }
 
-  void GetUserAgent(nsString& aUserAgent) const;
+  void GetUserAgent(nsString& aUserAgent, ErrorResult& aRv) const;
 
   bool OnLine() const
   {
     return mOnline;
   }
 
   // Worker thread only!
   void SetOnLine(bool aOnline)