Bug 1155546 - Implement WorkerControlRunnable::Cancel(), r=bent
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 22 Apr 2015 09:03:52 +0200
changeset 259379 91e9b0c36889b9c42c5b295f60d63015130f060c
parent 259378 65050168e0b7164010bb2fc7e7ce02139c2d8da1
child 259380 100b9eafbbfed8dee4827abe56bacea81c9a1bef
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1155546
milestone40.0a1
Bug 1155546 - Implement WorkerControlRunnable::Cancel(), r=bent
dom/workers/WorkerRunnable.cpp
dom/workers/WorkerRunnable.h
--- a/dom/workers/WorkerRunnable.cpp
+++ b/dom/workers/WorkerRunnable.cpp
@@ -300,17 +300,22 @@ WorkerRunnable::Run()
   }
 
   // Track down the appropriate global to use for the AutoJSAPI/AutoEntryScript.
   nsCOMPtr<nsIGlobalObject> globalObject;
   bool isMainThread = !targetIsWorkerThread && !mWorkerPrivate->GetParent();
   MOZ_ASSERT(isMainThread == NS_IsMainThread());
   nsRefPtr<WorkerPrivate> kungFuDeathGrip;
   if (targetIsWorkerThread) {
-    JSObject* global = JS::CurrentGlobalOrNull(GetCurrentThreadJSContext());
+    JSContext* cx = GetCurrentThreadJSContext();
+    if (NS_WARN_IF(!cx)) {
+      return NS_ERROR_FAILURE;
+    }
+
+    JSObject* global = JS::CurrentGlobalOrNull(cx);
     if (global) {
       globalObject = GetGlobalObjectForGlobal(global);
     } else {
       globalObject = DefaultGlobalObject();
     }
   } else {
     kungFuDeathGrip = mWorkerPrivate;
     if (isMainThread) {
@@ -494,16 +499,26 @@ WorkerControlRunnable::WorkerControlRunn
 {
   MOZ_ASSERT(aWorkerPrivate);
   MOZ_ASSERT(aBehavior == ParentThreadUnchangedBusyCount ||
              aBehavior == WorkerThreadUnchangedBusyCount,
              "WorkerControlRunnables should not modify the busy count");
 }
 #endif
 
+NS_IMETHODIMP
+WorkerControlRunnable::Cancel()
+{
+  if (NS_FAILED(Run())) {
+    NS_WARNING("WorkerControlRunnable::Run() failed.");
+  }
+
+  return WorkerRunnable::Cancel();
+}
+
 bool
 WorkerControlRunnable::DispatchInternal()
 {
   if (mBehavior == WorkerThreadUnchangedBusyCount) {
     return NS_SUCCEEDED(mWorkerPrivate->DispatchControlRunnable(this));
   }
 
   if (WorkerPrivate* parent = mWorkerPrivate->GetParent()) {
--- a/dom/workers/WorkerRunnable.h
+++ b/dom/workers/WorkerRunnable.h
@@ -315,16 +315,19 @@ protected:
 #else
   : WorkerRunnable(aWorkerPrivate, aBehavior)
   { }
 #endif
 
   virtual ~WorkerControlRunnable()
   { }
 
+  NS_IMETHOD
+  Cancel() override;
+
 public:
   NS_DECL_ISUPPORTS_INHERITED
 
 private:
   virtual bool
   DispatchInternal() override;
 
   // Should only be called by WorkerPrivate::DoRunLoop.
@@ -397,14 +400,14 @@ protected:
   ~WorkerMainThreadRunnable() {}
 
   virtual bool MainThreadRun() = 0;
 
 public:
   bool Dispatch(JSContext* aCx);
 
 private:
-  NS_IMETHOD Run() override;  
+  NS_IMETHOD Run() override;
 };
 
 END_WORKERS_NAMESPACE
 
 #endif // mozilla_dom_workers_workerrunnable_h__