Browse Source

Backports for bug 1413112

Ian Neal 5 months ago
parent
commit
42fefdfb34

+ 8 - 8
mozilla-release/patches/1403027-63a1.patch

@@ -2,7 +2,7 @@
 # User Thomas Wisniewski <wisniewskit@gmail.com>
 # Date 1516845544 18000
 # Node ID f839685ceb8eebc50fa69c9273141a4bdc8ce1e2
-# Parent  0fb3fef69fe19c1a204309ef07050bef0a9d44e0
+# Parent  c87ed26d521b8ea454139959af87aad52696f502
 Bug 1403027 - Do not throw from PerformanceObserver.observe when none of the entryTypes are known (log a JS console warning instead); r=bz
 
 MozReview-Commit-ID: Lx2cjWDX8sh
@@ -10,7 +10,7 @@ MozReview-Commit-ID: Lx2cjWDX8sh
 diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties
 --- a/dom/locales/en-US/chrome/dom/dom.properties
 +++ b/dom/locales/en-US/chrome/dom/dom.properties
-@@ -355,8 +355,9 @@ ScriptSourceMalformed=<script> source URI is malformed: “%S”.
+@@ -354,8 +354,9 @@ ScriptSourceMalformed=<script> source URI is malformed: “%S”.
  ModuleSourceMalformed=Module source URI is malformed: “%S”.
  # LOCALIZATION NOTE: Do not translate "<script>".
  ScriptSourceNotAllowed=<script> source URI is not allowed in this document: “%S”.
@@ -372,7 +372,7 @@ diff --git a/dom/webidl/PerformanceObserver.webidl b/dom/webidl/PerformanceObser
 diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
 --- a/dom/workers/WorkerPrivate.cpp
 +++ b/dom/workers/WorkerPrivate.cpp
-@@ -953,65 +953,74 @@ private:
+@@ -554,65 +554,74 @@ private:
    {
      return aWorkerPrivate->ThawInternal();
    }
@@ -452,11 +452,11 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
    }
  };
  
- class ReportErrorRunnable final : public WorkerRunnable
+ class TimerRunnable final : public WorkerRunnable,
+                             public nsITimerCallback,
+                             public nsINamed
  {
-   WorkerErrorReport mReport;
- 
-@@ -6414,22 +6423,31 @@ WorkerPrivate::ReportError(JSContext* aC
+@@ -5070,22 +5079,31 @@ WorkerPrivate::ReportError(JSContext* aC
  
    mErrorHandlerRecursionCount--;
  }
@@ -492,7 +492,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
 diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
 --- a/dom/workers/WorkerPrivate.h
 +++ b/dom/workers/WorkerPrivate.h
-@@ -1237,16 +1237,19 @@ public:
+@@ -1143,16 +1143,19 @@ public:
  
    void
    ReportError(JSContext* aCx, JS::ConstUTF8CharsZ aToStringResult,

+ 754 - 0
mozilla-release/patches/1413112-1-60a1.patch

@@ -0,0 +1,754 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303404 -3600
+# Node ID 76dc85918f42659123647db7265b9cc09b2cde83
+# Parent  c672dae4313c38caf94f7278c28292aa3cebb517
+Bug 1413112 - Renaming Workers.h to WorkerCommon.h, r=bkelly
+
+diff --git a/caps/nsJSPrincipals.cpp b/caps/nsJSPrincipals.cpp
+--- a/caps/nsJSPrincipals.cpp
++++ b/caps/nsJSPrincipals.cpp
+@@ -11,17 +11,17 @@
+ #include "plstr.h"
+ #include "nsCOMPtr.h"
+ #include "nsIServiceManager.h"
+ #include "nsMemory.h"
+ #include "nsStringBuffer.h"
+ 
+ #include "mozilla/dom/StructuredCloneTags.h"
+ // for mozilla::dom::workers::kJSPrincipalsDebugToken
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ #include "mozilla/ipc/BackgroundUtils.h"
+ 
+ using namespace mozilla;
+ using namespace mozilla::ipc;
+ 
+ NS_IMETHODIMP_(MozExternalRefCountType)
+ nsJSPrincipals::AddRef()
+ {
+diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp
+--- a/dom/base/nsGlobalWindow.cpp
++++ b/dom/base/nsGlobalWindow.cpp
+@@ -80,17 +80,17 @@
+ #include "mozilla/Sprintf.h"
+ #include "mozilla/Unused.h"
+ 
+ // Other Classes
+ #include "mozilla/dom/BarProps.h"
+ #include "nsContentCID.h"
+ #include "nsLayoutStatics.h"
+ #include "nsCCUncollectableMarker.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ #include "mozilla/dom/ToJSValue.h"
+ #include "nsJSPrincipals.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/Debug.h"
+ #include "mozilla/EventListenerManager.h"
+ #include "mozilla/EventStates.h"
+ #include "mozilla/MouseEvents.h"
+ #include "mozilla/ProcessHangMonitor.h"
+diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp
+--- a/dom/fetch/Fetch.cpp
++++ b/dom/fetch/Fetch.cpp
+@@ -39,20 +39,20 @@
+ #include "mozilla/dom/ScriptSettings.h"
+ #include "mozilla/dom/URLSearchParams.h"
+ 
+ #include "BodyExtractor.h"
+ #include "FetchObserver.h"
+ #include "InternalRequest.h"
+ #include "InternalResponse.h"
+ 
++#include "WorkerCommon.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+-#include "Workers.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ using namespace workers;
+ 
+ namespace {
+ 
+diff --git a/dom/fetch/FetchConsumer.cpp b/dom/fetch/FetchConsumer.cpp
+--- a/dom/fetch/FetchConsumer.cpp
++++ b/dom/fetch/FetchConsumer.cpp
+@@ -5,20 +5,20 @@
+  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+ #include "Fetch.h"
+ #include "FetchConsumer.h"
+ 
+ #include "mozilla/ipc/PBackgroundSharedTypes.h"
+ #include "nsIInputStreamPump.h"
+ #include "nsProxyRelease.h"
++#include "WorkerCommon.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+-#include "Workers.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ using namespace workers;
+ 
+ namespace {
+ 
+diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp
+--- a/dom/fetch/FetchDriver.cpp
++++ b/dom/fetch/FetchDriver.cpp
+@@ -27,17 +27,17 @@
+ #include "nsPrintfCString.h"
+ #include "nsProxyRelease.h"
+ #include "nsStreamUtils.h"
+ #include "nsStringStream.h"
+ #include "nsHttpChannel.h"
+ 
+ #include "mozilla/dom/File.h"
+ #include "mozilla/dom/PerformanceStorage.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ #include "mozilla/EventStateManager.h"
+ #include "mozilla/ipc/PBackgroundSharedTypes.h"
+ #include "mozilla/Unused.h"
+ 
+ #include "Fetch.h"
+ #include "FetchUtil.h"
+ #include "InternalRequest.h"
+ #include "InternalResponse.h"
+diff --git a/dom/fetch/FetchStream.cpp b/dom/fetch/FetchStream.cpp
+--- a/dom/fetch/FetchStream.cpp
++++ b/dom/fetch/FetchStream.cpp
+@@ -4,18 +4,18 @@
+  * 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 "FetchStream.h"
+ #include "mozilla/dom/DOMException.h"
+ #include "nsITransport.h"
+ #include "nsIStreamTransportService.h"
+ #include "nsProxyRelease.h"
++#include "WorkerCommon.h"
+ #include "WorkerPrivate.h"
+-#include "Workers.h"
+ 
+ #define FETCH_STREAM_FLAG 0
+ 
+ static NS_DEFINE_CID(kStreamTransportServiceCID,
+                      NS_STREAMTRANSPORTSERVICE_CID);
+ 
+ namespace mozilla {
+ namespace dom {
+diff --git a/dom/fetch/InternalRequest.cpp b/dom/fetch/InternalRequest.cpp
+--- a/dom/fetch/InternalRequest.cpp
++++ b/dom/fetch/InternalRequest.cpp
+@@ -8,17 +8,17 @@
+ 
+ #include "nsIContentPolicy.h"
+ #include "nsIDocument.h"
+ #include "nsStreamUtils.h"
+ 
+ #include "mozilla/ErrorResult.h"
+ #include "mozilla/dom/FetchTypes.h"
+ #include "mozilla/dom/ScriptSettings.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ 
+ #include "WorkerPrivate.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ // The global is used to extract the principal.
+ already_AddRefed<InternalRequest>
+ InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const
+diff --git a/dom/notification/NotificationEvent.h b/dom/notification/NotificationEvent.h
+--- a/dom/notification/NotificationEvent.h
++++ b/dom/notification/NotificationEvent.h
+@@ -5,17 +5,17 @@
+  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+ #ifndef mozilla_dom_workers_notificationevent_h__
+ #define mozilla_dom_workers_notificationevent_h__
+ 
+ #include "mozilla/dom/Event.h"
+ #include "mozilla/dom/NotificationEventBinding.h"
+ #include "mozilla/dom/ServiceWorkerEvents.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ class ServiceWorker;
+ class ServiceWorkerClient;
+ 
+ class NotificationEvent final : public ExtendableEvent
+ {
+diff --git a/dom/push/PushSubscription.cpp b/dom/push/PushSubscription.cpp
+--- a/dom/push/PushSubscription.cpp
++++ b/dom/push/PushSubscription.cpp
+@@ -13,17 +13,17 @@
+ #include "mozilla/Unused.h"
+ 
+ #include "mozilla/dom/Promise.h"
+ #include "mozilla/dom/PromiseWorkerProxy.h"
+ #include "mozilla/dom/PushSubscriptionOptions.h"
+ #include "mozilla/dom/PushUtil.h"
+ #include "mozilla/dom/WorkerPrivate.h"
+ #include "mozilla/dom/WorkerScope.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ using namespace workers;
+ 
+ namespace {
+ 
+diff --git a/dom/serviceworkers/ServiceWorkerEvents.h b/dom/serviceworkers/ServiceWorkerEvents.h
+--- a/dom/serviceworkers/ServiceWorkerEvents.h
++++ b/dom/serviceworkers/ServiceWorkerEvents.h
+@@ -10,17 +10,17 @@
+ #include "mozilla/dom/DOMPrefs.h"
+ #include "mozilla/dom/Event.h"
+ #include "mozilla/dom/ExtendableEventBinding.h"
+ #include "mozilla/dom/ExtendableMessageEventBinding.h"
+ #include "mozilla/dom/FetchEventBinding.h"
+ #include "mozilla/dom/File.h"
+ #include "mozilla/dom/Promise.h"
+ #include "mozilla/dom/Response.h"
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ 
+ #include "nsProxyRelease.h"
+ #include "nsContentUtils.h"
+ 
+ class nsIInterceptedChannel;
+ 
+ namespace mozilla {
+ namespace dom {
+diff --git a/dom/serviceworkers/ServiceWorkerInfo.h b/dom/serviceworkers/ServiceWorkerInfo.h
+--- a/dom/serviceworkers/ServiceWorkerInfo.h
++++ b/dom/serviceworkers/ServiceWorkerInfo.h
+@@ -4,17 +4,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/. */
+ 
+ #ifndef mozilla_dom_serviceworkerinfo_h
+ #define mozilla_dom_serviceworkerinfo_h
+ 
+ #include "MainThreadUtils.h"
+ #include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ #include "nsIServiceWorkerManager.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ class ServiceWorker;
+ class ServiceWorkerPrivate;
+ 
+diff --git a/dom/serviceworkers/ServiceWorkerJob.cpp b/dom/serviceworkers/ServiceWorkerJob.cpp
+--- a/dom/serviceworkers/ServiceWorkerJob.cpp
++++ b/dom/serviceworkers/ServiceWorkerJob.cpp
+@@ -3,17 +3,17 @@
+ /* 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 "ServiceWorkerJob.h"
+ 
+ #include "nsProxyRelease.h"
+ #include "nsThreadUtils.h"
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ ServiceWorkerJob::Type
+ ServiceWorkerJob::GetType() const
+ {
+   return mType;
+diff --git a/dom/serviceworkers/ServiceWorkerJobQueue.cpp b/dom/serviceworkers/ServiceWorkerJobQueue.cpp
+--- a/dom/serviceworkers/ServiceWorkerJobQueue.cpp
++++ b/dom/serviceworkers/ServiceWorkerJobQueue.cpp
+@@ -2,17 +2,17 @@
+ /* 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 "ServiceWorkerJobQueue.h"
+ 
+ #include "ServiceWorkerJob.h"
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ class ServiceWorkerJobQueue::Callback final : public ServiceWorkerJob::Callback
+ {
+   RefPtr<ServiceWorkerJobQueue> mQueue;
+ 
+diff --git a/dom/serviceworkers/ServiceWorkerRegisterJob.cpp b/dom/serviceworkers/ServiceWorkerRegisterJob.cpp
+--- a/dom/serviceworkers/ServiceWorkerRegisterJob.cpp
++++ b/dom/serviceworkers/ServiceWorkerRegisterJob.cpp
+@@ -1,17 +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 "ServiceWorkerRegisterJob.h"
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ ServiceWorkerRegisterJob::ServiceWorkerRegisterJob(
+     nsIPrincipal* aPrincipal,
+     const nsACString& aScope,
+     const nsACString& aScriptSpec,
+diff --git a/dom/serviceworkers/ServiceWorkerRegistration.cpp b/dom/serviceworkers/ServiceWorkerRegistration.cpp
+--- a/dom/serviceworkers/ServiceWorkerRegistration.cpp
++++ b/dom/serviceworkers/ServiceWorkerRegistration.cpp
+@@ -25,17 +25,17 @@
+ 
+ #include "nsIDocument.h"
+ #include "nsIServiceWorkerManager.h"
+ #include "nsISupportsPrimitives.h"
+ #include "nsPIDOMWindow.h"
+ #include "nsContentUtils.h"
+ 
+ #include "WorkerPrivate.h"
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "WorkerScope.h"
+ 
+ using namespace mozilla::dom::workers;
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ ////////////////////////////////////////////////////
+diff --git a/dom/serviceworkers/ServiceWorkerScriptCache.cpp b/dom/serviceworkers/ServiceWorkerScriptCache.cpp
+--- a/dom/serviceworkers/ServiceWorkerScriptCache.cpp
++++ b/dom/serviceworkers/ServiceWorkerScriptCache.cpp
+@@ -22,17 +22,17 @@
+ 
+ #include "nsIInputStreamPump.h"
+ #include "nsIPrincipal.h"
+ #include "nsIScriptError.h"
+ #include "nsIScriptSecurityManager.h"
+ #include "nsContentUtils.h"
+ #include "nsNetUtil.h"
+ #include "ServiceWorkerManager.h"
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "nsStringStream.h"
+ 
+ using mozilla::dom::cache::Cache;
+ using mozilla::dom::cache::CacheStorage;
+ using mozilla::ipc::PrincipalInfo;
+ 
+ namespace mozilla {
+ namespace dom {
+diff --git a/dom/serviceworkers/ServiceWorkerUpdateJob.cpp b/dom/serviceworkers/ServiceWorkerUpdateJob.cpp
+--- a/dom/serviceworkers/ServiceWorkerUpdateJob.cpp
++++ b/dom/serviceworkers/ServiceWorkerUpdateJob.cpp
+@@ -4,17 +4,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/. */
+ 
+ #include "ServiceWorkerUpdateJob.h"
+ 
+ #include "nsIScriptError.h"
+ #include "nsIURL.h"
+ #include "ServiceWorkerScriptCache.h"
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ namespace {
+ 
+ /**
+  * The spec mandates slightly different behaviors for computing the scope
+diff --git a/dom/workers/ChromeWorkerScope.h b/dom/workers/ChromeWorkerScope.h
+--- a/dom/workers/ChromeWorkerScope.h
++++ b/dom/workers/ChromeWorkerScope.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_chromeworkerscope_h__
+ #define mozilla_dom_workers_chromeworkerscope_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ bool
+ DefineChromeWorkerFunctions(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
+ 
+ END_WORKERS_NAMESPACE
+ 
+diff --git a/dom/workers/FileReaderSync.h b/dom/workers/FileReaderSync.h
+--- a/dom/workers/FileReaderSync.h
++++ b/dom/workers/FileReaderSync.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_filereadersync_h__
+ #define mozilla_dom_filereadersync_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ class nsIInputStream;
+ 
+ namespace mozilla {
+ class ErrorResult;
+ 
+ namespace dom {
+ class Blob;
+diff --git a/dom/workers/Principal.h b/dom/workers/Principal.h
+--- a/dom/workers/Principal.h
++++ b/dom/workers/Principal.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_principal_h__
+ #define mozilla_dom_workers_principal_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ JSPrincipals*
+ GetWorkerPrincipal();
+ 
+ void
+ DestroyWorkerPrincipals(JSPrincipals* aPrincipals);
+diff --git a/dom/workers/Queue.h b/dom/workers/Queue.h
+--- a/dom/workers/Queue.h
++++ b/dom/workers/Queue.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_queue_h__
+ #define mozilla_dom_workers_queue_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "mozilla/Mutex.h"
+ #include "nsTArray.h"
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ template <typename T, int TCount>
+ struct StorageWithTArray
+diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h
+--- a/dom/workers/RuntimeService.h
++++ b/dom/workers/RuntimeService.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_runtimeservice_h__
+ #define mozilla_dom_workers_runtimeservice_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "nsIObserver.h"
+ 
+ #include "mozilla/dom/BindingDeclarations.h"
+ #include "nsClassHashtable.h"
+ #include "nsHashKeys.h"
+ #include "nsTArray.h"
+ 
+diff --git a/dom/workers/ScriptLoader.h b/dom/workers/ScriptLoader.h
+--- a/dom/workers/ScriptLoader.h
++++ b/dom/workers/ScriptLoader.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_scriptloader_h__
+ #define mozilla_dom_workers_scriptloader_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "nsIContentPolicyBase.h"
+ #include "nsStringFwd.h"
+ 
+ class nsIPrincipal;
+ class nsIURI;
+ class nsIDocument;
+ class nsILoadGroup;
+ class nsIChannel;
+diff --git a/dom/workers/SharedWorker.h b/dom/workers/SharedWorker.h
+--- a/dom/workers/SharedWorker.h
++++ b/dom/workers/SharedWorker.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_sharedworker_h__
+ #define mozilla_dom_workers_sharedworker_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "mozilla/dom/BindingDeclarations.h"
+ #include "mozilla/DOMEventTargetHelper.h"
+ 
+ class nsIDOMEvent;
+ class nsPIDOMWindowInner;
+ 
+ namespace mozilla {
+diff --git a/dom/workers/Workers.h b/dom/workers/WorkerCommon.h
+rename from dom/workers/Workers.h
+rename to dom/workers/WorkerCommon.h
+--- a/dom/workers/Workers.h
++++ b/dom/workers/WorkerCommon.h
+@@ -1,16 +1,16 @@
+ /* -*- 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/. */
+ 
+-#ifndef mozilla_dom_workers_workers_h__
+-#define mozilla_dom_workers_workers_h__
++#ifndef mozilla_dom_workers_WorkerCommon_h
++#define mozilla_dom_workers_WorkerCommon_h
+ 
+ #include "jsapi.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/Maybe.h"
+ #include "mozilla/Mutex.h"
+ #include <stdint.h>
+ #include "nsAutoPtr.h"
+ #include "nsCOMPtr.h"
+@@ -375,9 +375,9 @@ IsWorkerGlobal(JSObject* global);
+ bool
+ IsDebuggerGlobal(JSObject* global);
+ 
+ bool
+ IsDebuggerSandbox(JSObject* object);
+ 
+ END_WORKERS_NAMESPACE
+ 
+-#endif // mozilla_dom_workers_workers_h__
++#endif // mozilla_dom_workers_WorkerCommon_h
+diff --git a/dom/workers/WorkerDebuggerManager.h b/dom/workers/WorkerDebuggerManager.h
+--- a/dom/workers/WorkerDebuggerManager.h
++++ b/dom/workers/WorkerDebuggerManager.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerdebuggermanager_h
+ #define mozilla_dom_workers_workerdebuggermanager_h
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "nsIObserver.h"
+ #include "nsIWorkerDebuggerManager.h"
+ 
+ #include "nsServiceManagerUtils.h"
+ #include "nsTArray.h"
+ #include "nsThreadUtils.h"
+ 
+diff --git a/dom/workers/WorkerHolder.h b/dom/workers/WorkerHolder.h
+--- a/dom/workers/WorkerHolder.h
++++ b/dom/workers/WorkerHolder.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_WorkerHolder_h
+ #define mozilla_dom_workers_WorkerHolder_h
+ 
+-#include "mozilla/dom/workers/Workers.h"
++#include "mozilla/dom/workers/WorkerCommon.h"
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ /**
+  * Use this chart to help figure out behavior during each of the closing
+  * statuses. Details below.
+  *
+  * +==============================================================+
+diff --git a/dom/workers/WorkerLocation.h b/dom/workers/WorkerLocation.h
+--- a/dom/workers/WorkerLocation.h
++++ b/dom/workers/WorkerLocation.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_location_h__
+ #define mozilla_dom_location_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "WorkerPrivate.h"
+ #include "nsWrapperCache.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ class WorkerLocation final : public nsWrapperCache
+ {
+diff --git a/dom/workers/WorkerNavigator.h b/dom/workers/WorkerNavigator.h
+--- a/dom/workers/WorkerNavigator.h
++++ b/dom/workers/WorkerNavigator.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workernavigator_h__
+ #define mozilla_dom_workernavigator_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "RuntimeService.h"
+ #include "nsString.h"
+ #include "nsWrapperCache.h"
+ #include "mozilla/dom/BindingDeclarations.h"
+ #include "mozilla/dom/StorageManager.h"
+ 
+ namespace mozilla {
+ namespace dom {
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
+--- a/dom/workers/WorkerPrivate.h
++++ b/dom/workers/WorkerPrivate.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerprivate_h__
+ #define mozilla_dom_workers_workerprivate_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "js/CharacterEncoding.h"
+ #include "nsIContentPolicy.h"
+ #include "nsIContentSecurityPolicy.h"
+ #include "nsILoadGroup.h"
+ #include "nsIWorkerDebugger.h"
+ #include "nsPIDOMWindow.h"
+ 
+diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h
+--- a/dom/workers/WorkerRunnable.h
++++ b/dom/workers/WorkerRunnable.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerrunnable_h__
+ #define mozilla_dom_workers_workerrunnable_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ 
+ #include "nsICancelableRunnable.h"
+ 
+ #include "mozilla/Atomics.h"
+ #include "nsISupportsImpl.h"
+ #include "nsThreadUtils.h" /* nsRunnable */
+ 
+ struct JSContext;
+diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
+--- a/dom/workers/WorkerScope.h
++++ b/dom/workers/WorkerScope.h
+@@ -2,17 +2,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workerscope_h__
+ #define mozilla_dom_workerscope_h__
+ 
+-#include "Workers.h"
++#include "WorkerCommon.h"
+ #include "mozilla/DOMEventTargetHelper.h"
+ #include "mozilla/dom/Headers.h"
+ #include "mozilla/dom/RequestBinding.h"
+ #include "nsWeakReference.h"
+ #include "mozilla/dom/ImageBitmapSource.h"
+ 
+ namespace mozilla {
+ namespace dom {
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -14,18 +14,18 @@ EXPORTS.mozilla.dom += [
+     'WorkerNavigator.h',
+     'WorkerPrivate.h',
+     'WorkerRunnable.h',
+     'WorkerScope.h',
+ ]
+ 
+ EXPORTS.mozilla.dom.workers += [
+     'RuntimeService.h',
++    'WorkerCommon.h',
+     'WorkerDebuggerManager.h',
+-    'Workers.h',
+ ]
+ 
+ # Stuff needed for the bindings, not really public though.
+ EXPORTS.mozilla.dom.workers.bindings += [
+     'SharedWorker.h',
+     'WorkerHolder.h',
+     'WorkerHolderToken.h',
+ ]

+ 405 - 0
mozilla-release/patches/1413112-2-60a1.patch

@@ -0,0 +1,405 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303425 -3600
+# Node ID 1bad9d53ed36aa1642eb8d51f2ce01a5f9192810
+# Parent  242c7096ba50f8d9aef9a9c8fac701a31fb0cbab
+Bug 1413112 - Moving MessageEventRunnable out of WorkerPrivate.cpp, r=bkelly
+
+diff --git a/dom/workers/MessageEventRunnable.cpp b/dom/workers/MessageEventRunnable.cpp
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/MessageEventRunnable.cpp
+@@ -0,0 +1,154 @@
++/* -*- 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 "MessageEventRunnable.h"
++
++#include "mozilla/dom/MessageEvent.h"
++#include "mozilla/dom/MessageEventBinding.h"
++#include "mozilla/TimelineConsumers.h"
++#include "mozilla/WorkerTimelineMarker.h"
++#include "nsQueryObject.h"
++#include "WorkerPrivate.h"
++#include "WorkerScope.h"
++
++BEGIN_WORKERS_NAMESPACE
++
++MessageEventRunnable::MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
++                                           TargetAndBusyBehavior aBehavior)
++  : WorkerRunnable(aWorkerPrivate, aBehavior)
++  , StructuredCloneHolder(CloningSupported, TransferringSupported,
++                          StructuredCloneScope::SameProcessDifferentThread)
++{
++}
++
++bool
++MessageEventRunnable::DispatchDOMEvent(JSContext* aCx,
++                                       WorkerPrivate* aWorkerPrivate,
++                                       DOMEventTargetHelper* aTarget,
++                                       bool aIsMainThread)
++{
++  nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(aTarget->GetParentObject());
++
++  // For some workers without window, parent is null and we try to find it
++  // from the JS Context.
++  if (!parent) {
++    JS::Rooted<JSObject*> globalObject(aCx, JS::CurrentGlobalOrNull(aCx));
++    if (NS_WARN_IF(!globalObject)) {
++      return false;
++    }
++
++    parent = xpc::NativeGlobal(globalObject);
++    if (NS_WARN_IF(!parent)) {
++      return false;
++    }
++  }
++
++  MOZ_ASSERT(parent);
++
++  JS::Rooted<JS::Value> messageData(aCx);
++  IgnoredErrorResult rv;
++
++  UniquePtr<AbstractTimelineMarker> start;
++  UniquePtr<AbstractTimelineMarker> end;
++  RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
++  bool isTimelineRecording = timelines && !timelines->IsEmpty();
++
++  if (isTimelineRecording) {
++    start = MakeUnique<WorkerTimelineMarker>(aIsMainThread
++      ? ProfileTimelineWorkerOperationType::DeserializeDataOnMainThread
++      : ProfileTimelineWorkerOperationType::DeserializeDataOffMainThread,
++      MarkerTracingType::START);
++  }
++
++  Read(parent, aCx, &messageData, rv);
++
++  if (isTimelineRecording) {
++    end = MakeUnique<WorkerTimelineMarker>(aIsMainThread
++      ? ProfileTimelineWorkerOperationType::DeserializeDataOnMainThread
++      : ProfileTimelineWorkerOperationType::DeserializeDataOffMainThread,
++      MarkerTracingType::END);
++    timelines->AddMarkerForAllObservedDocShells(start);
++    timelines->AddMarkerForAllObservedDocShells(end);
++  }
++
++  if (NS_WARN_IF(rv.Failed())) {
++    DispatchError(aCx, aTarget);
++    return false;
++  }
++
++  Sequence<OwningNonNull<MessagePort>> ports;
++  if (!TakeTransferredPortsAsSequence(ports)) {
++    DispatchError(aCx, aTarget);
++    return false;
++  }
++
++  nsCOMPtr<nsIDOMEvent> domEvent;
++  RefPtr<MessageEvent> event = new MessageEvent(aTarget, nullptr, nullptr);
++  event->InitMessageEvent(nullptr,
++                          NS_LITERAL_STRING("message"),
++                          false /* non-bubbling */,
++                          false /* cancelable */,
++                          messageData,
++                          EmptyString(),
++                          EmptyString(),
++                          nullptr,
++                          ports);
++  domEvent = do_QueryObject(event);
++
++  domEvent->SetTrusted(true);
++
++  bool dummy;
++  aTarget->DispatchEvent(domEvent, &dummy);
++
++  return true;
++}
++
++bool
++MessageEventRunnable::WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
++{
++  if (mBehavior == ParentThreadUnchangedBusyCount) {
++    // Don't fire this event if the JS object has been disconnected from the
++    // private object.
++    if (!aWorkerPrivate->IsAcceptingEvents()) {
++      return true;
++    }
++
++    if (aWorkerPrivate->IsFrozen() ||
++        aWorkerPrivate->IsParentWindowPaused()) {
++      MOZ_ASSERT(!IsDebuggerRunnable());
++      aWorkerPrivate->QueueRunnable(this);
++      return true;
++    }
++
++    aWorkerPrivate->AssertInnerWindowIsCorrect();
++
++    return DispatchDOMEvent(aCx, aWorkerPrivate, aWorkerPrivate,
++                            !aWorkerPrivate->GetParent());
++  }
++
++  MOZ_ASSERT(aWorkerPrivate == GetWorkerPrivateFromContext(aCx));
++
++  return DispatchDOMEvent(aCx, aWorkerPrivate, aWorkerPrivate->GlobalScope(),
++                          false);
++}
++
++void
++MessageEventRunnable::DispatchError(JSContext* aCx,
++                                    DOMEventTargetHelper* aTarget)
++{
++  RootedDictionary<MessageEventInit> init(aCx);
++  init.mBubbles = false;
++  init.mCancelable = false;
++
++  RefPtr<Event> event =
++    MessageEvent::Constructor(aTarget, NS_LITERAL_STRING("messageerror"), init);
++  event->SetTrusted(true);
++
++  bool dummy;
++  aTarget->DispatchEvent(event, &dummy);
++}
++
++END_WORKERS_NAMESPACE
+diff --git a/dom/workers/MessageEventRunnable.h b/dom/workers/MessageEventRunnable.h
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/MessageEventRunnable.h
+@@ -0,0 +1,37 @@
++/* -*- 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/. */
++
++#ifndef mozilla_dom_workers_MessageEventRunnable_h
++#define mozilla_dom_workers_MessageEventRunnable_h
++
++#include "WorkerCommon.h"
++#include "WorkerRunnable.h"
++#include "mozilla/dom/StructuredCloneHolder.h"
++
++BEGIN_WORKERS_NAMESPACE
++
++class MessageEventRunnable final : public WorkerRunnable
++                                 , public StructuredCloneHolder
++{
++public:
++  MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
++                       TargetAndBusyBehavior aBehavior);
++
++  bool
++  DispatchDOMEvent(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
++                   DOMEventTargetHelper* aTarget, bool aIsMainThread);
++
++private:
++  bool
++  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
++
++  void
++  DispatchError(JSContext* aCx, DOMEventTargetHelper* aTarget);
++};
++
++END_WORKERS_NAMESPACE
++
++#endif // mozilla_dom_workers_MessageEventRunnable_h
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
+--- a/dom/workers/WorkerPrivate.cpp
++++ b/dom/workers/WorkerPrivate.cpp
+@@ -34,16 +34,17 @@
+ #include "nsIXPConnect.h"
+ #include "nsPIDOMWindow.h"
+ #include "nsGlobalWindow.h"
+ 
+ #include <algorithm>
+ #include "ImageContainer.h"
+ #include "jsfriendapi.h"
+ #include "js/MemoryMetrics.h"
++#include "MessageEventRunnable.h"
+ #include "mozilla/Assertions.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/ContentEvents.h"
+ #include "mozilla/EventDispatcher.h"
+ #include "mozilla/Likely.h"
+ #include "mozilla/LoadContext.h"
+ #include "mozilla/Move.h"
+ #include "mozilla/dom/BindingUtils.h"
+@@ -701,154 +702,16 @@ private:
+     if (rv.MaybeSetPendingException(aCx)) {
+       return false;
+     }
+ 
+     return true;
+   }
+ };
+ 
+-class MessageEventRunnable final : public WorkerRunnable
+-                                 , public StructuredCloneHolder
+-{
+-public:
+-  MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
+-                       TargetAndBusyBehavior aBehavior)
+-  : WorkerRunnable(aWorkerPrivate, aBehavior)
+-  , StructuredCloneHolder(CloningSupported, TransferringSupported,
+-                          StructuredCloneScope::SameProcessDifferentThread)
+-  {
+-  }
+-
+-  bool
+-  DispatchDOMEvent(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
+-                   DOMEventTargetHelper* aTarget, bool aIsMainThread)
+-  {
+-    nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(aTarget->GetParentObject());
+-
+-    // For some workers without window, parent is null and we try to find it
+-    // from the JS Context.
+-    if (!parent) {
+-      JS::Rooted<JSObject*> globalObject(aCx, JS::CurrentGlobalOrNull(aCx));
+-      if (NS_WARN_IF(!globalObject)) {
+-        return false;
+-      }
+-
+-      parent = xpc::NativeGlobal(globalObject);
+-      if (NS_WARN_IF(!parent)) {
+-        return false;
+-      }
+-    }
+-
+-    MOZ_ASSERT(parent);
+-
+-    JS::Rooted<JS::Value> messageData(aCx);
+-    IgnoredErrorResult rv;
+-
+-    UniquePtr<AbstractTimelineMarker> start;
+-    UniquePtr<AbstractTimelineMarker> end;
+-    RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
+-    bool isTimelineRecording = timelines && !timelines->IsEmpty();
+-
+-    if (isTimelineRecording) {
+-      start = MakeUnique<WorkerTimelineMarker>(aIsMainThread
+-        ? ProfileTimelineWorkerOperationType::DeserializeDataOnMainThread
+-        : ProfileTimelineWorkerOperationType::DeserializeDataOffMainThread,
+-        MarkerTracingType::START);
+-    }
+-
+-    Read(parent, aCx, &messageData, rv);
+-
+-    if (isTimelineRecording) {
+-      end = MakeUnique<WorkerTimelineMarker>(aIsMainThread
+-        ? ProfileTimelineWorkerOperationType::DeserializeDataOnMainThread
+-        : ProfileTimelineWorkerOperationType::DeserializeDataOffMainThread,
+-        MarkerTracingType::END);
+-      timelines->AddMarkerForAllObservedDocShells(start);
+-      timelines->AddMarkerForAllObservedDocShells(end);
+-    }
+-
+-    if (NS_WARN_IF(rv.Failed())) {
+-      DispatchError(aCx, aTarget);
+-      return false;
+-    }
+-
+-    Sequence<OwningNonNull<MessagePort>> ports;
+-    if (!TakeTransferredPortsAsSequence(ports)) {
+-      DispatchError(aCx, aTarget);
+-      return false;
+-    }
+-
+-    nsCOMPtr<nsIDOMEvent> domEvent;
+-    RefPtr<MessageEvent> event = new MessageEvent(aTarget, nullptr, nullptr);
+-    event->InitMessageEvent(nullptr,
+-                            NS_LITERAL_STRING("message"),
+-                            false /* non-bubbling */,
+-                            false /* cancelable */,
+-                            messageData,
+-                            EmptyString(),
+-                            EmptyString(),
+-                            nullptr,
+-                            ports);
+-    domEvent = do_QueryObject(event);
+-
+-    domEvent->SetTrusted(true);
+-
+-    bool dummy;
+-    aTarget->DispatchEvent(domEvent, &dummy);
+-
+-    return true;
+-  }
+-
+-private:
+-  virtual bool
+-  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
+-  {
+-    if (mBehavior == ParentThreadUnchangedBusyCount) {
+-      // Don't fire this event if the JS object has been disconnected from the
+-      // private object.
+-      if (!aWorkerPrivate->IsAcceptingEvents()) {
+-        return true;
+-      }
+-
+-      if (aWorkerPrivate->IsFrozen() ||
+-          aWorkerPrivate->IsParentWindowPaused()) {
+-        MOZ_ASSERT(!IsDebuggerRunnable());
+-        aWorkerPrivate->QueueRunnable(this);
+-        return true;
+-      }
+-
+-      aWorkerPrivate->AssertInnerWindowIsCorrect();
+-
+-      return DispatchDOMEvent(aCx, aWorkerPrivate, aWorkerPrivate,
+-                              !aWorkerPrivate->GetParent());
+-    }
+-
+-    MOZ_ASSERT(aWorkerPrivate == GetWorkerPrivateFromContext(aCx));
+-
+-    return DispatchDOMEvent(aCx, aWorkerPrivate, aWorkerPrivate->GlobalScope(),
+-                            false);
+-  }
+-
+-  void
+-  DispatchError(JSContext* aCx, DOMEventTargetHelper* aTarget)
+-  {
+-    RootedDictionary<MessageEventInit> init(aCx);
+-    init.mBubbles = false;
+-    init.mCancelable = false;
+-
+-    RefPtr<Event> event =
+-      MessageEvent::Constructor(aTarget, NS_LITERAL_STRING("messageerror"), init);
+-    event->SetTrusted(true);
+-
+-    bool dummy;
+-    aTarget->DispatchEvent(event, &dummy);
+-  }
+-};
+-
+ class DebuggerMessageEventRunnable : public WorkerDebuggerRunnable {
+   nsString mMessage;
+ 
+ public:
+   DebuggerMessageEventRunnable(WorkerPrivate* aWorkerPrivate,
+                                const nsAString& aMessage)
+   : WorkerDebuggerRunnable(aWorkerPrivate),
+     mMessage(aMessage)
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -35,16 +35,17 @@ XPIDL_MODULE = 'dom_workers'
+ XPIDL_SOURCES += [
+     'nsIWorkerDebugger.idl',
+     'nsIWorkerDebuggerManager.idl',
+ ]
+ 
+ UNIFIED_SOURCES += [
+     'ChromeWorkerScope.cpp',
+     'FileReaderSync.cpp',
++    'MessageEventRunnable.cpp',
+     'Principal.cpp',
+     'RegisterBindings.cpp',
+     'RuntimeService.cpp',
+     'ScriptLoader.cpp',
+     'SharedWorker.cpp',
+     'WorkerDebuggerManager.cpp',
+     'WorkerHolder.cpp',
+     'WorkerHolderToken.cpp',

+ 1688 - 0
mozilla-release/patches/1413112-3-60a1.patch

@@ -0,0 +1,1688 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303524 -3600
+# Node ID f891bdb45bc7100b46d664a7055da0b3467f3540
+# Parent  41f034c05ddace7b63bd58f302e71a88a2196233
+Bug 1413112 - Move WorkerLoadInfo into separate files, r=bkelly
+
+diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp
+--- a/dom/workers/RuntimeService.cpp
++++ b/dom/workers/RuntimeService.cpp
+@@ -64,16 +64,17 @@
+ #include "nsXPCOM.h"
+ #include "nsXPCOMPrivate.h"
+ #include "OSFileConstants.h"
+ #include "xpcpublic.h"
+ 
+ #include "Principal.h"
+ #include "SharedWorker.h"
+ #include "WorkerDebuggerManager.h"
++#include "WorkerLoadInfo.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "WorkerThread.h"
+ #include "prsystem.h"
+ 
+ using namespace mozilla;
+ using namespace mozilla::dom;
+diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h
+--- a/dom/workers/RuntimeService.h
++++ b/dom/workers/RuntimeService.h
+@@ -17,16 +17,17 @@
+ #include "nsTArray.h"
+ 
+ class nsITimer;
+ class nsPIDOMWindowInner;
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+ class SharedWorker;
++struct WorkerLoadInfo;
+ class WorkerThread;
+ 
+ class RuntimeService final : public nsIObserver
+ {
+   struct SharedWorkerInfo
+   {
+     WorkerPrivate* mWorkerPrivate;
+     nsCString mScriptSpec;
+diff --git a/dom/workers/WorkerCommon.h b/dom/workers/WorkerCommon.h
+--- a/dom/workers/WorkerCommon.h
++++ b/dom/workers/WorkerCommon.h
+@@ -15,47 +15,35 @@
+ #include "nsAutoPtr.h"
+ #include "nsCOMPtr.h"
+ #include "nsDebug.h"
+ #include "nsString.h"
+ #include "nsTArray.h"
+ 
+ #include "nsILoadContext.h"
+ #include "nsIWeakReferenceUtils.h"
+-#include "nsIInterfaceRequestor.h"
+ #include "mozilla/dom/ChannelInfo.h"
+ #include "mozilla/dom/ServiceWorkerDescriptor.h"
+ #include "mozilla/net/ReferrerPolicy.h"
+ 
+ #define BEGIN_WORKERS_NAMESPACE \
+   namespace mozilla { namespace dom { namespace workers {
+ #define END_WORKERS_NAMESPACE \
+   } /* namespace workers */ } /* namespace dom */ } /* namespace mozilla */
+ #define USING_WORKERS_NAMESPACE \
+   using namespace mozilla::dom::workers;
+ 
+ #define WORKERS_SHUTDOWN_TOPIC "web-workers-shutdown"
+ 
+-class nsIContentSecurityPolicy;
+-class nsIScriptContext;
+ class nsIGlobalObject;
+ class nsPIDOMWindowInner;
+-class nsIPrincipal;
+-class nsILoadGroup;
+-class nsITabChild;
+-class nsIChannel;
+-class nsIRunnable;
+-class nsIURI;
+ 
+ namespace mozilla {
+-namespace ipc {
+-class PrincipalInfo;
+-} // namespace ipc
++namespace dom {
+ 
+-namespace dom {
+ // If you change this, the corresponding list in nsIWorkerDebugger.idl needs to
+ // be updated too.
+ enum WorkerType
+ {
+   WorkerTypeDedicated,
+   WorkerTypeShared,
+   WorkerTypeService
+ };
+@@ -181,127 +169,16 @@ struct JSSettings
+       foundSetting->key.reset();
+       return true;
+     }
+ 
+     return false;
+   }
+ };
+ 
+-// Implemented in WorkerPrivate.cpp
+-
+-struct WorkerLoadInfo
+-{
+-  // All of these should be released in WorkerPrivateParent::ForgetMainThreadObjects.
+-  nsCOMPtr<nsIURI> mBaseURI;
+-  nsCOMPtr<nsIURI> mResolvedScriptURI;
+-
+-  // This is the principal of the global (parent worker or a window) loading
+-  // the worker. It can be null if we are executing a ServiceWorker, otherwise,
+-  // except for data: URL, it must subsumes the worker principal.
+-  // If we load a data: URL, mPrincipal will be a null principal.
+-  nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
+-  nsCOMPtr<nsIPrincipal> mPrincipal;
+-
+-  nsCOMPtr<nsIScriptContext> mScriptContext;
+-  nsCOMPtr<nsPIDOMWindowInner> mWindow;
+-  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
+-  nsCOMPtr<nsIChannel> mChannel;
+-  nsCOMPtr<nsILoadGroup> mLoadGroup;
+-
+-  // mLoadFailedAsyncRunnable will execute on main thread if script loading
+-  // fails during script loading.  If script loading is never started due to
+-  // a synchronous error, then the runnable is never executed.  The runnable
+-  // is guaranteed to be released on the main thread.
+-  nsCOMPtr<nsIRunnable> mLoadFailedAsyncRunnable;
+-
+-  class InterfaceRequestor final : public nsIInterfaceRequestor
+-  {
+-    NS_DECL_ISUPPORTS
+-
+-  public:
+-    InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
+-    void MaybeAddTabChild(nsILoadGroup* aLoadGroup);
+-    NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override;
+-
+-  private:
+-    ~InterfaceRequestor() { }
+-
+-    already_AddRefed<nsITabChild> GetAnyLiveTabChild();
+-
+-    nsCOMPtr<nsILoadContext> mLoadContext;
+-    nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor;
+-
+-    // Array of weak references to nsITabChild.  We do not want to keep TabChild
+-    // actors alive for long after their ActorDestroy() methods are called.
+-    nsTArray<nsWeakPtr> mTabChildList;
+-  };
+-
+-  // Only set if we have a custom overriden load group
+-  RefPtr<InterfaceRequestor> mInterfaceRequestor;
+-
+-  nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
+-  nsCString mDomain;
+-  nsString mOrigin; // Derived from mPrincipal; can be used on worker thread.
+-
+-  nsString mServiceWorkerCacheName;
+-  Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
+-
+-  Maybe<ServiceWorkerDescriptor> mParentController;
+-
+-  ChannelInfo mChannelInfo;
+-  nsLoadFlags mLoadFlags;
+-
+-  uint64_t mWindowID;
+-
+-  net::ReferrerPolicy mReferrerPolicy;
+-  bool mFromWindow;
+-  bool mEvalAllowed;
+-  bool mReportCSPViolations;
+-  bool mXHRParamsAllowed;
+-  bool mPrincipalIsSystem;
+-  bool mStorageAllowed;
+-  bool mServiceWorkersTestingInWindow;
+-  OriginAttributes mOriginAttributes;
+-
+-  WorkerLoadInfo();
+-  ~WorkerLoadInfo();
+-
+-  void StealFrom(WorkerLoadInfo& aOther);
+-
+-  nsresult
+-  SetPrincipalOnMainThread(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
+-
+-  nsresult
+-  GetPrincipalAndLoadGroupFromChannel(nsIChannel* aChannel,
+-                                      nsIPrincipal** aPrincipalOut,
+-                                      nsILoadGroup** aLoadGroupOut);
+-
+-  nsresult
+-  SetPrincipalFromChannel(nsIChannel* aChannel);
+-
+-  bool
+-  FinalChannelPrincipalIsValid(nsIChannel* aChannel);
+-
+-#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
+-  bool
+-  PrincipalIsValid() const;
+-
+-  bool
+-  PrincipalURIMatchesScriptURL();
+-#endif
+-
+-  bool
+-  ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
+-
+-  bool
+-  ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate,
+-                                nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel);
+-};
+-
+ // All of these are implemented in RuntimeService.cpp
+ 
+ void
+ CancelWorkersForWindow(nsPIDOMWindowInner* aWindow);
+ 
+ void
+ FreezeWorkersForWindow(nsPIDOMWindowInner* aWindow);
+ 
+diff --git a/dom/workers/WorkerLoadInfo.cpp b/dom/workers/WorkerLoadInfo.cpp
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerLoadInfo.cpp
+@@ -0,0 +1,547 @@
++/* -*- 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 "WorkerLoadInfo.h"
++#include "WorkerPrivate.h"
++
++#include "mozilla/dom/TabChild.h"
++#include "mozilla/ipc/BackgroundUtils.h"
++#include "mozilla/ipc/PBackgroundSharedTypes.h"
++#include "mozilla/LoadContext.h"
++#include "nsContentUtils.h"
++#include "nsIContentSecurityPolicy.h"
++#include "nsINetworkInterceptController.h"
++#include "nsIProtocolHandler.h"
++#include "nsITabChild.h"
++#include "nsNetUtil.h"
++
++namespace mozilla {
++
++using namespace ipc;
++
++namespace dom {
++namespace workers {
++
++namespace {
++
++class MainThreadReleaseRunnable final : public Runnable
++{
++  nsTArray<nsCOMPtr<nsISupports>> mDoomed;
++  nsCOMPtr<nsILoadGroup> mLoadGroupToCancel;
++
++public:
++  MainThreadReleaseRunnable(nsTArray<nsCOMPtr<nsISupports>>& aDoomed,
++                            nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel)
++    : mozilla::Runnable("MainThreadReleaseRunnable")
++  {
++    mDoomed.SwapElements(aDoomed);
++    mLoadGroupToCancel.swap(aLoadGroupToCancel);
++  }
++
++  NS_DECL_ISUPPORTS_INHERITED
++
++  NS_IMETHOD
++  Run() override
++  {
++    if (mLoadGroupToCancel) {
++      mLoadGroupToCancel->Cancel(NS_BINDING_ABORTED);
++      mLoadGroupToCancel = nullptr;
++    }
++
++    mDoomed.Clear();
++    return NS_OK;
++  }
++
++private:
++  ~MainThreadReleaseRunnable()
++  { }
++};
++
++// Specialize this if there's some class that has multiple nsISupports bases.
++template <class T>
++struct ISupportsBaseInfo
++{
++  typedef T ISupportsBase;
++};
++
++template <template <class> class SmartPtr, class T>
++inline void
++SwapToISupportsArray(SmartPtr<T>& aSrc,
++                     nsTArray<nsCOMPtr<nsISupports> >& aDest)
++{
++  nsCOMPtr<nsISupports>* dest = aDest.AppendElement();
++
++  T* raw = nullptr;
++  aSrc.swap(raw);
++
++  nsISupports* rawSupports =
++    static_cast<typename ISupportsBaseInfo<T>::ISupportsBase*>(raw);
++  dest->swap(rawSupports);
++}
++
++} // anonymous
++
++NS_IMPL_ISUPPORTS_INHERITED0(MainThreadReleaseRunnable, Runnable)
++
++WorkerLoadInfo::WorkerLoadInfo()
++  : mLoadFlags(nsIRequest::LOAD_NORMAL)
++  , mWindowID(UINT64_MAX)
++  , mReferrerPolicy(net::RP_Unset)
++  , mFromWindow(false)
++  , mEvalAllowed(false)
++  , mReportCSPViolations(false)
++  , mXHRParamsAllowed(false)
++  , mPrincipalIsSystem(false)
++  , mStorageAllowed(false)
++  , mServiceWorkersTestingInWindow(false)
++{
++  MOZ_COUNT_CTOR(WorkerLoadInfo);
++}
++
++WorkerLoadInfo::~WorkerLoadInfo()
++{
++  MOZ_COUNT_DTOR(WorkerLoadInfo);
++}
++
++void
++WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther)
++{
++  MOZ_ASSERT(!mBaseURI);
++  aOther.mBaseURI.swap(mBaseURI);
++
++  MOZ_ASSERT(!mResolvedScriptURI);
++  aOther.mResolvedScriptURI.swap(mResolvedScriptURI);
++
++  MOZ_ASSERT(!mPrincipal);
++  aOther.mPrincipal.swap(mPrincipal);
++
++  // mLoadingPrincipal can be null if this is a ServiceWorker.
++  aOther.mLoadingPrincipal.swap(mLoadingPrincipal);
++
++  MOZ_ASSERT(!mScriptContext);
++  aOther.mScriptContext.swap(mScriptContext);
++
++  MOZ_ASSERT(!mWindow);
++  aOther.mWindow.swap(mWindow);
++
++  MOZ_ASSERT(!mCSP);
++  aOther.mCSP.swap(mCSP);
++
++  MOZ_ASSERT(!mChannel);
++  aOther.mChannel.swap(mChannel);
++
++  MOZ_ASSERT(!mLoadGroup);
++  aOther.mLoadGroup.swap(mLoadGroup);
++
++  MOZ_ASSERT(!mLoadFailedAsyncRunnable);
++  aOther.mLoadFailedAsyncRunnable.swap(mLoadFailedAsyncRunnable);
++
++  MOZ_ASSERT(!mInterfaceRequestor);
++  aOther.mInterfaceRequestor.swap(mInterfaceRequestor);
++
++  MOZ_ASSERT(!mPrincipalInfo);
++  mPrincipalInfo = aOther.mPrincipalInfo.forget();
++
++  mDomain = aOther.mDomain;
++  mOrigin = aOther.mOrigin;
++  mServiceWorkerCacheName = aOther.mServiceWorkerCacheName;
++  mServiceWorkerDescriptor = aOther.mServiceWorkerDescriptor;
++  mLoadFlags = aOther.mLoadFlags;
++  mWindowID = aOther.mWindowID;
++  mReferrerPolicy = aOther.mReferrerPolicy;
++  mFromWindow = aOther.mFromWindow;
++  mEvalAllowed = aOther.mEvalAllowed;
++  mReportCSPViolations = aOther.mReportCSPViolations;
++  mXHRParamsAllowed = aOther.mXHRParamsAllowed;
++  mPrincipalIsSystem = aOther.mPrincipalIsSystem;
++  mStorageAllowed = aOther.mStorageAllowed;
++  mServiceWorkersTestingInWindow = aOther.mServiceWorkersTestingInWindow;
++  mOriginAttributes = aOther.mOriginAttributes;
++  mParentController = aOther.mParentController;
++}
++
++nsresult
++WorkerLoadInfo::SetPrincipalOnMainThread(nsIPrincipal* aPrincipal,
++                                         nsILoadGroup* aLoadGroup)
++{
++  AssertIsOnMainThread();
++  MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(aLoadGroup, aPrincipal));
++
++  mPrincipal = aPrincipal;
++  mPrincipalIsSystem = nsContentUtils::IsSystemPrincipal(aPrincipal);
++
++  nsresult rv = aPrincipal->GetCsp(getter_AddRefs(mCSP));
++  NS_ENSURE_SUCCESS(rv, rv);
++
++  if (mCSP) {
++    mCSP->GetAllowsEval(&mReportCSPViolations, &mEvalAllowed);
++    // Set ReferrerPolicy
++    bool hasReferrerPolicy = false;
++    uint32_t rp = mozilla::net::RP_Unset;
++
++    rv = mCSP->GetReferrerPolicy(&rp, &hasReferrerPolicy);
++    NS_ENSURE_SUCCESS(rv, rv);
++
++    if (hasReferrerPolicy) {
++      mReferrerPolicy = static_cast<net::ReferrerPolicy>(rp);
++    }
++  } else {
++    mEvalAllowed = true;
++    mReportCSPViolations = false;
++  }
++
++  mLoadGroup = aLoadGroup;
++
++  mPrincipalInfo = new PrincipalInfo();
++  mOriginAttributes = nsContentUtils::GetOriginAttributes(aLoadGroup);
++
++  rv = PrincipalToPrincipalInfo(aPrincipal, mPrincipalInfo);
++  NS_ENSURE_SUCCESS(rv, rv);
++
++  rv = nsContentUtils::GetUTFOrigin(aPrincipal, mOrigin);
++  NS_ENSURE_SUCCESS(rv, rv);
++
++  return NS_OK;
++}
++
++nsresult
++WorkerLoadInfo::GetPrincipalAndLoadGroupFromChannel(nsIChannel* aChannel,
++                                                    nsIPrincipal** aPrincipalOut,
++                                                    nsILoadGroup** aLoadGroupOut)
++{
++  AssertIsOnMainThread();
++  MOZ_DIAGNOSTIC_ASSERT(aChannel);
++  MOZ_DIAGNOSTIC_ASSERT(aPrincipalOut);
++  MOZ_DIAGNOSTIC_ASSERT(aLoadGroupOut);
++
++  // Initial triggering principal should be set
++  NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_DOM_INVALID_STATE_ERR);
++
++  nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
++  MOZ_DIAGNOSTIC_ASSERT(ssm);
++
++  nsCOMPtr<nsIPrincipal> channelPrincipal;
++  nsresult rv = ssm->GetChannelResultPrincipal(aChannel, getter_AddRefs(channelPrincipal));
++  NS_ENSURE_SUCCESS(rv, rv);
++
++  // Every time we call GetChannelResultPrincipal() it will return a different
++  // null principal for a data URL.  We don't want to change the worker's
++  // principal again, though.  Instead just keep the original null principal we
++  // first got from the channel.
++  //
++  // Note, we don't do this by setting principalToInherit on the channel's
++  // load info because we don't yet have the first null principal when we
++  // create the channel.
++  if (mPrincipal && mPrincipal->GetIsNullPrincipal() &&
++                    channelPrincipal->GetIsNullPrincipal()) {
++    channelPrincipal = mPrincipal;
++  }
++
++  nsCOMPtr<nsILoadGroup> channelLoadGroup;
++  rv = aChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
++  NS_ENSURE_SUCCESS(rv, rv);
++  MOZ_ASSERT(channelLoadGroup);
++
++  // If the loading principal is the system principal then the channel
++  // principal must also be the system principal (we do not allow chrome
++  // code to create workers with non-chrome scripts, and if we ever decide
++  // to change this we need to make sure we don't always set
++  // mPrincipalIsSystem to true in WorkerPrivate::GetLoadInfo()). Otherwise
++  // this channel principal must be same origin with the load principal (we
++  // check again here in case redirects changed the location of the script).
++  if (nsContentUtils::IsSystemPrincipal(mLoadingPrincipal)) {
++    if (!nsContentUtils::IsSystemPrincipal(channelPrincipal)) {
++      nsCOMPtr<nsIURI> finalURI;
++      rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(finalURI));
++      NS_ENSURE_SUCCESS(rv, rv);
++
++      // See if this is a resource URI. Since JSMs usually come from
++      // resource:// URIs we're currently considering all URIs with the
++      // URI_IS_UI_RESOURCE flag as valid for creating privileged workers.
++      bool isResource;
++      rv = NS_URIChainHasFlags(finalURI,
++                               nsIProtocolHandler::URI_IS_UI_RESOURCE,
++                               &isResource);
++      NS_ENSURE_SUCCESS(rv, rv);
++
++      if (isResource) {
++        // Assign the system principal to the resource:// worker only if it
++        // was loaded from code using the system principal.
++        channelPrincipal = mLoadingPrincipal;
++      } else {
++        return NS_ERROR_DOM_BAD_URI;
++      }
++    }
++  }
++
++  // The principal can change, but it should still match the original
++  // load group's appId and browser element flag.
++  MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(channelLoadGroup, channelPrincipal));
++
++  channelPrincipal.forget(aPrincipalOut);
++  channelLoadGroup.forget(aLoadGroupOut);
++
++  return NS_OK;
++}
++
++nsresult
++WorkerLoadInfo::SetPrincipalFromChannel(nsIChannel* aChannel)
++{
++  AssertIsOnMainThread();
++
++  nsCOMPtr<nsIPrincipal> principal;
++  nsCOMPtr<nsILoadGroup> loadGroup;
++  nsresult rv = GetPrincipalAndLoadGroupFromChannel(aChannel,
++                                                    getter_AddRefs(principal),
++                                                    getter_AddRefs(loadGroup));
++  NS_ENSURE_SUCCESS(rv, rv);
++
++  return SetPrincipalOnMainThread(principal, loadGroup);
++}
++
++bool
++WorkerLoadInfo::FinalChannelPrincipalIsValid(nsIChannel* aChannel)
++{
++  AssertIsOnMainThread();
++
++  nsCOMPtr<nsIPrincipal> principal;
++  nsCOMPtr<nsILoadGroup> loadGroup;
++  nsresult rv = GetPrincipalAndLoadGroupFromChannel(aChannel,
++                                                    getter_AddRefs(principal),
++                                                    getter_AddRefs(loadGroup));
++  NS_ENSURE_SUCCESS(rv, false);
++
++
++  // Verify that the channel is still a null principal.  We don't care
++  // if these are the exact same null principal object, though.  From
++  // the worker's perspective its the same effect.
++  if (principal->GetIsNullPrincipal() && mPrincipal->GetIsNullPrincipal()) {
++    return true;
++  }
++
++  // Otherwise we require exact equality.  Redirects can happen, but they
++  // are not allowed to change our principal.
++  if (principal->Equals(mPrincipal)) {
++    return true;
++  }
++
++  return false;
++}
++
++#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
++bool
++WorkerLoadInfo::PrincipalIsValid() const
++{
++  return mPrincipal && mPrincipalInfo &&
++         mPrincipalInfo->type() != PrincipalInfo::T__None &&
++         mPrincipalInfo->type() <= PrincipalInfo::T__Last;
++}
++
++bool
++WorkerLoadInfo::PrincipalURIMatchesScriptURL()
++{
++  AssertIsOnMainThread();
++
++  nsAutoCString scheme;
++  nsresult rv = mBaseURI->GetScheme(scheme);
++  NS_ENSURE_SUCCESS(rv, false);
++
++  // A system principal must either be a blob URL or a resource JSM.
++  if (mPrincipal->GetIsSystemPrincipal()) {
++    if (scheme == NS_LITERAL_CSTRING("blob")) {
++      return true;
++    }
++
++    bool isResource = false;
++    nsresult rv = NS_URIChainHasFlags(mBaseURI,
++                                      nsIProtocolHandler::URI_IS_UI_RESOURCE,
++                                      &isResource);
++    NS_ENSURE_SUCCESS(rv, false);
++
++    return isResource;
++  }
++
++  // A null principal can occur for a data URL worker script or a blob URL
++  // worker script from a sandboxed iframe.
++  if (mPrincipal->GetIsNullPrincipal()) {
++    return scheme == NS_LITERAL_CSTRING("data") ||
++           scheme == NS_LITERAL_CSTRING("blob");
++  }
++
++  // The principal for a blob: URL worker script does not have a matching URL.
++  // This is likely a bug in our referer setting logic, but exempt it for now.
++  // This is another reason we should fix bug 1340694 so that referer does not
++  // depend on the principal URI.
++  if (scheme == NS_LITERAL_CSTRING("blob")) {
++    return true;
++  }
++
++  nsCOMPtr<nsIURI> principalURI;
++  rv = mPrincipal->GetURI(getter_AddRefs(principalURI));
++  NS_ENSURE_SUCCESS(rv, false);
++  NS_ENSURE_TRUE(principalURI, false);
++
++  bool equal = false;
++  rv = principalURI->Equals(mBaseURI, &equal);
++  NS_ENSURE_SUCCESS(rv, false);
++
++  return equal;
++}
++#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
++
++bool
++WorkerLoadInfo::ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate)
++{
++  nsCOMPtr<nsILoadGroup> nullLoadGroup;
++  return ProxyReleaseMainThreadObjects(aWorkerPrivate, nullLoadGroup);
++}
++
++bool
++WorkerLoadInfo::ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate,
++                                              nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel)
++{
++
++  static const uint32_t kDoomedCount = 11;
++  nsTArray<nsCOMPtr<nsISupports>> doomed(kDoomedCount);
++
++  SwapToISupportsArray(mWindow, doomed);
++  SwapToISupportsArray(mScriptContext, doomed);
++  SwapToISupportsArray(mBaseURI, doomed);
++  SwapToISupportsArray(mResolvedScriptURI, doomed);
++  SwapToISupportsArray(mPrincipal, doomed);
++  SwapToISupportsArray(mLoadingPrincipal, doomed);
++  SwapToISupportsArray(mChannel, doomed);
++  SwapToISupportsArray(mCSP, doomed);
++  SwapToISupportsArray(mLoadGroup, doomed);
++  SwapToISupportsArray(mLoadFailedAsyncRunnable, doomed);
++  SwapToISupportsArray(mInterfaceRequestor, doomed);
++  // Before adding anything here update kDoomedCount above!
++
++  MOZ_ASSERT(doomed.Length() == kDoomedCount);
++
++  RefPtr<MainThreadReleaseRunnable> runnable =
++    new MainThreadReleaseRunnable(doomed, aLoadGroupToCancel);
++  return NS_SUCCEEDED(aWorkerPrivate->DispatchToMainThread(runnable.forget()));
++}
++
++WorkerLoadInfo::
++InterfaceRequestor::InterfaceRequestor(nsIPrincipal* aPrincipal,
++                                       nsILoadGroup* aLoadGroup)
++{
++  MOZ_ASSERT(NS_IsMainThread());
++  MOZ_ASSERT(aPrincipal);
++
++  // Look for an existing LoadContext.  This is optional and it's ok if
++  // we don't find one.
++  nsCOMPtr<nsILoadContext> baseContext;
++  if (aLoadGroup) {
++    nsCOMPtr<nsIInterfaceRequestor> callbacks;
++    aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
++    if (callbacks) {
++      callbacks->GetInterface(NS_GET_IID(nsILoadContext),
++                              getter_AddRefs(baseContext));
++    }
++    mOuterRequestor = callbacks;
++  }
++
++  mLoadContext = new LoadContext(aPrincipal, baseContext);
++}
++
++void
++WorkerLoadInfo::
++InterfaceRequestor::MaybeAddTabChild(nsILoadGroup* aLoadGroup)
++{
++  MOZ_ASSERT(NS_IsMainThread());
++
++  if (!aLoadGroup) {
++    return;
++  }
++
++  nsCOMPtr<nsIInterfaceRequestor> callbacks;
++  aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
++  if (!callbacks) {
++    return;
++  }
++
++  nsCOMPtr<nsITabChild> tabChild;
++  callbacks->GetInterface(NS_GET_IID(nsITabChild), getter_AddRefs(tabChild));
++  if (!tabChild) {
++    return;
++  }
++
++  // Use weak references to the tab child.  Holding a strong reference will
++  // not prevent an ActorDestroy() from being called on the TabChild.
++  // Therefore, we should let the TabChild destroy itself as soon as possible.
++  mTabChildList.AppendElement(do_GetWeakReference(tabChild));
++}
++
++NS_IMETHODIMP
++WorkerLoadInfo::
++InterfaceRequestor::GetInterface(const nsIID& aIID, void** aSink)
++{
++  MOZ_ASSERT(NS_IsMainThread());
++  MOZ_ASSERT(mLoadContext);
++
++  if (aIID.Equals(NS_GET_IID(nsILoadContext))) {
++    nsCOMPtr<nsILoadContext> ref = mLoadContext;
++    ref.forget(aSink);
++    return NS_OK;
++  }
++
++  // If we still have an active nsITabChild, then return it.  Its possible,
++  // though, that all of the TabChild objects have been destroyed.  In that
++  // case we return NS_NOINTERFACE.
++  if (aIID.Equals(NS_GET_IID(nsITabChild))) {
++    nsCOMPtr<nsITabChild> tabChild = GetAnyLiveTabChild();
++    if (!tabChild) {
++      return NS_NOINTERFACE;
++    }
++    tabChild.forget(aSink);
++    return NS_OK;
++  }
++
++  if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController)) &&
++      mOuterRequestor) {
++    // If asked for the network intercept controller, ask the outer requestor,
++    // which could be the docshell.
++    return mOuterRequestor->GetInterface(aIID, aSink);
++  }
++
++  return NS_NOINTERFACE;
++}
++
++already_AddRefed<nsITabChild>
++WorkerLoadInfo::
++InterfaceRequestor::GetAnyLiveTabChild()
++{
++  MOZ_ASSERT(NS_IsMainThread());
++
++  // Search our list of known TabChild objects for one that still exists.
++  while (!mTabChildList.IsEmpty()) {
++    nsCOMPtr<nsITabChild> tabChild =
++      do_QueryReferent(mTabChildList.LastElement());
++
++    // Does this tab child still exist?  If so, return it.  We are done.  If the
++    // PBrowser actor is no longer useful, don't bother returning this tab.
++    if (tabChild && !static_cast<TabChild*>(tabChild.get())->IsDestroyed()) {
++      return tabChild.forget();
++    }
++
++    // Otherwise remove the stale weak reference and check the next one
++    mTabChildList.RemoveElementAt(mTabChildList.Length() - 1);
++  }
++
++  return nullptr;
++}
++
++NS_IMPL_ADDREF(WorkerLoadInfo::InterfaceRequestor)
++NS_IMPL_RELEASE(WorkerLoadInfo::InterfaceRequestor)
++NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor,
++                        nsIInterfaceRequestor)
++
++} // worker namespace
++} // dom namespace
++} // mozilla namespace
+diff --git a/dom/workers/WorkerLoadInfo.h b/dom/workers/WorkerLoadInfo.h
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerLoadInfo.h
+@@ -0,0 +1,143 @@
++/* -*- 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/. */
++
++#ifndef mozilla_dom_workers_WorkerLoadInfo_h
++#define mozilla_dom_workers_WorkerLoadInfo_h
++
++#include "mozilla/dom/workers/WorkerCommon.h"
++#include "nsIInterfaceRequestor.h"
++#include "nsISupportsImpl.h"
++
++class nsIChannel;
++class nsIContentSecurityPolicy;
++class nsILoadGroup;
++class nsIPrincipal;
++class nsIRunnable;
++class nsIScriptContext;
++class nsITabChild;
++class nsIURI;
++class nsPIDOMWindowInner;
++
++namespace mozilla {
++namespace ipc {
++class PrincipalInfo;
++} // namespace ipc
++} // namespace mozilla
++
++BEGIN_WORKERS_NAMESPACE
++
++struct WorkerLoadInfo
++{
++  // All of these should be released in WorkerPrivateParent::ForgetMainThreadObjects.
++  nsCOMPtr<nsIURI> mBaseURI;
++  nsCOMPtr<nsIURI> mResolvedScriptURI;
++
++  // This is the principal of the global (parent worker or a window) loading
++  // the worker. It can be null if we are executing a ServiceWorker, otherwise,
++  // except for data: URL, it must subsumes the worker principal.
++  // If we load a data: URL, mPrincipal will be a null principal.
++  nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
++  nsCOMPtr<nsIPrincipal> mPrincipal;
++
++  nsCOMPtr<nsIScriptContext> mScriptContext;
++  nsCOMPtr<nsPIDOMWindowInner> mWindow;
++  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
++  nsCOMPtr<nsIChannel> mChannel;
++  nsCOMPtr<nsILoadGroup> mLoadGroup;
++
++  // mLoadFailedAsyncRunnable will execute on main thread if script loading
++  // fails during script loading.  If script loading is never started due to
++  // a synchronous error, then the runnable is never executed.  The runnable
++  // is guaranteed to be released on the main thread.
++  nsCOMPtr<nsIRunnable> mLoadFailedAsyncRunnable;
++
++  class InterfaceRequestor final : public nsIInterfaceRequestor
++  {
++    NS_DECL_ISUPPORTS
++
++  public:
++    InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
++    void MaybeAddTabChild(nsILoadGroup* aLoadGroup);
++    NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override;
++
++  private:
++    ~InterfaceRequestor() { }
++
++    already_AddRefed<nsITabChild> GetAnyLiveTabChild();
++
++    nsCOMPtr<nsILoadContext> mLoadContext;
++    nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor;
++
++    // Array of weak references to nsITabChild.  We do not want to keep TabChild
++    // actors alive for long after their ActorDestroy() methods are called.
++    nsTArray<nsWeakPtr> mTabChildList;
++  };
++
++  // Only set if we have a custom overriden load group
++  RefPtr<InterfaceRequestor> mInterfaceRequestor;
++
++  nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
++  nsCString mDomain;
++  nsString mOrigin; // Derived from mPrincipal; can be used on worker thread.
++
++  nsString mServiceWorkerCacheName;
++  Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
++
++  Maybe<ServiceWorkerDescriptor> mParentController;
++
++  ChannelInfo mChannelInfo;
++  nsLoadFlags mLoadFlags;
++
++  uint64_t mWindowID;
++
++  net::ReferrerPolicy mReferrerPolicy;
++  bool mFromWindow;
++  bool mEvalAllowed;
++  bool mReportCSPViolations;
++  bool mXHRParamsAllowed;
++  bool mPrincipalIsSystem;
++  bool mStorageAllowed;
++  bool mServiceWorkersTestingInWindow;
++  OriginAttributes mOriginAttributes;
++
++  WorkerLoadInfo();
++  ~WorkerLoadInfo();
++
++  void StealFrom(WorkerLoadInfo& aOther);
++
++  nsresult
++  SetPrincipalOnMainThread(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
++
++  nsresult
++  GetPrincipalAndLoadGroupFromChannel(nsIChannel* aChannel,
++                                      nsIPrincipal** aPrincipalOut,
++                                      nsILoadGroup** aLoadGroupOut);
++
++  nsresult
++  SetPrincipalFromChannel(nsIChannel* aChannel);
++
++  bool
++  FinalChannelPrincipalIsValid(nsIChannel* aChannel);
++
++#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
++  bool
++  PrincipalIsValid() const;
++
++  bool
++  PrincipalURIMatchesScriptURL();
++#endif
++
++  bool
++  ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
++
++  bool
++  ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate,
++                                nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel);
++};
++
++END_WORKERS_NAMESPACE
++
++#endif // mozilla_dom_workers_WorkerLoadInfo_h
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
+--- a/dom/workers/WorkerPrivate.cpp
++++ b/dom/workers/WorkerPrivate.cpp
+@@ -12,23 +12,21 @@
+ #include "nsIConsoleService.h"
+ #include "nsIDOMDOMException.h"
+ #include "nsIDOMEvent.h"
+ #include "nsIDocument.h"
+ #include "nsIDocShell.h"
+ #include "nsIInterfaceRequestor.h"
+ #include "nsIMemoryReporter.h"
+ #include "nsINamed.h"
+-#include "nsINetworkInterceptController.h"
+ #include "nsIPermissionManager.h"
+ #include "nsIScriptError.h"
+ #include "nsIScriptGlobalObject.h"
+ #include "nsIScriptSecurityManager.h"
+ #include "nsIScriptTimeoutHandler.h"
+-#include "nsITabChild.h"
+ #include "nsITextToSubURI.h"
+ #include "nsIThreadInternal.h"
+ #include "nsITimer.h"
+ #include "nsIURI.h"
+ #include "nsIURL.h"
+ #include "nsIWeakReferenceUtils.h"
+ #include "nsIWorkerDebugger.h"
+ #include "nsIXPConnect.h"
+@@ -40,17 +38,16 @@
+ #include "jsfriendapi.h"
+ #include "js/MemoryMetrics.h"
+ #include "MessageEventRunnable.h"
+ #include "mozilla/Assertions.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/ContentEvents.h"
+ #include "mozilla/EventDispatcher.h"
+ #include "mozilla/Likely.h"
+-#include "mozilla/LoadContext.h"
+ #include "mozilla/Move.h"
+ #include "mozilla/dom/BindingUtils.h"
+ #include "mozilla/dom/ClientManager.h"
+ #include "mozilla/dom/ClientSource.h"
+ #include "mozilla/dom/ClientState.h"
+ #include "mozilla/dom/Console.h"
+ #include "mozilla/dom/DocGroup.h"
+ #include "mozilla/dom/ErrorEvent.h"
+@@ -68,17 +65,16 @@
+ #include "mozilla/dom/PerformanceStorageWorker.h"
+ #include "mozilla/dom/PMessagePort.h"
+ #include "mozilla/dom/Promise.h"
+ #include "mozilla/dom/PromiseDebugging.h"
+ #include "mozilla/dom/PromiseNativeHandler.h"
+ #include "mozilla/dom/SimpleGlobalObject.h"
+ #include "mozilla/dom/ScriptSettings.h"
+ #include "mozilla/dom/StructuredCloneHolder.h"
+-#include "mozilla/dom/TabChild.h"
+ #include "mozilla/dom/WorkerBinding.h"
+ #include "mozilla/dom/WorkerDebuggerGlobalScopeBinding.h"
+ #include "mozilla/dom/WorkerGlobalScopeBinding.h"
+ #include "mozilla/Preferences.h"
+ #include "mozilla/ThreadEventQueue.h"
+ #include "mozilla/ThrottledEventQueue.h"
+ #include "mozilla/TimelineConsumers.h"
+ #include "mozilla/WorkerTimelineMarker.h"
+@@ -196,38 +192,16 @@ public:
+ 
+ template <class T>
+ inline AutoPtrComparator<T>
+ GetAutoPtrComparator(const nsTArray<nsAutoPtr<T> >&)
+ {
+   return AutoPtrComparator<T>();
+ }
+ 
+-// Specialize this if there's some class that has multiple nsISupports bases.
+-template <class T>
+-struct ISupportsBaseInfo
+-{
+-  typedef T ISupportsBase;
+-};
+-
+-template <template <class> class SmartPtr, class T>
+-inline void
+-SwapToISupportsArray(SmartPtr<T>& aSrc,
+-                     nsTArray<nsCOMPtr<nsISupports> >& aDest)
+-{
+-  nsCOMPtr<nsISupports>* dest = aDest.AppendElement();
+-
+-  T* raw = nullptr;
+-  aSrc.swap(raw);
+-
+-  nsISupports* rawSupports =
+-    static_cast<typename ISupportsBaseInfo<T>::ISupportsBase*>(raw);
+-  dest->swap(rawSupports);
+-}
+-
+ // This class is used to wrap any runnables that the worker receives via the
+ // nsIEventTarget::Dispatch() method (either from NS_DispatchToCurrentThread or
+ // from the worker's EventTarget).
+ class ExternalRunnableWrapper final : public WorkerRunnable
+ {
+   nsCOMPtr<nsIRunnable> mWrappedRunnable;
+ 
+ public:
+@@ -359,49 +333,16 @@ LogErrorToConsole(const WorkerErrorRepor
+   __android_log_print(ANDROID_LOG_INFO, "Gecko", kErrorString, msg.get(),
+                       filename.get(), aReport.mLineNumber);
+ #endif
+ 
+   fprintf(stderr, kErrorString, msg.get(), filename.get(), aReport.mLineNumber);
+   fflush(stderr);
+ }
+ 
+-class MainThreadReleaseRunnable final : public Runnable
+-{
+-  nsTArray<nsCOMPtr<nsISupports>> mDoomed;
+-  nsCOMPtr<nsILoadGroup> mLoadGroupToCancel;
+-
+-public:
+-  MainThreadReleaseRunnable(nsTArray<nsCOMPtr<nsISupports>>& aDoomed,
+-                            nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel)
+-    : mozilla::Runnable("MainThreadReleaseRunnable")
+-  {
+-    mDoomed.SwapElements(aDoomed);
+-    mLoadGroupToCancel.swap(aLoadGroupToCancel);
+-  }
+-
+-  NS_DECL_ISUPPORTS_INHERITED
+-
+-  NS_IMETHOD
+-  Run() override
+-  {
+-    if (mLoadGroupToCancel) {
+-      mLoadGroupToCancel->Cancel(NS_BINDING_ABORTED);
+-      mLoadGroupToCancel = nullptr;
+-    }
+-
+-    mDoomed.Clear();
+-    return NS_OK;
+-  }
+-
+-private:
+-  ~MainThreadReleaseRunnable()
+-  { }
+-};
+-
+ class WorkerFinishedRunnable final : public WorkerControlRunnable
+ {
+   WorkerPrivate* mFinishedWorker;
+ 
+ public:
+   WorkerFinishedRunnable(WorkerPrivate* aWorkerPrivate,
+                          WorkerPrivate* aFinishedWorker)
+   : WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
+@@ -1457,18 +1398,16 @@ public:
+     : WorkerHolder("SimpleWorkerHolder")
+   {}
+ 
+   virtual bool Notify(Status aStatus) override { return true; }
+ };
+ 
+ } /* anonymous namespace */
+ 
+-NS_IMPL_ISUPPORTS_INHERITED0(MainThreadReleaseRunnable, Runnable)
+-
+ NS_IMPL_ISUPPORTS_INHERITED0(TopLevelWorkerFinishedRunnable, Runnable)
+ 
+ namespace {
+ 
+ class WrappedControlRunnable final : public WorkerControlRunnable
+ {
+   nsCOMPtr<nsIRunnable> mInner;
+ 
+@@ -1636,357 +1575,16 @@ public:
+   NS_DECL_THREADSAFE_ISUPPORTS
+ };
+ 
+ NS_IMPL_ISUPPORTS(WorkerEventTarget, nsIEventTarget,
+                                             nsISerialEventTarget)
+ 
+ END_WORKERS_NAMESPACE
+ 
+-WorkerLoadInfo::WorkerLoadInfo()
+-  : mLoadFlags(nsIRequest::LOAD_NORMAL)
+-  , mWindowID(UINT64_MAX)
+-  , mReferrerPolicy(net::RP_Unset)
+-  , mFromWindow(false)
+-  , mEvalAllowed(false)
+-  , mReportCSPViolations(false)
+-  , mXHRParamsAllowed(false)
+-  , mPrincipalIsSystem(false)
+-  , mStorageAllowed(false)
+-  , mServiceWorkersTestingInWindow(false)
+-{
+-  MOZ_COUNT_CTOR(WorkerLoadInfo);
+-}
+-
+-WorkerLoadInfo::~WorkerLoadInfo()
+-{
+-  MOZ_COUNT_DTOR(WorkerLoadInfo);
+-}
+-
+-void
+-WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther)
+-{
+-  MOZ_ASSERT(!mBaseURI);
+-  aOther.mBaseURI.swap(mBaseURI);
+-
+-  MOZ_ASSERT(!mResolvedScriptURI);
+-  aOther.mResolvedScriptURI.swap(mResolvedScriptURI);
+-
+-  MOZ_ASSERT(!mPrincipal);
+-  aOther.mPrincipal.swap(mPrincipal);
+-
+-  // mLoadingPrincipal can be null if this is a ServiceWorker.
+-  aOther.mLoadingPrincipal.swap(mLoadingPrincipal);
+-
+-  MOZ_ASSERT(!mScriptContext);
+-  aOther.mScriptContext.swap(mScriptContext);
+-
+-  MOZ_ASSERT(!mWindow);
+-  aOther.mWindow.swap(mWindow);
+-
+-  MOZ_ASSERT(!mCSP);
+-  aOther.mCSP.swap(mCSP);
+-
+-  MOZ_ASSERT(!mChannel);
+-  aOther.mChannel.swap(mChannel);
+-
+-  MOZ_ASSERT(!mLoadGroup);
+-  aOther.mLoadGroup.swap(mLoadGroup);
+-
+-  MOZ_ASSERT(!mLoadFailedAsyncRunnable);
+-  aOther.mLoadFailedAsyncRunnable.swap(mLoadFailedAsyncRunnable);
+-
+-  MOZ_ASSERT(!mInterfaceRequestor);
+-  aOther.mInterfaceRequestor.swap(mInterfaceRequestor);
+-
+-  MOZ_ASSERT(!mPrincipalInfo);
+-  mPrincipalInfo = aOther.mPrincipalInfo.forget();
+-
+-  mDomain = aOther.mDomain;
+-  mOrigin = aOther.mOrigin;
+-  mServiceWorkerCacheName = aOther.mServiceWorkerCacheName;
+-  mServiceWorkerDescriptor = aOther.mServiceWorkerDescriptor;
+-  mLoadFlags = aOther.mLoadFlags;
+-  mWindowID = aOther.mWindowID;
+-  mReferrerPolicy = aOther.mReferrerPolicy;
+-  mFromWindow = aOther.mFromWindow;
+-  mEvalAllowed = aOther.mEvalAllowed;
+-  mReportCSPViolations = aOther.mReportCSPViolations;
+-  mXHRParamsAllowed = aOther.mXHRParamsAllowed;
+-  mPrincipalIsSystem = aOther.mPrincipalIsSystem;
+-  mStorageAllowed = aOther.mStorageAllowed;
+-  mServiceWorkersTestingInWindow = aOther.mServiceWorkersTestingInWindow;
+-  mOriginAttributes = aOther.mOriginAttributes;
+-  mParentController = aOther.mParentController;
+-}
+-
+-nsresult
+-WorkerLoadInfo::SetPrincipalOnMainThread(nsIPrincipal* aPrincipal,
+-                                         nsILoadGroup* aLoadGroup)
+-{
+-  AssertIsOnMainThread();
+-  MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(aLoadGroup, aPrincipal));
+-
+-  mPrincipal = aPrincipal;
+-  mPrincipalIsSystem = nsContentUtils::IsSystemPrincipal(aPrincipal);
+-
+-  nsresult rv = aPrincipal->GetCsp(getter_AddRefs(mCSP));
+-  NS_ENSURE_SUCCESS(rv, rv);
+-
+-  if (mCSP) {
+-    mCSP->GetAllowsEval(&mReportCSPViolations, &mEvalAllowed);
+-    // Set ReferrerPolicy
+-    bool hasReferrerPolicy = false;
+-    uint32_t rp = mozilla::net::RP_Unset;
+-
+-    rv = mCSP->GetReferrerPolicy(&rp, &hasReferrerPolicy);
+-    NS_ENSURE_SUCCESS(rv, rv);
+-
+-    if (hasReferrerPolicy) {
+-      mReferrerPolicy = static_cast<net::ReferrerPolicy>(rp);
+-    }
+-  } else {
+-    mEvalAllowed = true;
+-    mReportCSPViolations = false;
+-  }
+-
+-  mLoadGroup = aLoadGroup;
+-
+-  mPrincipalInfo = new PrincipalInfo();
+-  mOriginAttributes = nsContentUtils::GetOriginAttributes(aLoadGroup);
+-
+-  rv = PrincipalToPrincipalInfo(aPrincipal, mPrincipalInfo);
+-  NS_ENSURE_SUCCESS(rv, rv);
+-
+-  rv = nsContentUtils::GetUTFOrigin(aPrincipal, mOrigin);
+-  NS_ENSURE_SUCCESS(rv, rv);
+-
+-  return NS_OK;
+-}
+-
+-nsresult
+-WorkerLoadInfo::GetPrincipalAndLoadGroupFromChannel(nsIChannel* aChannel,
+-                                                    nsIPrincipal** aPrincipalOut,
+-                                                    nsILoadGroup** aLoadGroupOut)
+-{
+-  AssertIsOnMainThread();
+-  MOZ_DIAGNOSTIC_ASSERT(aChannel);
+-  MOZ_DIAGNOSTIC_ASSERT(aPrincipalOut);
+-  MOZ_DIAGNOSTIC_ASSERT(aLoadGroupOut);
+-
+-  // Initial triggering principal should be set
+-  NS_ENSURE_TRUE(mLoadingPrincipal, NS_ERROR_DOM_INVALID_STATE_ERR);
+-
+-  nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
+-  MOZ_DIAGNOSTIC_ASSERT(ssm);
+-
+-  nsCOMPtr<nsIPrincipal> channelPrincipal;
+-  nsresult rv = ssm->GetChannelResultPrincipal(aChannel, getter_AddRefs(channelPrincipal));
+-  NS_ENSURE_SUCCESS(rv, rv);
+-
+-  // Every time we call GetChannelResultPrincipal() it will return a different
+-  // null principal for a data URL.  We don't want to change the worker's
+-  // principal again, though.  Instead just keep the original null principal we
+-  // first got from the channel.
+-  //
+-  // Note, we don't do this by setting principalToInherit on the channel's
+-  // load info because we don't yet have the first null principal when we
+-  // create the channel.
+-  if (mPrincipal && mPrincipal->GetIsNullPrincipal() &&
+-                    channelPrincipal->GetIsNullPrincipal()) {
+-    channelPrincipal = mPrincipal;
+-  }
+-
+-  nsCOMPtr<nsILoadGroup> channelLoadGroup;
+-  rv = aChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
+-  NS_ENSURE_SUCCESS(rv, rv);
+-  MOZ_ASSERT(channelLoadGroup);
+-
+-  // If the loading principal is the system principal then the channel
+-  // principal must also be the system principal (we do not allow chrome
+-  // code to create workers with non-chrome scripts, and if we ever decide
+-  // to change this we need to make sure we don't always set
+-  // mPrincipalIsSystem to true in WorkerPrivate::GetLoadInfo()). Otherwise
+-  // this channel principal must be same origin with the load principal (we
+-  // check again here in case redirects changed the location of the script).
+-  if (nsContentUtils::IsSystemPrincipal(mLoadingPrincipal)) {
+-    if (!nsContentUtils::IsSystemPrincipal(channelPrincipal)) {
+-      nsCOMPtr<nsIURI> finalURI;
+-      rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(finalURI));
+-      NS_ENSURE_SUCCESS(rv, rv);
+-
+-      // See if this is a resource URI. Since JSMs usually come from
+-      // resource:// URIs we're currently considering all URIs with the
+-      // URI_IS_UI_RESOURCE flag as valid for creating privileged workers.
+-      bool isResource;
+-      rv = NS_URIChainHasFlags(finalURI,
+-                               nsIProtocolHandler::URI_IS_UI_RESOURCE,
+-                               &isResource);
+-      NS_ENSURE_SUCCESS(rv, rv);
+-
+-      if (isResource) {
+-        // Assign the system principal to the resource:// worker only if it
+-        // was loaded from code using the system principal.
+-        channelPrincipal = mLoadingPrincipal;
+-      } else {
+-        return NS_ERROR_DOM_BAD_URI;
+-      }
+-    }
+-  }
+-
+-  // The principal can change, but it should still match the original
+-  // load group's appId and browser element flag.
+-  MOZ_ASSERT(NS_LoadGroupMatchesPrincipal(channelLoadGroup, channelPrincipal));
+-
+-  channelPrincipal.forget(aPrincipalOut);
+-  channelLoadGroup.forget(aLoadGroupOut);
+-
+-  return NS_OK;
+-}
+-
+-nsresult
+-WorkerLoadInfo::SetPrincipalFromChannel(nsIChannel* aChannel)
+-{
+-  AssertIsOnMainThread();
+-
+-  nsCOMPtr<nsIPrincipal> principal;
+-  nsCOMPtr<nsILoadGroup> loadGroup;
+-  nsresult rv = GetPrincipalAndLoadGroupFromChannel(aChannel,
+-                                                    getter_AddRefs(principal),
+-                                                    getter_AddRefs(loadGroup));
+-  NS_ENSURE_SUCCESS(rv, rv);
+-
+-  return SetPrincipalOnMainThread(principal, loadGroup);
+-}
+-
+-bool
+-WorkerLoadInfo::FinalChannelPrincipalIsValid(nsIChannel* aChannel)
+-{
+-  AssertIsOnMainThread();
+-
+-  nsCOMPtr<nsIPrincipal> principal;
+-  nsCOMPtr<nsILoadGroup> loadGroup;
+-  nsresult rv = GetPrincipalAndLoadGroupFromChannel(aChannel,
+-                                                    getter_AddRefs(principal),
+-                                                    getter_AddRefs(loadGroup));
+-  NS_ENSURE_SUCCESS(rv, false);
+-
+-
+-  // Verify that the channel is still a null principal.  We don't care
+-  // if these are the exact same null principal object, though.  From
+-  // the worker's perspective its the same effect.
+-  if (principal->GetIsNullPrincipal() && mPrincipal->GetIsNullPrincipal()) {
+-    return true;
+-  }
+-
+-  // Otherwise we require exact equality.  Redirects can happen, but they
+-  // are not allowed to change our principal.
+-  if (principal->Equals(mPrincipal)) {
+-    return true;
+-  }
+-
+-  return false;
+-}
+-
+-#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
+-bool
+-WorkerLoadInfo::PrincipalIsValid() const
+-{
+-  return mPrincipal && mPrincipalInfo &&
+-         mPrincipalInfo->type() != PrincipalInfo::T__None &&
+-         mPrincipalInfo->type() <= PrincipalInfo::T__Last;
+-}
+-
+-bool
+-WorkerLoadInfo::PrincipalURIMatchesScriptURL()
+-{
+-  AssertIsOnMainThread();
+-
+-  nsAutoCString scheme;
+-  nsresult rv = mBaseURI->GetScheme(scheme);
+-  NS_ENSURE_SUCCESS(rv, false);
+-
+-  // A system principal must either be a blob URL or a resource JSM.
+-  if (mPrincipal->GetIsSystemPrincipal()) {
+-    if (scheme == NS_LITERAL_CSTRING("blob")) {
+-      return true;
+-    }
+-
+-    bool isResource = false;
+-    nsresult rv = NS_URIChainHasFlags(mBaseURI,
+-                                      nsIProtocolHandler::URI_IS_UI_RESOURCE,
+-                                      &isResource);
+-    NS_ENSURE_SUCCESS(rv, false);
+-
+-    return isResource;
+-  }
+-
+-  // A null principal can occur for a data URL worker script or a blob URL
+-  // worker script from a sandboxed iframe.
+-  if (mPrincipal->GetIsNullPrincipal()) {
+-    return scheme == NS_LITERAL_CSTRING("data") ||
+-           scheme == NS_LITERAL_CSTRING("blob");
+-  }
+-
+-  // The principal for a blob: URL worker script does not have a matching URL.
+-  // This is likely a bug in our referer setting logic, but exempt it for now.
+-  // This is another reason we should fix bug 1340694 so that referer does not
+-  // depend on the principal URI.
+-  if (scheme == NS_LITERAL_CSTRING("blob")) {
+-    return true;
+-  }
+-
+-  nsCOMPtr<nsIURI> principalURI;
+-  rv = mPrincipal->GetURI(getter_AddRefs(principalURI));
+-  NS_ENSURE_SUCCESS(rv, false);
+-  NS_ENSURE_TRUE(principalURI, false);
+-
+-  bool equal = false;
+-  rv = principalURI->Equals(mBaseURI, &equal);
+-  NS_ENSURE_SUCCESS(rv, false);
+-
+-  return equal;
+-}
+-#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
+-
+-bool
+-WorkerLoadInfo::ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate)
+-{
+-  nsCOMPtr<nsILoadGroup> nullLoadGroup;
+-  return ProxyReleaseMainThreadObjects(aWorkerPrivate, nullLoadGroup);
+-}
+-
+-bool
+-WorkerLoadInfo::ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate,
+-                                              nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel)
+-{
+-
+-  static const uint32_t kDoomedCount = 11;
+-  nsTArray<nsCOMPtr<nsISupports>> doomed(kDoomedCount);
+-
+-  SwapToISupportsArray(mWindow, doomed);
+-  SwapToISupportsArray(mScriptContext, doomed);
+-  SwapToISupportsArray(mBaseURI, doomed);
+-  SwapToISupportsArray(mResolvedScriptURI, doomed);
+-  SwapToISupportsArray(mPrincipal, doomed);
+-  SwapToISupportsArray(mLoadingPrincipal, doomed);
+-  SwapToISupportsArray(mChannel, doomed);
+-  SwapToISupportsArray(mCSP, doomed);
+-  SwapToISupportsArray(mLoadGroup, doomed);
+-  SwapToISupportsArray(mLoadFailedAsyncRunnable, doomed);
+-  SwapToISupportsArray(mInterfaceRequestor, doomed);
+-  // Before adding anything here update kDoomedCount above!
+-
+-  MOZ_ASSERT(doomed.Length() == kDoomedCount);
+-
+-  RefPtr<MainThreadReleaseRunnable> runnable =
+-    new MainThreadReleaseRunnable(doomed, aLoadGroupToCancel);
+-  return NS_SUCCEEDED(aWorkerPrivate->DispatchToMainThread(runnable.forget()));
+-}
+-
+ template <class Derived>
+ class WorkerPrivateParent<Derived>::EventTarget final
+   : public nsISerialEventTarget
+ {
+   // This mutex protects mWorkerPrivate and must be acquired *before* the
+   // WorkerPrivate's mutex whenever they must both be held.
+   mozilla::Mutex mMutex;
+   WorkerPrivate* mWorkerPrivate;
+@@ -2033,130 +1631,16 @@ public:
+   NS_DECL_THREADSAFE_ISUPPORTS
+   NS_DECL_NSIEVENTTARGET_FULL
+ 
+ private:
+   ~EventTarget()
+   { }
+ };
+ 
+-WorkerLoadInfo::
+-InterfaceRequestor::InterfaceRequestor(nsIPrincipal* aPrincipal,
+-                                       nsILoadGroup* aLoadGroup)
+-{
+-  MOZ_ASSERT(NS_IsMainThread());
+-  MOZ_ASSERT(aPrincipal);
+-
+-  // Look for an existing LoadContext.  This is optional and it's ok if
+-  // we don't find one.
+-  nsCOMPtr<nsILoadContext> baseContext;
+-  if (aLoadGroup) {
+-    nsCOMPtr<nsIInterfaceRequestor> callbacks;
+-    aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
+-    if (callbacks) {
+-      callbacks->GetInterface(NS_GET_IID(nsILoadContext),
+-                              getter_AddRefs(baseContext));
+-    }
+-    mOuterRequestor = callbacks;
+-  }
+-
+-  mLoadContext = new LoadContext(aPrincipal, baseContext);
+-}
+-
+-void
+-WorkerLoadInfo::
+-InterfaceRequestor::MaybeAddTabChild(nsILoadGroup* aLoadGroup)
+-{
+-  MOZ_ASSERT(NS_IsMainThread());
+-
+-  if (!aLoadGroup) {
+-    return;
+-  }
+-
+-  nsCOMPtr<nsIInterfaceRequestor> callbacks;
+-  aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
+-  if (!callbacks) {
+-    return;
+-  }
+-
+-  nsCOMPtr<nsITabChild> tabChild;
+-  callbacks->GetInterface(NS_GET_IID(nsITabChild), getter_AddRefs(tabChild));
+-  if (!tabChild) {
+-    return;
+-  }
+-
+-  // Use weak references to the tab child.  Holding a strong reference will
+-  // not prevent an ActorDestroy() from being called on the TabChild.
+-  // Therefore, we should let the TabChild destroy itself as soon as possible.
+-  mTabChildList.AppendElement(do_GetWeakReference(tabChild));
+-}
+-
+-NS_IMETHODIMP
+-WorkerLoadInfo::
+-InterfaceRequestor::GetInterface(const nsIID& aIID, void** aSink)
+-{
+-  MOZ_ASSERT(NS_IsMainThread());
+-  MOZ_ASSERT(mLoadContext);
+-
+-  if (aIID.Equals(NS_GET_IID(nsILoadContext))) {
+-    nsCOMPtr<nsILoadContext> ref = mLoadContext;
+-    ref.forget(aSink);
+-    return NS_OK;
+-  }
+-
+-  // If we still have an active nsITabChild, then return it.  Its possible,
+-  // though, that all of the TabChild objects have been destroyed.  In that
+-  // case we return NS_NOINTERFACE.
+-  if (aIID.Equals(NS_GET_IID(nsITabChild))) {
+-    nsCOMPtr<nsITabChild> tabChild = GetAnyLiveTabChild();
+-    if (!tabChild) {
+-      return NS_NOINTERFACE;
+-    }
+-    tabChild.forget(aSink);
+-    return NS_OK;
+-  }
+-
+-  if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController)) &&
+-      mOuterRequestor) {
+-    // If asked for the network intercept controller, ask the outer requestor,
+-    // which could be the docshell.
+-    return mOuterRequestor->GetInterface(aIID, aSink);
+-  }
+-
+-  return NS_NOINTERFACE;
+-}
+-
+-already_AddRefed<nsITabChild>
+-WorkerLoadInfo::
+-InterfaceRequestor::GetAnyLiveTabChild()
+-{
+-  MOZ_ASSERT(NS_IsMainThread());
+-
+-  // Search our list of known TabChild objects for one that still exists.
+-  while (!mTabChildList.IsEmpty()) {
+-    nsCOMPtr<nsITabChild> tabChild =
+-      do_QueryReferent(mTabChildList.LastElement());
+-
+-    // Does this tab child still exist?  If so, return it.  We are done.  If the
+-    // PBrowser actor is no longer useful, don't bother returning this tab.
+-    if (tabChild && !static_cast<TabChild*>(tabChild.get())->IsDestroyed()) {
+-      return tabChild.forget();
+-    }
+-
+-    // Otherwise remove the stale weak reference and check the next one
+-    mTabChildList.RemoveElementAt(mTabChildList.Length() - 1);
+-  }
+-
+-  return nullptr;
+-}
+-
+-NS_IMPL_ADDREF(WorkerLoadInfo::InterfaceRequestor)
+-NS_IMPL_RELEASE(WorkerLoadInfo::InterfaceRequestor)
+-NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor, nsIInterfaceRequestor)
+-
+ struct WorkerPrivate::TimeoutInfo
+ {
+   TimeoutInfo()
+   : mId(0), mIsInterval(false), mCanceled(false)
+   {
+     MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerPrivate::TimeoutInfo);
+   }
+ 
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
+--- a/dom/workers/WorkerPrivate.h
++++ b/dom/workers/WorkerPrivate.h
+@@ -3,16 +3,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerprivate_h__
+ #define mozilla_dom_workers_workerprivate_h__
+ 
+ #include "WorkerCommon.h"
++#include "WorkerLoadInfo.h"
+ 
+ #include "js/CharacterEncoding.h"
+ #include "nsIContentPolicy.h"
+ #include "nsIContentSecurityPolicy.h"
+ #include "nsILoadGroup.h"
+ #include "nsIWorkerDebugger.h"
+ #include "nsPIDOMWindow.h"
+ 
+diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
+--- a/dom/workers/WorkerScope.cpp
++++ b/dom/workers/WorkerScope.cpp
+@@ -5,16 +5,17 @@
+  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+ #include "WorkerScope.h"
+ 
+ #include "jsapi.h"
+ #include "mozilla/EventListenerManager.h"
+ #include "mozilla/dom/BindingDeclarations.h"
+ #include "mozilla/dom/Clients.h"
++#include "mozilla/dom/ClientState.h"
+ #include "mozilla/dom/Console.h"
+ #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
+ #include "mozilla/dom/DOMPrefs.h"
+ #include "mozilla/dom/Fetch.h"
+ #include "mozilla/dom/FunctionBinding.h"
+ #include "mozilla/dom/IDBFactory.h"
+ #include "mozilla/dom/ImageBitmap.h"
+ #include "mozilla/dom/ImageBitmapBinding.h"
+@@ -29,16 +30,17 @@
+ #include "mozilla/dom/WorkerLocation.h"
+ #include "mozilla/dom/WorkerNavigator.h"
+ #include "mozilla/dom/cache/CacheStorage.h"
+ #include "mozilla/Services.h"
+ #include "nsServiceManagerUtils.h"
+ 
+ #include "nsIDocument.h"
+ #include "nsIServiceWorkerManager.h"
++#include "nsIScriptError.h"
+ #include "nsIScriptTimeoutHandler.h"
+ 
+ #ifdef ANDROID
+ #include <android/log.h>
+ #endif
+ 
+ #include "Crypto.h"
+ #include "Principal.h"
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -16,16 +16,17 @@ EXPORTS.mozilla.dom += [
+     'WorkerRunnable.h',
+     'WorkerScope.h',
+ ]
+ 
+ EXPORTS.mozilla.dom.workers += [
+     'RuntimeService.h',
+     'WorkerCommon.h',
+     'WorkerDebuggerManager.h',
++    'WorkerLoadInfo.h',
+ ]
+ 
+ # Stuff needed for the bindings, not really public though.
+ EXPORTS.mozilla.dom.workers.bindings += [
+     'SharedWorker.h',
+     'WorkerHolder.h',
+     'WorkerHolderToken.h',
+ ]
+@@ -44,16 +45,17 @@ UNIFIED_SOURCES += [
+     'Principal.cpp',
+     'RegisterBindings.cpp',
+     'RuntimeService.cpp',
+     'ScriptLoader.cpp',
+     'SharedWorker.cpp',
+     'WorkerDebuggerManager.cpp',
+     'WorkerHolder.cpp',
+     'WorkerHolderToken.cpp',
++    'WorkerLoadInfo.cpp',
+     'WorkerLocation.cpp',
+     'WorkerNavigator.cpp',
+     'WorkerPrivate.cpp',
+     'WorkerRunnable.cpp',
+     'WorkerScope.cpp',
+     'WorkerThread.cpp',
+ ]
+ 

+ 1466 - 0
mozilla-release/patches/1413112-4-60a1.patch

@@ -0,0 +1,1466 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303546 -3600
+# Node ID a21f55ba5530649e029b615c835eaffed7799e28
+# Parent  0894869ef55942ce139b898992e972493fb5f39b
+Bug 1413112 - Separate files for WorkerDebugger, r=bkelly
+
+diff --git a/dom/serviceworkers/ServiceWorkerPrivate.cpp b/dom/serviceworkers/ServiceWorkerPrivate.cpp
+--- a/dom/serviceworkers/ServiceWorkerPrivate.cpp
++++ b/dom/serviceworkers/ServiceWorkerPrivate.cpp
+@@ -17,16 +17,17 @@
+ #include "nsISupportsImpl.h"
+ #include "nsITimedChannel.h"
+ #include "nsIUploadChannel2.h"
+ #include "nsNetUtil.h"
+ #include "nsProxyRelease.h"
+ #include "nsQueryObject.h"
+ #include "nsStreamUtils.h"
+ #include "nsStringStream.h"
++#include "WorkerDebugger.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "mozilla/Assertions.h"
+ #include "mozilla/dom/Client.h"
+ #include "mozilla/dom/ClientIPCTypes.h"
+ #include "mozilla/dom/DOMPrefs.h"
+ #include "mozilla/dom/FetchUtil.h"
+ #include "mozilla/dom/IndexedDatabaseManager.h"
+diff --git a/dom/workers/ScriptLoader.h b/dom/workers/ScriptLoader.h
+--- a/dom/workers/ScriptLoader.h
++++ b/dom/workers/ScriptLoader.h
+@@ -20,16 +20,18 @@ class nsIChannel;
+ namespace mozilla {
+ 
+ class ErrorResult;
+ 
+ } // namespace mozilla
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
++struct WorkerLoadInfo;
++
+ enum WorkerScriptType {
+   WorkerScript,
+   DebuggerScript
+ };
+ 
+ namespace scriptloader {
+ 
+ nsresult
+diff --git a/dom/workers/WorkerDebugger.cpp b/dom/workers/WorkerDebugger.cpp
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerDebugger.cpp
+@@ -0,0 +1,477 @@
++/* -*- 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 "WorkerDebugger.h"
++
++#include "mozilla/dom/MessageEvent.h"
++#include "mozilla/dom/MessageEventBinding.h"
++#include "nsProxyRelease.h"
++#include "nsQueryObject.h"
++#include "nsThreadUtils.h"
++#include "ScriptLoader.h"
++#include "WorkerCommon.h"
++#include "WorkerPrivate.h"
++#include "WorkerRunnable.h"
++#include "WorkerScope.h"
++
++namespace mozilla {
++namespace dom {
++namespace workers {
++
++namespace {
++
++class DebuggerMessageEventRunnable : public WorkerDebuggerRunnable
++{
++  nsString mMessage;
++
++public:
++  DebuggerMessageEventRunnable(WorkerPrivate* aWorkerPrivate,
++                               const nsAString& aMessage)
++  : WorkerDebuggerRunnable(aWorkerPrivate),
++    mMessage(aMessage)
++  {
++  }
++
++private:
++  virtual bool
++  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
++  {
++    WorkerDebuggerGlobalScope* globalScope = aWorkerPrivate->DebuggerGlobalScope();
++    MOZ_ASSERT(globalScope);
++
++    JS::Rooted<JSString*> message(aCx, JS_NewUCStringCopyN(aCx, mMessage.get(),
++                                                           mMessage.Length()));
++    if (!message) {
++      return false;
++    }
++    JS::Rooted<JS::Value> data(aCx, JS::StringValue(message));
++
++    RefPtr<MessageEvent> event = new MessageEvent(globalScope, nullptr,
++                                                  nullptr);
++    event->InitMessageEvent(nullptr,
++                            NS_LITERAL_STRING("message"),
++                            false, // canBubble
++                            true, // cancelable
++                            data,
++                            EmptyString(),
++                            EmptyString(),
++                            nullptr,
++                            Sequence<OwningNonNull<MessagePort>>());
++    event->SetTrusted(true);
++
++    nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
++    bool dummy;
++    globalScope->DispatchEvent(domEvent, &dummy);
++    return true;
++  }
++};
++
++class CompileDebuggerScriptRunnable final : public WorkerDebuggerRunnable
++{
++  nsString mScriptURL;
++
++public:
++  CompileDebuggerScriptRunnable(WorkerPrivate* aWorkerPrivate,
++                                const nsAString& aScriptURL)
++  : WorkerDebuggerRunnable(aWorkerPrivate),
++    mScriptURL(aScriptURL)
++  { }
++
++private:
++  virtual bool
++  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
++  {
++    aWorkerPrivate->AssertIsOnWorkerThread();
++
++    WorkerDebuggerGlobalScope* globalScope =
++      aWorkerPrivate->CreateDebuggerGlobalScope(aCx);
++    if (!globalScope) {
++      NS_WARNING("Failed to make global!");
++      return false;
++    }
++
++    if (NS_WARN_IF(!aWorkerPrivate->EnsureClientSource())) {
++      return false;
++    }
++
++    JS::Rooted<JSObject*> global(aCx, globalScope->GetWrapper());
++
++    ErrorResult rv;
++    JSAutoCompartment ac(aCx, global);
++    scriptloader::LoadMainScript(aWorkerPrivate, mScriptURL,
++                                 DebuggerScript, rv);
++    rv.WouldReportJSException();
++    // Explicitly ignore NS_BINDING_ABORTED on rv.  Or more precisely, still
++    // return false and don't SetWorkerScriptExecutedSuccessfully() in that
++    // case, but don't throw anything on aCx.  The idea is to not dispatch error
++    // events if our load is canceled with that error code.
++    if (rv.ErrorCodeIs(NS_BINDING_ABORTED)) {
++      rv.SuppressException();
++      return false;
++    }
++    // Make sure to propagate exceptions from rv onto aCx, so that they will get
++    // reported after we return.  We do this for all failures on rv, because now
++    // we're using rv to track all the state we care about.
++    if (rv.MaybeSetPendingException(aCx)) {
++      return false;
++    }
++
++    return true;
++  }
++};
++
++} // anonymous
++
++class WorkerDebugger::PostDebuggerMessageRunnable final : public Runnable
++{
++  WorkerDebugger *mDebugger;
++  nsString mMessage;
++
++public:
++  PostDebuggerMessageRunnable(WorkerDebugger* aDebugger,
++                              const nsAString& aMessage)
++    : mozilla::Runnable("PostDebuggerMessageRunnable")
++    , mDebugger(aDebugger)
++    , mMessage(aMessage)
++  {
++  }
++
++private:
++  ~PostDebuggerMessageRunnable()
++  { }
++
++  NS_IMETHOD
++  Run() override
++  {
++    mDebugger->PostMessageToDebuggerOnMainThread(mMessage);
++
++    return NS_OK;
++  }
++};
++
++class WorkerDebugger::ReportDebuggerErrorRunnable final : public Runnable
++{
++  WorkerDebugger *mDebugger;
++  nsString mFilename;
++  uint32_t mLineno;
++  nsString mMessage;
++
++public:
++  ReportDebuggerErrorRunnable(WorkerDebugger* aDebugger,
++                              const nsAString& aFilename,
++                              uint32_t aLineno,
++                              const nsAString& aMessage)
++    : Runnable("ReportDebuggerErrorRunnable")
++    , mDebugger(aDebugger)
++    , mFilename(aFilename)
++    , mLineno(aLineno)
++    , mMessage(aMessage)
++  {
++  }
++
++private:
++  ~ReportDebuggerErrorRunnable()
++  { }
++
++  NS_IMETHOD
++  Run() override
++  {
++    mDebugger->ReportErrorToDebuggerOnMainThread(mFilename, mLineno, mMessage);
++
++    return NS_OK;
++  }
++};
++
++WorkerDebugger::WorkerDebugger(WorkerPrivate* aWorkerPrivate)
++: mWorkerPrivate(aWorkerPrivate),
++  mIsInitialized(false)
++{
++  AssertIsOnMainThread();
++}
++
++WorkerDebugger::~WorkerDebugger()
++{
++  MOZ_ASSERT(!mWorkerPrivate);
++
++  if (!NS_IsMainThread()) {
++    for (size_t index = 0; index < mListeners.Length(); ++index) {
++      NS_ReleaseOnMainThreadSystemGroup(
++        "WorkerDebugger::mListeners", mListeners[index].forget());
++    }
++  }
++}
++
++NS_IMPL_ISUPPORTS(WorkerDebugger, nsIWorkerDebugger)
++
++NS_IMETHODIMP
++WorkerDebugger::GetIsClosed(bool* aResult)
++{
++  AssertIsOnMainThread();
++
++  *aResult = !mWorkerPrivate;
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetIsChrome(bool* aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  *aResult = mWorkerPrivate->IsChromeWorker();
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetIsInitialized(bool* aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  *aResult = mIsInitialized;
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetParent(nsIWorkerDebugger** aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  WorkerPrivate* parent = mWorkerPrivate->GetParent();
++  if (!parent) {
++    *aResult = nullptr;
++    return NS_OK;
++  }
++
++  MOZ_ASSERT(mWorkerPrivate->IsDedicatedWorker());
++
++  nsCOMPtr<nsIWorkerDebugger> debugger = parent->Debugger();
++  debugger.forget(aResult);
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetType(uint32_t* aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  *aResult = mWorkerPrivate->Type();
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetUrl(nsAString& aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  aResult = mWorkerPrivate->ScriptURL();
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetWindow(mozIDOMWindow** aResult)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  if (mWorkerPrivate->GetParent() || !mWorkerPrivate->IsDedicatedWorker()) {
++    *aResult = nullptr;
++    return NS_OK;
++  }
++
++  nsCOMPtr<nsPIDOMWindowInner> window = mWorkerPrivate->GetWindow();
++  window.forget(aResult);
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetPrincipal(nsIPrincipal** aResult)
++{
++  AssertIsOnMainThread();
++  MOZ_ASSERT(aResult);
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  nsCOMPtr<nsIPrincipal> prin = mWorkerPrivate->GetPrincipal();
++  prin.forget(aResult);
++
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::GetServiceWorkerID(uint32_t* aResult)
++{
++  AssertIsOnMainThread();
++  MOZ_ASSERT(aResult);
++
++  if (!mWorkerPrivate || !mWorkerPrivate->IsServiceWorker()) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  *aResult = mWorkerPrivate->ServiceWorkerID();
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::Initialize(const nsAString& aURL)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  if (!mIsInitialized) {
++    RefPtr<CompileDebuggerScriptRunnable> runnable =
++      new CompileDebuggerScriptRunnable(mWorkerPrivate, aURL);
++    if (!runnable->Dispatch()) {
++      return NS_ERROR_FAILURE;
++    }
++
++    mIsInitialized = true;
++  }
++
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::PostMessageMoz(const nsAString& aMessage)
++{
++  AssertIsOnMainThread();
++
++  if (!mWorkerPrivate || !mIsInitialized) {
++    return NS_ERROR_UNEXPECTED;
++  }
++
++  RefPtr<DebuggerMessageEventRunnable> runnable =
++    new DebuggerMessageEventRunnable(mWorkerPrivate, aMessage);
++  if (!runnable->Dispatch()) {
++    return NS_ERROR_FAILURE;
++  }
++
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::AddListener(nsIWorkerDebuggerListener* aListener)
++{
++  AssertIsOnMainThread();
++
++  if (mListeners.Contains(aListener)) {
++    return NS_ERROR_INVALID_ARG;
++  }
++
++  mListeners.AppendElement(aListener);
++  return NS_OK;
++}
++
++NS_IMETHODIMP
++WorkerDebugger::RemoveListener(nsIWorkerDebuggerListener* aListener)
++{
++  AssertIsOnMainThread();
++
++  if (!mListeners.Contains(aListener)) {
++    return NS_ERROR_INVALID_ARG;
++  }
++
++  mListeners.RemoveElement(aListener);
++  return NS_OK;
++}
++
++void
++WorkerDebugger::Close()
++{
++  MOZ_ASSERT(mWorkerPrivate);
++  mWorkerPrivate = nullptr;
++
++  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
++  for (size_t index = 0; index < listeners.Length(); ++index) {
++      listeners[index]->OnClose();
++  }
++}
++
++void
++WorkerDebugger::PostMessageToDebugger(const nsAString& aMessage)
++{
++  mWorkerPrivate->AssertIsOnWorkerThread();
++
++  RefPtr<PostDebuggerMessageRunnable> runnable =
++    new PostDebuggerMessageRunnable(this, aMessage);
++  if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable.forget()))) {
++    NS_WARNING("Failed to post message to debugger on main thread!");
++  }
++}
++
++void
++WorkerDebugger::PostMessageToDebuggerOnMainThread(const nsAString& aMessage)
++{
++  AssertIsOnMainThread();
++
++  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
++  for (size_t index = 0; index < listeners.Length(); ++index) {
++    listeners[index]->OnMessage(aMessage);
++  }
++}
++
++void
++WorkerDebugger::ReportErrorToDebugger(const nsAString& aFilename,
++                                      uint32_t aLineno,
++                                      const nsAString& aMessage)
++{
++  mWorkerPrivate->AssertIsOnWorkerThread();
++
++  RefPtr<ReportDebuggerErrorRunnable> runnable =
++    new ReportDebuggerErrorRunnable(this, aFilename, aLineno, aMessage);
++  if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable.forget()))) {
++    NS_WARNING("Failed to report error to debugger on main thread!");
++  }
++}
++
++void
++WorkerDebugger::ReportErrorToDebuggerOnMainThread(const nsAString& aFilename,
++                                                  uint32_t aLineno,
++                                                  const nsAString& aMessage)
++{
++  AssertIsOnMainThread();
++
++  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
++  for (size_t index = 0; index < listeners.Length(); ++index) {
++    listeners[index]->OnError(aFilename, aLineno, aMessage);
++  }
++
++  WorkerErrorReport report;
++  report.mMessage = aMessage;
++  report.mFilename = aFilename;
++  LogErrorToConsole(report, 0);
++}
++
++
++} // worker namespace
++} // dom namespace
++} // mozilla namespace
+diff --git a/dom/workers/WorkerDebugger.h b/dom/workers/WorkerDebugger.h
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerDebugger.h
+@@ -0,0 +1,58 @@
++/* -*- 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/. */
++
++#ifndef mozilla_dom_workers_WorkerDebugger_h
++#define mozilla_dom_workers_WorkerDebugger_h
++
++#include "mozilla/dom/workers/WorkerCommon.h"
++#include "nsIWorkerDebugger.h"
++
++BEGIN_WORKERS_NAMESPACE
++
++class WorkerDebugger : public nsIWorkerDebugger
++{
++  class ReportDebuggerErrorRunnable;
++  class PostDebuggerMessageRunnable;
++
++  WorkerPrivate* mWorkerPrivate;
++  bool mIsInitialized;
++  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> mListeners;
++
++public:
++  explicit WorkerDebugger(WorkerPrivate* aWorkerPrivate);
++
++  NS_DECL_ISUPPORTS
++  NS_DECL_NSIWORKERDEBUGGER
++
++  void
++  AssertIsOnParentThread();
++
++  void
++  Close();
++
++  void
++  PostMessageToDebugger(const nsAString& aMessage);
++
++  void
++  ReportErrorToDebugger(const nsAString& aFilename, uint32_t aLineno,
++                        const nsAString& aMessage);
++
++private:
++  virtual
++  ~WorkerDebugger();
++
++  void
++  PostMessageToDebuggerOnMainThread(const nsAString& aMessage);
++
++  void
++  ReportErrorToDebuggerOnMainThread(const nsAString& aFilename,
++                                    uint32_t aLineno,
++                                    const nsAString& aMessage);
++};
++
++END_WORKERS_NAMESPACE
++
++#endif // mozilla_dom_workers_WorkerDebugger_h
+diff --git a/dom/workers/WorkerDebuggerManager.cpp b/dom/workers/WorkerDebuggerManager.cpp
+--- a/dom/workers/WorkerDebuggerManager.cpp
++++ b/dom/workers/WorkerDebuggerManager.cpp
+@@ -6,16 +6,17 @@
+ 
+ #include "WorkerDebuggerManager.h"
+ 
+ #include "nsISimpleEnumerator.h"
+ 
+ #include "mozilla/ClearOnShutdown.h"
+ #include "mozilla/StaticPtr.h"
+ 
++#include "WorkerDebugger.h"
+ #include "WorkerPrivate.h"
+ 
+ USING_WORKERS_NAMESPACE
+ 
+ namespace {
+ 
+ class RegisterDebuggerMainThreadRunnable final : public mozilla::Runnable
+ {
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
+--- a/dom/workers/WorkerPrivate.cpp
++++ b/dom/workers/WorkerPrivate.cpp
+@@ -23,17 +23,16 @@
+ #include "nsIScriptSecurityManager.h"
+ #include "nsIScriptTimeoutHandler.h"
+ #include "nsITextToSubURI.h"
+ #include "nsIThreadInternal.h"
+ #include "nsITimer.h"
+ #include "nsIURI.h"
+ #include "nsIURL.h"
+ #include "nsIWeakReferenceUtils.h"
+-#include "nsIWorkerDebugger.h"
+ #include "nsIXPConnect.h"
+ #include "nsPIDOMWindow.h"
+ #include "nsGlobalWindow.h"
+ 
+ #include <algorithm>
+ #include "ImageContainer.h"
+ #include "jsfriendapi.h"
+ #include "js/MemoryMetrics.h"
+@@ -106,16 +105,17 @@
+ 
+ #include "Navigator.h"
+ #include "Principal.h"
+ #include "RuntimeService.h"
+ #include "ScriptLoader.h"
+ #include "mozilla/dom/ServiceWorkerEvents.h"
+ #include "mozilla/dom/ServiceWorkerManager.h"
+ #include "SharedWorker.h"
++#include "WorkerDebugger.h"
+ #include "WorkerDebuggerManager.h"
+ #include "WorkerHolder.h"
+ #include "WorkerNavigator.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "WorkerThread.h"
+ 
+ // JS_MaybeGC will run once every second during normal execution.
+@@ -270,79 +270,16 @@ struct WindowAction
+ 
+   bool
+   operator==(const WindowAction& aOther) const
+   {
+     return mWindow == aOther.mWindow;
+   }
+ };
+ 
+-void
+-LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId)
+-{
+-  AssertIsOnMainThread();
+-
+-  RefPtr<nsScriptErrorBase> scriptError = new nsScriptError();
+-  NS_WARNING_ASSERTION(scriptError, "Failed to create script error!");
+-
+-  if (scriptError) {
+-    nsAutoCString category("Web Worker");
+-    if (NS_FAILED(scriptError->InitWithWindowID(aReport.mMessage,
+-                                                aReport.mFilename,
+-                                                aReport.mLine,
+-                                                aReport.mLineNumber,
+-                                                aReport.mColumnNumber,
+-                                                aReport.mFlags,
+-                                                category,
+-                                                aInnerWindowId))) {
+-      NS_WARNING("Failed to init script error!");
+-      scriptError = nullptr;
+-    }
+-
+-    for (size_t i = 0, len = aReport.mNotes.Length(); i < len; i++) {
+-      const WorkerErrorNote& note = aReport.mNotes.ElementAt(i);
+-
+-      nsScriptErrorNote* noteObject = new nsScriptErrorNote();
+-      noteObject->Init(note.mMessage, note.mFilename,
+-                       note.mLineNumber, note.mColumnNumber);
+-      scriptError->AddNote(noteObject);
+-    }
+-  }
+-
+-  nsCOMPtr<nsIConsoleService> consoleService =
+-    do_GetService(NS_CONSOLESERVICE_CONTRACTID);
+-  NS_WARNING_ASSERTION(consoleService, "Failed to get console service!");
+-
+-  if (consoleService) {
+-    if (scriptError) {
+-      if (NS_SUCCEEDED(consoleService->LogMessage(scriptError))) {
+-        return;
+-      }
+-      NS_WARNING("LogMessage failed!");
+-    } else if (NS_SUCCEEDED(consoleService->LogStringMessage(
+-                              aReport.mMessage.BeginReading()))) {
+-      return;
+-    }
+-    NS_WARNING("LogStringMessage failed!");
+-  }
+-
+-  NS_ConvertUTF16toUTF8 msg(aReport.mMessage);
+-  NS_ConvertUTF16toUTF8 filename(aReport.mFilename);
+-
+-  static const char kErrorString[] = "JS error in Web Worker: %s [%s:%u]";
+-
+-#ifdef ANDROID
+-  __android_log_print(ANDROID_LOG_INFO, "Gecko", kErrorString, msg.get(),
+-                      filename.get(), aReport.mLineNumber);
+-#endif
+-
+-  fprintf(stderr, kErrorString, msg.get(), filename.get(), aReport.mLineNumber);
+-  fflush(stderr);
+-}
+-
+ class WorkerFinishedRunnable final : public WorkerControlRunnable
+ {
+   WorkerPrivate* mFinishedWorker;
+ 
+ public:
+   WorkerFinishedRunnable(WorkerPrivate* aWorkerPrivate,
+                          WorkerPrivate* aFinishedWorker)
+   : WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
+@@ -589,115 +526,16 @@ private:
+       return false;
+     }
+ 
+     aWorkerPrivate->SetWorkerScriptExecutedSuccessfully();
+     return true;
+   }
+ };
+ 
+-class CompileDebuggerScriptRunnable final : public WorkerDebuggerRunnable
+-{
+-  nsString mScriptURL;
+-
+-public:
+-  CompileDebuggerScriptRunnable(WorkerPrivate* aWorkerPrivate,
+-                                const nsAString& aScriptURL)
+-  : WorkerDebuggerRunnable(aWorkerPrivate),
+-    mScriptURL(aScriptURL)
+-  { }
+-
+-private:
+-  virtual bool
+-  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
+-  {
+-    aWorkerPrivate->AssertIsOnWorkerThread();
+-
+-    WorkerDebuggerGlobalScope* globalScope =
+-      aWorkerPrivate->CreateDebuggerGlobalScope(aCx);
+-    if (!globalScope) {
+-      NS_WARNING("Failed to make global!");
+-      return false;
+-    }
+-
+-    if (NS_WARN_IF(!aWorkerPrivate->EnsureClientSource())) {
+-      return false;
+-    }
+-
+-    JS::Rooted<JSObject*> global(aCx, globalScope->GetWrapper());
+-
+-    ErrorResult rv;
+-    JSAutoCompartment ac(aCx, global);
+-    scriptloader::LoadMainScript(aWorkerPrivate, mScriptURL,
+-                                 DebuggerScript, rv);
+-    rv.WouldReportJSException();
+-    // Explicitly ignore NS_BINDING_ABORTED on rv.  Or more precisely, still
+-    // return false and don't SetWorkerScriptExecutedSuccessfully() in that
+-    // case, but don't throw anything on aCx.  The idea is to not dispatch error
+-    // events if our load is canceled with that error code.
+-    if (rv.ErrorCodeIs(NS_BINDING_ABORTED)) {
+-      rv.SuppressException();
+-      return false;
+-    }
+-    // Make sure to propagate exceptions from rv onto aCx, so that they will get
+-    // reported after we return.  We do this for all failures on rv, because now
+-    // we're using rv to track all the state we care about.
+-    if (rv.MaybeSetPendingException(aCx)) {
+-      return false;
+-    }
+-
+-    return true;
+-  }
+-};
+-
+-class DebuggerMessageEventRunnable : public WorkerDebuggerRunnable {
+-  nsString mMessage;
+-
+-public:
+-  DebuggerMessageEventRunnable(WorkerPrivate* aWorkerPrivate,
+-                               const nsAString& aMessage)
+-  : WorkerDebuggerRunnable(aWorkerPrivate),
+-    mMessage(aMessage)
+-  {
+-  }
+-
+-private:
+-  virtual bool
+-  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
+-  {
+-    WorkerDebuggerGlobalScope* globalScope = aWorkerPrivate->DebuggerGlobalScope();
+-    MOZ_ASSERT(globalScope);
+-
+-    JS::Rooted<JSString*> message(aCx, JS_NewUCStringCopyN(aCx, mMessage.get(),
+-                                                           mMessage.Length()));
+-    if (!message) {
+-      return false;
+-    }
+-    JS::Rooted<JS::Value> data(aCx, JS::StringValue(message));
+-
+-    RefPtr<MessageEvent> event = new MessageEvent(globalScope, nullptr,
+-                                                    nullptr);
+-    event->InitMessageEvent(nullptr,
+-                            NS_LITERAL_STRING("message"),
+-                            false, // canBubble
+-                            true, // cancelable
+-                            data,
+-                            EmptyString(),
+-                            EmptyString(),
+-                            nullptr,
+-                            Sequence<OwningNonNull<MessagePort>>());
+-    event->SetTrusted(true);
+-
+-    nsCOMPtr<nsIDOMEvent> domEvent = do_QueryObject(event);
+-    bool dummy;
+-    globalScope->DispatchEvent(domEvent, &dummy);
+-    return true;
+-  }
+-};
+-
+ class NotifyRunnable final : public WorkerControlRunnable
+ {
+   Status mStatus;
+ 
+ public:
+   NotifyRunnable(WorkerPrivate* aWorkerPrivate, Status aStatus)
+   : WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount),
+     mStatus(aStatus)
+@@ -3481,362 +3319,16 @@ WorkerPrivateParent<Derived>::AssertInne
+ template <class Derived>
+ bool
+ WorkerPrivateParent<Derived>::PrincipalIsValid() const
+ {
+   return mLoadInfo.PrincipalIsValid();
+ }
+ #endif
+ 
+-class PostDebuggerMessageRunnable final : public Runnable
+-{
+-  WorkerDebugger *mDebugger;
+-  nsString mMessage;
+-
+-public:
+-  PostDebuggerMessageRunnable(WorkerDebugger* aDebugger,
+-                              const nsAString& aMessage)
+-    : mozilla::Runnable("PostDebuggerMessageRunnable")
+-    , mDebugger(aDebugger)
+-    , mMessage(aMessage)
+-  {
+-  }
+-
+-private:
+-  ~PostDebuggerMessageRunnable()
+-  { }
+-
+-  NS_IMETHOD
+-  Run() override
+-  {
+-    mDebugger->PostMessageToDebuggerOnMainThread(mMessage);
+-
+-    return NS_OK;
+-  }
+-};
+-
+-class ReportDebuggerErrorRunnable final : public Runnable
+-{
+-  WorkerDebugger *mDebugger;
+-  nsString mFilename;
+-  uint32_t mLineno;
+-  nsString mMessage;
+-
+-public:
+-  ReportDebuggerErrorRunnable(WorkerDebugger* aDebugger,
+-                              const nsAString& aFilename,
+-                              uint32_t aLineno,
+-                              const nsAString& aMessage)
+-    : mozilla::Runnable("ReportDebuggerErrorRunnable")
+-    , mDebugger(aDebugger)
+-    , mFilename(aFilename)
+-    , mLineno(aLineno)
+-    , mMessage(aMessage)
+-  {
+-  }
+-
+-private:
+-  ~ReportDebuggerErrorRunnable()
+-  { }
+-
+-  NS_IMETHOD
+-  Run() override
+-  {
+-    mDebugger->ReportErrorToDebuggerOnMainThread(mFilename, mLineno, mMessage);
+-
+-    return NS_OK;
+-  }
+-};
+-
+-WorkerDebugger::WorkerDebugger(WorkerPrivate* aWorkerPrivate)
+-: mWorkerPrivate(aWorkerPrivate),
+-  mIsInitialized(false)
+-{
+-  AssertIsOnMainThread();
+-}
+-
+-WorkerDebugger::~WorkerDebugger()
+-{
+-  MOZ_ASSERT(!mWorkerPrivate);
+-
+-  if (!NS_IsMainThread()) {
+-    for (size_t index = 0; index < mListeners.Length(); ++index) {
+-      NS_ReleaseOnMainThreadSystemGroup(
+-        "WorkerDebugger::mListeners", mListeners[index].forget());
+-    }
+-  }
+-}
+-
+-NS_IMPL_ISUPPORTS(WorkerDebugger, nsIWorkerDebugger)
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetIsClosed(bool* aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  *aResult = !mWorkerPrivate;
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetIsChrome(bool* aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  *aResult = mWorkerPrivate->IsChromeWorker();
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetIsInitialized(bool* aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  *aResult = mIsInitialized;
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetParent(nsIWorkerDebugger** aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  WorkerPrivate* parent = mWorkerPrivate->GetParent();
+-  if (!parent) {
+-    *aResult = nullptr;
+-    return NS_OK;
+-  }
+-
+-  MOZ_ASSERT(mWorkerPrivate->IsDedicatedWorker());
+-
+-  nsCOMPtr<nsIWorkerDebugger> debugger = parent->Debugger();
+-  debugger.forget(aResult);
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetType(uint32_t* aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  *aResult = mWorkerPrivate->Type();
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetUrl(nsAString& aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  aResult = mWorkerPrivate->ScriptURL();
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetWindow(mozIDOMWindow** aResult)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  if (mWorkerPrivate->GetParent() || !mWorkerPrivate->IsDedicatedWorker()) {
+-    *aResult = nullptr;
+-    return NS_OK;
+-  }
+-
+-  nsCOMPtr<nsPIDOMWindowInner> window = mWorkerPrivate->GetWindow();
+-  window.forget(aResult);
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetPrincipal(nsIPrincipal** aResult)
+-{
+-  AssertIsOnMainThread();
+-  MOZ_ASSERT(aResult);
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  nsCOMPtr<nsIPrincipal> prin = mWorkerPrivate->GetPrincipal();
+-  prin.forget(aResult);
+-
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::GetServiceWorkerID(uint32_t* aResult)
+-{
+-  AssertIsOnMainThread();
+-  MOZ_ASSERT(aResult);
+-
+-  if (!mWorkerPrivate || !mWorkerPrivate->IsServiceWorker()) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  *aResult = mWorkerPrivate->ServiceWorkerID();
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::Initialize(const nsAString& aURL)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  if (!mIsInitialized) {
+-    RefPtr<CompileDebuggerScriptRunnable> runnable =
+-      new CompileDebuggerScriptRunnable(mWorkerPrivate, aURL);
+-    if (!runnable->Dispatch()) {
+-      return NS_ERROR_FAILURE;
+-    }
+-
+-    mIsInitialized = true;
+-  }
+-
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::PostMessageMoz(const nsAString& aMessage)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mWorkerPrivate || !mIsInitialized) {
+-    return NS_ERROR_UNEXPECTED;
+-  }
+-
+-  RefPtr<DebuggerMessageEventRunnable> runnable =
+-    new DebuggerMessageEventRunnable(mWorkerPrivate, aMessage);
+-  if (!runnable->Dispatch()) {
+-    return NS_ERROR_FAILURE;
+-  }
+-
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::AddListener(nsIWorkerDebuggerListener* aListener)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (mListeners.Contains(aListener)) {
+-    return NS_ERROR_INVALID_ARG;
+-  }
+-
+-  mListeners.AppendElement(aListener);
+-  return NS_OK;
+-}
+-
+-NS_IMETHODIMP
+-WorkerDebugger::RemoveListener(nsIWorkerDebuggerListener* aListener)
+-{
+-  AssertIsOnMainThread();
+-
+-  if (!mListeners.Contains(aListener)) {
+-    return NS_ERROR_INVALID_ARG;
+-  }
+-
+-  mListeners.RemoveElement(aListener);
+-  return NS_OK;
+-}
+-
+-void
+-WorkerDebugger::Close()
+-{
+-  MOZ_ASSERT(mWorkerPrivate);
+-  mWorkerPrivate = nullptr;
+-
+-  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
+-  for (size_t index = 0; index < listeners.Length(); ++index) {
+-      listeners[index]->OnClose();
+-  }
+-}
+-
+-void
+-WorkerDebugger::PostMessageToDebugger(const nsAString& aMessage)
+-{
+-  mWorkerPrivate->AssertIsOnWorkerThread();
+-
+-  RefPtr<PostDebuggerMessageRunnable> runnable =
+-    new PostDebuggerMessageRunnable(this, aMessage);
+-  if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable.forget()))) {
+-    NS_WARNING("Failed to post message to debugger on main thread!");
+-  }
+-}
+-
+-void
+-WorkerDebugger::PostMessageToDebuggerOnMainThread(const nsAString& aMessage)
+-{
+-  AssertIsOnMainThread();
+-
+-  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
+-  for (size_t index = 0; index < listeners.Length(); ++index) {
+-    listeners[index]->OnMessage(aMessage);
+-  }
+-}
+-
+-void
+-WorkerDebugger::ReportErrorToDebugger(const nsAString& aFilename,
+-                                      uint32_t aLineno,
+-                                      const nsAString& aMessage)
+-{
+-  mWorkerPrivate->AssertIsOnWorkerThread();
+-
+-  RefPtr<ReportDebuggerErrorRunnable> runnable =
+-    new ReportDebuggerErrorRunnable(this, aFilename, aLineno, aMessage);
+-  if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable.forget()))) {
+-    NS_WARNING("Failed to report error to debugger on main thread!");
+-  }
+-}
+-
+-void
+-WorkerDebugger::ReportErrorToDebuggerOnMainThread(const nsAString& aFilename,
+-                                                  uint32_t aLineno,
+-                                                  const nsAString& aMessage)
+-{
+-  AssertIsOnMainThread();
+-
+-  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> listeners(mListeners);
+-  for (size_t index = 0; index < listeners.Length(); ++index) {
+-    listeners[index]->OnError(aFilename, aLineno, aMessage);
+-  }
+-
+-  WorkerErrorReport report;
+-  report.mMessage = aMessage;
+-  report.mFilename = aFilename;
+-  LogErrorToConsole(report, 0);
+-}
+-
+ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
+                              const nsAString& aScriptURL,
+                              bool aIsChromeWorker, WorkerType aWorkerType,
+                              const nsAString& aWorkerName,
+                              const nsACString& aServiceWorkerScope,
+                              WorkerLoadInfo& aLoadInfo)
+   : WorkerPrivateParent<WorkerPrivate>(aParent, aScriptURL,
+                                        aIsChromeWorker, aWorkerType,
+@@ -6683,14 +6175,77 @@ EventTarget::IsOnCurrentThreadInfallible
+   if (!mWorkerPrivate) {
+     NS_WARNING("A worker's event target was used after the worker has !");
+     return false;
+   }
+ 
+   return mWorkerPrivate->IsOnCurrentThread();
+ }
+ 
++void
++LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId)
++{
++  AssertIsOnMainThread();
++
++  RefPtr<nsScriptErrorBase> scriptError = new nsScriptError();
++  NS_WARNING_ASSERTION(scriptError, "Failed to create script error!");
++
++  if (scriptError) {
++    nsAutoCString category("Web Worker");
++    if (NS_FAILED(scriptError->InitWithWindowID(aReport.mMessage,
++                                                aReport.mFilename,
++                                                aReport.mLine,
++                                                aReport.mLineNumber,
++                                                aReport.mColumnNumber,
++                                                aReport.mFlags,
++                                                category,
++                                                aInnerWindowId))) {
++      NS_WARNING("Failed to init script error!");
++      scriptError = nullptr;
++    }
++
++    for (size_t i = 0, len = aReport.mNotes.Length(); i < len; i++) {
++      const WorkerErrorNote& note = aReport.mNotes.ElementAt(i);
++
++      nsScriptErrorNote* noteObject = new nsScriptErrorNote();
++      noteObject->Init(note.mMessage, note.mFilename,
++                       note.mLineNumber, note.mColumnNumber);
++      scriptError->AddNote(noteObject);
++    }
++  }
++
++  nsCOMPtr<nsIConsoleService> consoleService =
++    do_GetService(NS_CONSOLESERVICE_CONTRACTID);
++  NS_WARNING_ASSERTION(consoleService, "Failed to get console service!");
++
++  if (consoleService) {
++    if (scriptError) {
++      if (NS_SUCCEEDED(consoleService->LogMessage(scriptError))) {
++        return;
++      }
++      NS_WARNING("LogMessage failed!");
++    } else if (NS_SUCCEEDED(consoleService->LogStringMessage(
++                              aReport.mMessage.BeginReading()))) {
++      return;
++    }
++    NS_WARNING("LogStringMessage failed!");
++  }
++
++  NS_ConvertUTF16toUTF8 msg(aReport.mMessage);
++  NS_ConvertUTF16toUTF8 filename(aReport.mFilename);
++
++  static const char kErrorString[] = "JS error in Web Worker: %s [%s:%u]";
++
++#ifdef ANDROID
++  __android_log_print(ANDROID_LOG_INFO, "Gecko", kErrorString, msg.get(),
++                      filename.get(), aReport.mLineNumber);
++#endif
++
++  fprintf(stderr, kErrorString, msg.get(), filename.get(), aReport.mLineNumber);
++  fflush(stderr);
++}
++
+ BEGIN_WORKERS_NAMESPACE
+ 
+ // Force instantiation.
+ template class WorkerPrivateParent<WorkerPrivate>;
+ 
+ END_WORKERS_NAMESPACE
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
+--- a/dom/workers/WorkerPrivate.h
++++ b/dom/workers/WorkerPrivate.h
+@@ -9,17 +9,16 @@
+ 
+ #include "WorkerCommon.h"
+ #include "WorkerLoadInfo.h"
+ 
+ #include "js/CharacterEncoding.h"
+ #include "nsIContentPolicy.h"
+ #include "nsIContentSecurityPolicy.h"
+ #include "nsILoadGroup.h"
+-#include "nsIWorkerDebugger.h"
+ #include "nsPIDOMWindow.h"
+ 
+ #include "mozilla/Assertions.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/CondVar.h"
+ #include "mozilla/ConsoleReportCollector.h"
+ #include "mozilla/DOMEventTargetHelper.h"
+ #include "mozilla/Move.h"
+@@ -78,19 +77,16 @@ struct WorkerOptions;
+ } // namespace dom
+ namespace ipc {
+ class PrincipalInfo;
+ } // namespace ipc
+ } // namespace mozilla
+ 
+ struct PRThread;
+ 
+-class ReportDebuggerErrorRunnable;
+-class PostDebuggerMessageRunnable;
+-
+ BEGIN_WORKERS_NAMESPACE
+ 
+ class AutoSyncLoopHolder;
+ class SharedWorker;
+ class ServiceWorkerClientInfo;
+ class WorkerEventTarget;
+ class WorkerControlRunnable;
+ class WorkerDebugger;
+@@ -950,56 +946,16 @@ public:
+   // shutting down.
+   uint32_t
+   BusyCount()
+   {
+     return mBusyCount;
+   }
+ };
+ 
+-class WorkerDebugger : public nsIWorkerDebugger {
+-  friend class ::ReportDebuggerErrorRunnable;
+-  friend class ::PostDebuggerMessageRunnable;
+-
+-  WorkerPrivate* mWorkerPrivate;
+-  bool mIsInitialized;
+-  nsTArray<nsCOMPtr<nsIWorkerDebuggerListener>> mListeners;
+-
+-public:
+-  explicit WorkerDebugger(WorkerPrivate* aWorkerPrivate);
+-
+-  NS_DECL_ISUPPORTS
+-  NS_DECL_NSIWORKERDEBUGGER
+-
+-  void
+-  AssertIsOnParentThread();
+-
+-  void
+-  Close();
+-
+-  void
+-  PostMessageToDebugger(const nsAString& aMessage);
+-
+-  void
+-  ReportErrorToDebugger(const nsAString& aFilename, uint32_t aLineno,
+-                        const nsAString& aMessage);
+-
+-private:
+-  virtual
+-  ~WorkerDebugger();
+-
+-  void
+-  PostMessageToDebuggerOnMainThread(const nsAString& aMessage);
+-
+-  void
+-  ReportErrorToDebuggerOnMainThread(const nsAString& aFilename,
+-                                    uint32_t aLineno,
+-                                    const nsAString& aMessage);
+-};
+-
+ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
+ {
+   friend class WorkerHolder;
+   friend class WorkerPrivateParent<WorkerPrivate>;
+   typedef WorkerPrivateParent<WorkerPrivate> ParentType;
+   friend class AutoSyncLoopHolder;
+ 
+   struct TimeoutInfo;
+@@ -1695,11 +1651,15 @@ public:
+   nsIEventTarget*
+   GetEventTarget() const
+   {
+     // This can be null if CreateNewSyncLoop() fails.
+     return mTarget;
+   }
+ };
+ 
++// TODO: this will be removed in the next patch
++void
++LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId);
++
+ END_WORKERS_NAMESPACE
+ 
+ #endif /* mozilla_dom_workers_workerprivate_h__ */
+diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h
+--- a/dom/workers/WorkerRunnable.h
++++ b/dom/workers/WorkerRunnable.h
+@@ -3,16 +3,17 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerrunnable_h__
+ #define mozilla_dom_workers_workerrunnable_h__
+ 
+ #include "WorkerCommon.h"
++#include "WorkerHolder.h"
+ 
+ #include "nsICancelableRunnable.h"
+ 
+ #include "mozilla/Atomics.h"
+ #include "nsISupportsImpl.h"
+ #include "nsThreadUtils.h" /* nsRunnable */
+ 
+ struct JSContext;
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -15,16 +15,17 @@ EXPORTS.mozilla.dom += [
+     'WorkerPrivate.h',
+     'WorkerRunnable.h',
+     'WorkerScope.h',
+ ]
+ 
+ EXPORTS.mozilla.dom.workers += [
+     'RuntimeService.h',
+     'WorkerCommon.h',
++    'WorkerDebugger.h',
+     'WorkerDebuggerManager.h',
+     'WorkerLoadInfo.h',
+ ]
+ 
+ # Stuff needed for the bindings, not really public though.
+ EXPORTS.mozilla.dom.workers.bindings += [
+     'SharedWorker.h',
+     'WorkerHolder.h',
+@@ -42,16 +43,17 @@ UNIFIED_SOURCES += [
+     'ChromeWorkerScope.cpp',
+     'FileReaderSync.cpp',
+     'MessageEventRunnable.cpp',
+     'Principal.cpp',
+     'RegisterBindings.cpp',
+     'RuntimeService.cpp',
+     'ScriptLoader.cpp',
+     'SharedWorker.cpp',
++    'WorkerDebugger.cpp',
+     'WorkerDebuggerManager.cpp',
+     'WorkerHolder.cpp',
+     'WorkerHolderToken.cpp',
+     'WorkerLoadInfo.cpp',
+     'WorkerLocation.cpp',
+     'WorkerNavigator.cpp',
+     'WorkerPrivate.cpp',
+     'WorkerRunnable.cpp',

+ 1191 - 0
mozilla-release/patches/1413112-5-60a1.patch

@@ -0,0 +1,1191 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303570 -3600
+# Node ID fb8899d7c036b43b05283f825d444d6d0dc63fdc
+# Parent  e6efbd7ba4b273ebd2fb13373c8e666607f1f3ef
+Bug 1413112 - WorkerError in separate files, r=bkelly
+
+diff --git a/dom/performance/PerformanceStorageWorker.h b/dom/performance/PerformanceStorageWorker.h
+--- a/dom/performance/PerformanceStorageWorker.h
++++ b/dom/performance/PerformanceStorageWorker.h
+@@ -50,15 +50,15 @@ private:
+   // Protected by mutex.
+   enum {
+     eInitializing,
+     eReady,
+     eTerminated,
+   } mState;
+ 
+   // Touched on worker-thread only.
+-  UniquePtr<WorkerHolder> mWorkerHolder;
++  UniquePtr<workers::WorkerHolder> mWorkerHolder;
+ };
+ 
+ } // namespace dom
+ } // namespace mozilla
+ 
+ #endif // mozilla_dom_PerformanceStorageWorker_h
+diff --git a/dom/workers/WorkerDebugger.cpp b/dom/workers/WorkerDebugger.cpp
+--- a/dom/workers/WorkerDebugger.cpp
++++ b/dom/workers/WorkerDebugger.cpp
+@@ -8,16 +8,17 @@
+ 
+ #include "mozilla/dom/MessageEvent.h"
+ #include "mozilla/dom/MessageEventBinding.h"
+ #include "nsProxyRelease.h"
+ #include "nsQueryObject.h"
+ #include "nsThreadUtils.h"
+ #include "ScriptLoader.h"
+ #include "WorkerCommon.h"
++#include "WorkerError.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ namespace workers {
+ 
+diff --git a/dom/workers/WorkerError.cpp b/dom/workers/WorkerError.cpp
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerError.cpp
+@@ -0,0 +1,485 @@
++/* -*- 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 "WorkerError.h"
++
++#include "mozilla/DOMEventTargetHelper.h"
++#include "mozilla/dom/ErrorEvent.h"
++#include "mozilla/dom/ErrorEventBinding.h"
++#include "mozilla/dom/ServiceWorkerManager.h"
++#include "mozilla/dom/SimpleGlobalObject.h"
++#include "mozilla/dom/WorkerDebuggerGlobalScopeBinding.h"
++#include "mozilla/dom/WorkerGlobalScopeBinding.h"
++#include "mozilla/EventDispatcher.h"
++#include "nsIConsoleService.h"
++#include "nsScriptError.h"
++#include "WorkerRunnable.h"
++#include "WorkerPrivate.h"
++#include "WorkerScope.h"
++
++namespace mozilla {
++namespace dom {
++
++using namespace workers;
++
++namespace {
++
++class ReportErrorRunnable final : public WorkerRunnable
++{
++  WorkerErrorReport mReport;
++
++public:
++  // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
++  // aTarget is the worker object that we are going to fire an error at
++  // (if any).
++  static void
++  ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
++              bool aFireAtScope, WorkerPrivate* aTarget,
++              const WorkerErrorReport& aReport, uint64_t aInnerWindowId,
++              JS::Handle<JS::Value> aException = JS::NullHandleValue)
++  {
++    if (aWorkerPrivate) {
++      aWorkerPrivate->AssertIsOnWorkerThread();
++    } else {
++      AssertIsOnMainThread();
++    }
++
++    // We should not fire error events for warnings but instead make sure that
++    // they show up in the error console.
++    if (!JSREPORT_IS_WARNING(aReport.mFlags)) {
++      // First fire an ErrorEvent at the worker.
++      RootedDictionary<ErrorEventInit> init(aCx);
++
++      if (aReport.mMutedError) {
++        init.mMessage.AssignLiteral("Script error.");
++      } else {
++        init.mMessage = aReport.mMessage;
++        init.mFilename = aReport.mFilename;
++        init.mLineno = aReport.mLineNumber;
++        init.mError = aException;
++      }
++
++      init.mCancelable = true;
++      init.mBubbles = false;
++
++      if (aTarget) {
++        RefPtr<ErrorEvent> event =
++          ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
++        event->SetTrusted(true);
++
++        bool defaultActionEnabled;
++        aTarget->DispatchEvent(event, &defaultActionEnabled);
++
++        if (!defaultActionEnabled) {
++          return;
++        }
++      }
++
++      // Now fire an event at the global object, but don't do that if the error
++      // code is too much recursion and this is the same script threw the error.
++      // XXXbz the interaction of this with worker errors seems kinda broken.
++      // An overrecursion in the debugger or debugger sandbox will get turned
++      // into an error event on our parent worker!
++      // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks making this
++      // better.
++      if (aFireAtScope &&
++          (aTarget || aReport.mErrorNumber != JSMSG_OVER_RECURSED)) {
++        JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
++        NS_ASSERTION(global, "This should never be null!");
++
++        nsEventStatus status = nsEventStatus_eIgnore;
++        nsIScriptGlobalObject* sgo;
++
++        if (aWorkerPrivate) {
++          WorkerGlobalScope* globalScope = nullptr;
++          UNWRAP_OBJECT(WorkerGlobalScope, &global, globalScope);
++
++          if (!globalScope) {
++            WorkerDebuggerGlobalScope* globalScope = nullptr;
++            UNWRAP_OBJECT(WorkerDebuggerGlobalScope, &global, globalScope);
++
++            MOZ_ASSERT_IF(globalScope, globalScope->GetWrapperPreserveColor() == global);
++            if (globalScope || IsDebuggerSandbox(global)) {
++              aWorkerPrivate->ReportErrorToDebugger(aReport.mFilename, aReport.mLineNumber,
++                                                    aReport.mMessage);
++              return;
++            }
++
++            MOZ_ASSERT(SimpleGlobalObject::SimpleGlobalType(global) ==
++                         SimpleGlobalObject::GlobalType::BindingDetail);
++            // XXXbz We should really log this to console, but unwinding out of
++            // this stuff without ending up firing any events is ... hard.  Just
++            // return for now.
++            // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks
++            // making this better.
++            return;
++          }
++
++          MOZ_ASSERT(globalScope->GetWrapperPreserveColor() == global);
++          nsIDOMEventTarget* target = static_cast<nsIDOMEventTarget*>(globalScope);
++
++          RefPtr<ErrorEvent> event =
++            ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
++          event->SetTrusted(true);
++
++          if (NS_FAILED(EventDispatcher::DispatchDOMEvent(target, nullptr,
++                                                          event, nullptr,
++                                                          &status))) {
++            NS_WARNING("Failed to dispatch worker thread error event!");
++            status = nsEventStatus_eIgnore;
++          }
++        }
++        else if ((sgo = nsJSUtils::GetStaticScriptGlobal(global))) {
++          MOZ_ASSERT(NS_IsMainThread());
++
++          if (NS_FAILED(sgo->HandleScriptError(init, &status))) {
++            NS_WARNING("Failed to dispatch main thread error event!");
++            status = nsEventStatus_eIgnore;
++          }
++        }
++
++        // Was preventDefault() called?
++        if (status == nsEventStatus_eConsumeNoDefault) {
++          return;
++        }
++      }
++    }
++
++    // Now fire a runnable to do the same on the parent's thread if we can.
++    if (aWorkerPrivate) {
++      RefPtr<ReportErrorRunnable> runnable =
++        new ReportErrorRunnable(aWorkerPrivate, aReport);
++      runnable->Dispatch();
++      return;
++    }
++
++    // Otherwise log an error to the error console.
++    LogErrorToConsole(aReport, aInnerWindowId);
++  }
++
++  ReportErrorRunnable(WorkerPrivate* aWorkerPrivate,
++                      const WorkerErrorReport& aReport)
++  : WorkerRunnable(aWorkerPrivate, ParentThreadUnchangedBusyCount),
++    mReport(aReport)
++  { }
++
++private:
++  virtual void
++  PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
++  {
++    aWorkerPrivate->AssertIsOnWorkerThread();
++
++    // Dispatch may fail if the worker was canceled, no need to report that as
++    // an error, so don't call base class PostDispatch.
++  }
++
++  virtual bool
++  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
++  {
++    JS::Rooted<JSObject*> target(aCx, aWorkerPrivate->GetWrapper());
++
++    uint64_t innerWindowId;
++    bool fireAtScope = true;
++
++    bool workerIsAcceptingEvents = aWorkerPrivate->IsAcceptingEvents();
++
++    WorkerPrivate* parent = aWorkerPrivate->GetParent();
++    if (parent) {
++      innerWindowId = 0;
++    }
++    else {
++      AssertIsOnMainThread();
++
++      if (aWorkerPrivate->IsFrozen() ||
++          aWorkerPrivate->IsParentWindowPaused()) {
++        MOZ_ASSERT(!IsDebuggerRunnable());
++        aWorkerPrivate->QueueRunnable(this);
++        return true;
++      }
++
++      if (aWorkerPrivate->IsSharedWorker()) {
++        aWorkerPrivate->BroadcastErrorToSharedWorkers(aCx, &mReport,
++                                                      /* isErrorEvent */ true);
++        return true;
++      }
++
++      // Service workers do not have a main thread parent global, so normal
++      // worker error reporting will crash.  Instead, pass the error to
++      // the ServiceWorkerManager to report on any controlled documents.
++      if (aWorkerPrivate->IsServiceWorker()) {
++        RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
++        if (swm) {
++          swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(),
++                           aWorkerPrivate->ServiceWorkerScope(),
++                           aWorkerPrivate->ScriptURL(),
++                           mReport.mMessage,
++                           mReport.mFilename, mReport.mLine, mReport.mLineNumber,
++                           mReport.mColumnNumber, mReport.mFlags,
++                           mReport.mExnType);
++        }
++        return true;
++      }
++
++      // The innerWindowId is only required if we are going to ReportError
++      // below, which is gated on this condition. The inner window correctness
++      // check is only going to succeed when the worker is accepting events.
++      if (workerIsAcceptingEvents) {
++        aWorkerPrivate->AssertInnerWindowIsCorrect();
++        innerWindowId = aWorkerPrivate->WindowID();
++      }
++    }
++
++    // Don't fire this event if the JS object has been disconnected from the
++    // private object.
++    if (!workerIsAcceptingEvents) {
++      return true;
++    }
++
++    ReportError(aCx, parent, fireAtScope, aWorkerPrivate, mReport,
++                innerWindowId);
++    return true;
++  }
++};
++
++} // anonymous
++
++void
++WorkerErrorBase::AssignErrorBase(JSErrorBase* aReport)
++{
++  mFilename = NS_ConvertUTF8toUTF16(aReport->filename);
++  mLineNumber = aReport->lineno;
++  mColumnNumber = aReport->column;
++  mErrorNumber = aReport->errorNumber;
++}
++
++void
++WorkerErrorNote::AssignErrorNote(JSErrorNotes::Note* aNote)
++{
++  WorkerErrorBase::AssignErrorBase(aNote);
++  xpc::ErrorNote::ErrorNoteToMessageString(aNote, mMessage);
++}
++
++void
++WorkerErrorReport::AssignErrorReport(JSErrorReport* aReport)
++{
++  WorkerErrorBase::AssignErrorBase(aReport);
++  xpc::ErrorReport::ErrorReportToMessageString(aReport, mMessage);
++
++  mLine.Assign(aReport->linebuf(), aReport->linebufLength());
++  mFlags = aReport->flags;
++  MOZ_ASSERT(aReport->exnType >= JSEXN_FIRST && aReport->exnType < JSEXN_LIMIT);
++  mExnType = JSExnType(aReport->exnType);
++  mMutedError = aReport->isMuted;
++
++  if (aReport->notes) {
++    if (!mNotes.SetLength(aReport->notes->length(), fallible)) {
++      return;
++    }
++
++    size_t i = 0;
++    for (auto&& note : *aReport->notes) {
++      mNotes.ElementAt(i).AssignErrorNote(note.get());
++      i++;
++    }
++  }
++}
++
++namespace workers {
++
++// aWorkerPrivate is the worker thread we're on (or the main thread, if null)
++// aTarget is the worker object that we are going to fire an error at
++// (if any).
++void
++ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
++            bool aFireAtScope, DOMEventTargetHelper* aTarget,
++            const WorkerErrorReport& aReport, uint64_t aInnerWindowId,
++            JS::Handle<JS::Value> aException)
++{
++  if (aWorkerPrivate) {
++    aWorkerPrivate->AssertIsOnWorkerThread();
++  } else {
++    AssertIsOnMainThread();
++  }
++
++  // We should not fire error events for warnings but instead make sure that
++  // they show up in the error console.
++  if (!JSREPORT_IS_WARNING(aReport.mFlags)) {
++    // First fire an ErrorEvent at the worker.
++    RootedDictionary<ErrorEventInit> init(aCx);
++
++    if (aReport.mMutedError) {
++      init.mMessage.AssignLiteral("Script error.");
++    } else {
++      init.mMessage = aReport.mMessage;
++      init.mFilename = aReport.mFilename;
++      init.mLineno = aReport.mLineNumber;
++      init.mError = aException;
++    }
++
++    init.mCancelable = true;
++    init.mBubbles = false;
++
++    if (aTarget) {
++      RefPtr<ErrorEvent> event =
++        ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
++      event->SetTrusted(true);
++
++      bool defaultActionEnabled;
++      aTarget->DispatchEvent(event, &defaultActionEnabled);
++
++      if (!defaultActionEnabled) {
++        return;
++      }
++    }
++
++    // Now fire an event at the global object, but don't do that if the error
++    // code is too much recursion and this is the same script threw the error.
++    // XXXbz the interaction of this with worker errors seems kinda broken.
++    // An overrecursion in the debugger or debugger sandbox will get turned
++    // into an error event on our parent worker!
++    // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks making this
++    // better.
++    if (aFireAtScope &&
++        (aTarget || aReport.mErrorNumber != JSMSG_OVER_RECURSED)) {
++      JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
++      NS_ASSERTION(global, "This should never be null!");
++
++      nsEventStatus status = nsEventStatus_eIgnore;
++      nsIScriptGlobalObject* sgo;
++
++      if (aWorkerPrivate) {
++        WorkerGlobalScope* globalScope = nullptr;
++        UNWRAP_OBJECT(WorkerGlobalScope, &global, globalScope);
++
++        if (!globalScope) {
++          WorkerDebuggerGlobalScope* globalScope = nullptr;
++          UNWRAP_OBJECT(WorkerDebuggerGlobalScope, &global, globalScope);
++
++          MOZ_ASSERT_IF(globalScope, globalScope->GetWrapperPreserveColor() == global);
++          if (globalScope || IsDebuggerSandbox(global)) {
++            aWorkerPrivate->ReportErrorToDebugger(aReport.mFilename, aReport.mLineNumber,
++                                                  aReport.mMessage);
++            return;
++          }
++
++          MOZ_ASSERT(SimpleGlobalObject::SimpleGlobalType(global) ==
++                       SimpleGlobalObject::GlobalType::BindingDetail);
++          // XXXbz We should really log this to console, but unwinding out of
++          // this stuff without ending up firing any events is ... hard.  Just
++          // return for now.
++          // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks
++          // making this better.
++          return;
++        }
++
++        MOZ_ASSERT(globalScope->GetWrapperPreserveColor() == global);
++        nsIDOMEventTarget* target = static_cast<nsIDOMEventTarget*>(globalScope);
++
++        RefPtr<ErrorEvent> event =
++          ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
++        event->SetTrusted(true);
++
++        if (NS_FAILED(EventDispatcher::DispatchDOMEvent(target, nullptr,
++                                                        event, nullptr,
++                                                        &status))) {
++          NS_WARNING("Failed to dispatch worker thread error event!");
++          status = nsEventStatus_eIgnore;
++        }
++      }
++      else if ((sgo = nsJSUtils::GetStaticScriptGlobal(global))) {
++        MOZ_ASSERT(NS_IsMainThread());
++
++        if (NS_FAILED(sgo->HandleScriptError(init, &status))) {
++          NS_WARNING("Failed to dispatch main thread error event!");
++          status = nsEventStatus_eIgnore;
++        }
++      }
++
++      // Was preventDefault() called?
++      if (status == nsEventStatus_eConsumeNoDefault) {
++        return;
++      }
++    }
++  }
++
++  // Now fire a runnable to do the same on the parent's thread if we can.
++  if (aWorkerPrivate) {
++    RefPtr<ReportErrorRunnable> runnable =
++      new ReportErrorRunnable(aWorkerPrivate, aReport);
++    runnable->Dispatch();
++    return;
++  }
++
++  // Otherwise log an error to the error console.
++  LogErrorToConsole(aReport, aInnerWindowId);
++}
++
++void
++LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId)
++{
++  AssertIsOnMainThread();
++
++  RefPtr<nsScriptErrorBase> scriptError = new nsScriptError();
++  NS_WARNING_ASSERTION(scriptError, "Failed to create script error!");
++
++  if (scriptError) {
++    nsAutoCString category("Web Worker");
++    if (NS_FAILED(scriptError->InitWithWindowID(aReport.mMessage,
++                                                aReport.mFilename,
++                                                aReport.mLine,
++                                                aReport.mLineNumber,
++                                                aReport.mColumnNumber,
++                                                aReport.mFlags,
++                                                category,
++                                                aInnerWindowId))) {
++      NS_WARNING("Failed to init script error!");
++      scriptError = nullptr;
++    }
++
++    for (size_t i = 0, len = aReport.mNotes.Length(); i < len; i++) {
++      const WorkerErrorNote& note = aReport.mNotes.ElementAt(i);
++
++      nsScriptErrorNote* noteObject = new nsScriptErrorNote();
++      noteObject->Init(note.mMessage, note.mFilename,
++                       note.mLineNumber, note.mColumnNumber);
++      scriptError->AddNote(noteObject);
++    }
++  }
++
++  nsCOMPtr<nsIConsoleService> consoleService =
++    do_GetService(NS_CONSOLESERVICE_CONTRACTID);
++  NS_WARNING_ASSERTION(consoleService, "Failed to get console service!");
++
++  if (consoleService) {
++    if (scriptError) {
++      if (NS_SUCCEEDED(consoleService->LogMessage(scriptError))) {
++        return;
++      }
++      NS_WARNING("LogMessage failed!");
++    } else if (NS_SUCCEEDED(consoleService->LogStringMessage(
++                              aReport.mMessage.BeginReading()))) {
++      return;
++    }
++    NS_WARNING("LogStringMessage failed!");
++  }
++
++  NS_ConvertUTF16toUTF8 msg(aReport.mMessage);
++  NS_ConvertUTF16toUTF8 filename(aReport.mFilename);
++
++  static const char kErrorString[] = "JS error in Web Worker: %s [%s:%u]";
++
++#ifdef ANDROID
++  __android_log_print(ANDROID_LOG_INFO, "Gecko", kErrorString, msg.get(),
++                      filename.get(), aReport.mLineNumber);
++#endif
++
++  fprintf(stderr, kErrorString, msg.get(), filename.get(), aReport.mLineNumber);
++  fflush(stderr);
++}
++
++} // workers namespace
++} // dom namespace
++} // mozilla namespace
+diff --git a/dom/workers/WorkerError.h b/dom/workers/WorkerError.h
+new file mode 100644
+--- /dev/null
++++ b/dom/workers/WorkerError.h
+@@ -0,0 +1,82 @@
++/* -*- 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/. */
++
++#ifndef mozilla_dom_workers_WorkerError_h
++#define mozilla_dom_workers_WorkerError_h
++
++#include "WorkerCommon.h"
++#include "jsapi.h"
++
++namespace mozilla {
++
++class DOMEventTargetHelper;
++
++namespace dom {
++
++class WorkerErrorBase
++{
++public:
++  nsString mMessage;
++  nsString mFilename;
++  uint32_t mLineNumber;
++  uint32_t mColumnNumber;
++  uint32_t mErrorNumber;
++
++  WorkerErrorBase()
++  : mLineNumber(0),
++    mColumnNumber(0),
++    mErrorNumber(0)
++  { }
++
++  void AssignErrorBase(JSErrorBase* aReport);
++};
++
++class WorkerErrorNote : public WorkerErrorBase
++{
++public:
++  void AssignErrorNote(JSErrorNotes::Note* aNote);
++};
++
++class WorkerErrorReport : public WorkerErrorBase
++{
++public:
++  nsString mLine;
++  uint32_t mFlags;
++  JSExnType mExnType;
++  bool mMutedError;
++  nsTArray<WorkerErrorNote> mNotes;
++
++  WorkerErrorReport()
++  : mFlags(0),
++    mExnType(JSEXN_ERR),
++    mMutedError(false)
++  { }
++
++  void AssignErrorReport(JSErrorReport* aReport);
++};
++
++} // dom namespace
++} // mozilla namespace
++
++BEGIN_WORKERS_NAMESPACE
++
++class WorkerPrivate;
++
++// aWorkerPrivate is the worker thread we're on (or the main thread, if null)
++// aTarget is the worker object that we are going to fire an error at
++// (if any).
++void
++ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
++            bool aFireAtScope, DOMEventTargetHelper* aTarget,
++            const WorkerErrorReport& aReport, uint64_t aInnerWindowId,
++            JS::Handle<JS::Value> aException = JS::NullHandleValue);
++
++void
++LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId);
++
++END_WORKERS_NAMESPACE
++
++#endif // mozilla_dom_workers_WorkerError_h
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
+--- a/dom/workers/WorkerPrivate.cpp
++++ b/dom/workers/WorkerPrivate.cpp
+@@ -61,22 +61,19 @@
+ #include "mozilla/dom/MessagePortBinding.h"
+ #include "mozilla/dom/nsCSPUtils.h"
+ #include "mozilla/dom/Performance.h"
+ #include "mozilla/dom/PerformanceStorageWorker.h"
+ #include "mozilla/dom/PMessagePort.h"
+ #include "mozilla/dom/Promise.h"
+ #include "mozilla/dom/PromiseDebugging.h"
+ #include "mozilla/dom/PromiseNativeHandler.h"
+-#include "mozilla/dom/SimpleGlobalObject.h"
+ #include "mozilla/dom/ScriptSettings.h"
+ #include "mozilla/dom/StructuredCloneHolder.h"
+ #include "mozilla/dom/WorkerBinding.h"
+-#include "mozilla/dom/WorkerDebuggerGlobalScopeBinding.h"
+-#include "mozilla/dom/WorkerGlobalScopeBinding.h"
+ #include "mozilla/Preferences.h"
+ #include "mozilla/ThreadEventQueue.h"
+ #include "mozilla/ThrottledEventQueue.h"
+ #include "mozilla/TimelineConsumers.h"
+ #include "mozilla/WorkerTimelineMarker.h"
+ #include "nsAlgorithm.h"
+ #include "nsContentUtils.h"
+ #include "nsCycleCollector.h"
+@@ -85,17 +82,16 @@
+ #include "nsHostObjectProtocolHandler.h"
+ #include "nsJSEnvironment.h"
+ #include "nsJSUtils.h"
+ #include "nsNetUtil.h"
+ #include "nsPrintfCString.h"
+ #include "nsProxyRelease.h"
+ #include "nsQueryObject.h"
+ #include "nsSandboxFlags.h"
+-#include "nsScriptError.h"
+ #include "nsUTF8Utils.h"
+ #include "prthread.h"
+ #include "xpcpublic.h"
+ 
+ #ifdef ANDROID
+ #include <android/log.h>
+ #endif
+ 
+@@ -107,16 +103,17 @@
+ #include "Principal.h"
+ #include "RuntimeService.h"
+ #include "ScriptLoader.h"
+ #include "mozilla/dom/ServiceWorkerEvents.h"
+ #include "mozilla/dom/ServiceWorkerManager.h"
+ #include "SharedWorker.h"
+ #include "WorkerDebugger.h"
+ #include "WorkerDebuggerManager.h"
++#include "WorkerError.h"
+ #include "WorkerHolder.h"
+ #include "WorkerNavigator.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "WorkerThread.h"
+ 
+ // JS_MaybeGC will run once every second during normal execution.
+ #define PERIODIC_GC_TIMER_DELAY_SEC 1
+@@ -660,233 +657,16 @@ private:
+   {
+     WorkerPrivate* parent = aWorkerPrivate->GetParent();
+     MOZ_ASSERT_IF(!parent, NS_IsMainThread());
+     Report(parent, mMessage);
+     return true;
+   }
+ };
+ 
+-class ReportErrorRunnable final : public WorkerRunnable
+-{
+-  WorkerErrorReport mReport;
+-
+-public:
+-  // aWorkerPrivate is the worker thread we're on (or the main thread, if null)
+-  // aTarget is the worker object that we are going to fire an error at
+-  // (if any).
+-  static void
+-  ReportError(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
+-              bool aFireAtScope, WorkerPrivate* aTarget,
+-              const WorkerErrorReport& aReport, uint64_t aInnerWindowId,
+-              JS::Handle<JS::Value> aException = JS::NullHandleValue)
+-  {
+-    if (aWorkerPrivate) {
+-      aWorkerPrivate->AssertIsOnWorkerThread();
+-    } else {
+-      AssertIsOnMainThread();
+-    }
+-
+-    // We should not fire error events for warnings but instead make sure that
+-    // they show up in the error console.
+-    if (!JSREPORT_IS_WARNING(aReport.mFlags)) {
+-      // First fire an ErrorEvent at the worker.
+-      RootedDictionary<ErrorEventInit> init(aCx);
+-
+-      if (aReport.mMutedError) {
+-        init.mMessage.AssignLiteral("Script error.");
+-      } else {
+-        init.mMessage = aReport.mMessage;
+-        init.mFilename = aReport.mFilename;
+-        init.mLineno = aReport.mLineNumber;
+-        init.mError = aException;
+-      }
+-
+-      init.mCancelable = true;
+-      init.mBubbles = false;
+-
+-      if (aTarget) {
+-        RefPtr<ErrorEvent> event =
+-          ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
+-        event->SetTrusted(true);
+-
+-        bool defaultActionEnabled;
+-        aTarget->DispatchEvent(event, &defaultActionEnabled);
+-
+-        if (!defaultActionEnabled) {
+-          return;
+-        }
+-      }
+-
+-      // Now fire an event at the global object, but don't do that if the error
+-      // code is too much recursion and this is the same script threw the error.
+-      // XXXbz the interaction of this with worker errors seems kinda broken.
+-      // An overrecursion in the debugger or debugger sandbox will get turned
+-      // into an error event on our parent worker!
+-      // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks making this
+-      // better.
+-      if (aFireAtScope &&
+-          (aTarget || aReport.mErrorNumber != JSMSG_OVER_RECURSED)) {
+-        JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
+-        NS_ASSERTION(global, "This should never be null!");
+-
+-        nsEventStatus status = nsEventStatus_eIgnore;
+-        nsIScriptGlobalObject* sgo;
+-
+-        if (aWorkerPrivate) {
+-          WorkerGlobalScope* globalScope = nullptr;
+-          UNWRAP_OBJECT(WorkerGlobalScope, &global, globalScope);
+-
+-          if (!globalScope) {
+-            WorkerDebuggerGlobalScope* globalScope = nullptr;
+-            UNWRAP_OBJECT(WorkerDebuggerGlobalScope, &global, globalScope);
+-
+-            MOZ_ASSERT_IF(globalScope, globalScope->GetWrapperPreserveColor() == global);
+-            if (globalScope || IsDebuggerSandbox(global)) {
+-              aWorkerPrivate->ReportErrorToDebugger(aReport.mFilename, aReport.mLineNumber,
+-                                                    aReport.mMessage);
+-              return;
+-            }
+-
+-            MOZ_ASSERT(SimpleGlobalObject::SimpleGlobalType(global) ==
+-                         SimpleGlobalObject::GlobalType::BindingDetail);
+-            // XXXbz We should really log this to console, but unwinding out of
+-            // this stuff without ending up firing any events is ... hard.  Just
+-            // return for now.
+-            // https://bugzilla.mozilla.org/show_bug.cgi?id=1271441 tracks
+-            // making this better.
+-            return;
+-          }
+-
+-          MOZ_ASSERT(globalScope->GetWrapperPreserveColor() == global);
+-          nsIDOMEventTarget* target = static_cast<nsIDOMEventTarget*>(globalScope);
+-
+-          RefPtr<ErrorEvent> event =
+-            ErrorEvent::Constructor(aTarget, NS_LITERAL_STRING("error"), init);
+-          event->SetTrusted(true);
+-
+-          if (NS_FAILED(EventDispatcher::DispatchDOMEvent(target, nullptr,
+-                                                          event, nullptr,
+-                                                          &status))) {
+-            NS_WARNING("Failed to dispatch worker thread error event!");
+-            status = nsEventStatus_eIgnore;
+-          }
+-        }
+-        else if ((sgo = nsJSUtils::GetStaticScriptGlobal(global))) {
+-          MOZ_ASSERT(NS_IsMainThread());
+-
+-          if (NS_FAILED(sgo->HandleScriptError(init, &status))) {
+-            NS_WARNING("Failed to dispatch main thread error event!");
+-            status = nsEventStatus_eIgnore;
+-          }
+-        }
+-
+-        // Was preventDefault() called?
+-        if (status == nsEventStatus_eConsumeNoDefault) {
+-          return;
+-        }
+-      }
+-    }
+-
+-    // Now fire a runnable to do the same on the parent's thread if we can.
+-    if (aWorkerPrivate) {
+-      RefPtr<ReportErrorRunnable> runnable =
+-        new ReportErrorRunnable(aWorkerPrivate, aReport);
+-      runnable->Dispatch();
+-      return;
+-    }
+-
+-    // Otherwise log an error to the error console.
+-    LogErrorToConsole(aReport, aInnerWindowId);
+-  }
+-
+-private:
+-  ReportErrorRunnable(WorkerPrivate* aWorkerPrivate,
+-                      const WorkerErrorReport& aReport)
+-  : WorkerRunnable(aWorkerPrivate, ParentThreadUnchangedBusyCount),
+-    mReport(aReport)
+-  { }
+-
+-  virtual void
+-  PostDispatch(WorkerPrivate* aWorkerPrivate, bool aDispatchResult) override
+-  {
+-    aWorkerPrivate->AssertIsOnWorkerThread();
+-
+-    // Dispatch may fail if the worker was canceled, no need to report that as
+-    // an error, so don't call base class PostDispatch.
+-  }
+-
+-  virtual bool
+-  WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
+-  {
+-    JS::Rooted<JSObject*> target(aCx, aWorkerPrivate->GetWrapper());
+-
+-    uint64_t innerWindowId;
+-    bool fireAtScope = true;
+-
+-    bool workerIsAcceptingEvents = aWorkerPrivate->IsAcceptingEvents();
+-
+-    WorkerPrivate* parent = aWorkerPrivate->GetParent();
+-    if (parent) {
+-      innerWindowId = 0;
+-    }
+-    else {
+-      AssertIsOnMainThread();
+-
+-      if (aWorkerPrivate->IsFrozen() ||
+-          aWorkerPrivate->IsParentWindowPaused()) {
+-        MOZ_ASSERT(!IsDebuggerRunnable());
+-        aWorkerPrivate->QueueRunnable(this);
+-        return true;
+-      }
+-
+-      if (aWorkerPrivate->IsSharedWorker()) {
+-        aWorkerPrivate->BroadcastErrorToSharedWorkers(aCx, &mReport,
+-                                                      /* isErrorEvent */ true);
+-        return true;
+-      }
+-
+-      // Service workers do not have a main thread parent global, so normal
+-      // worker error reporting will crash.  Instead, pass the error to
+-      // the ServiceWorkerManager to report on any controlled documents.
+-      if (aWorkerPrivate->IsServiceWorker()) {
+-        RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+-        if (swm) {
+-          swm->HandleError(aCx, aWorkerPrivate->GetPrincipal(),
+-                           aWorkerPrivate->ServiceWorkerScope(),
+-                           aWorkerPrivate->ScriptURL(),
+-                           mReport.mMessage,
+-                           mReport.mFilename, mReport.mLine, mReport.mLineNumber,
+-                           mReport.mColumnNumber, mReport.mFlags,
+-                           mReport.mExnType);
+-        }
+-        return true;
+-      }
+-
+-      // The innerWindowId is only required if we are going to ReportError
+-      // below, which is gated on this condition. The inner window correctness
+-      // check is only going to succeed when the worker is accepting events.
+-      if (workerIsAcceptingEvents) {
+-        aWorkerPrivate->AssertInnerWindowIsCorrect();
+-        innerWindowId = aWorkerPrivate->WindowID();
+-      }
+-    }
+-
+-    // Don't fire this event if the JS object has been disconnected from the
+-    // private object.
+-    if (!workerIsAcceptingEvents) {
+-      return true;
+-    }
+-
+-    ReportError(aCx, parent, fireAtScope, aWorkerPrivate, mReport,
+-                innerWindowId);
+-    return true;
+-  }
+-};
+-
+ class TimerRunnable final : public WorkerRunnable,
+                             public nsITimerCallback,
+                             public nsINamed
+ {
+ public:
+   NS_DECL_ISUPPORTS_INHERITED
+ 
+   explicit TimerRunnable(WorkerPrivate* aWorkerPrivate)
+@@ -5270,57 +5050,16 @@ WorkerPrivate::NotifyInternal(JSContext*
+              aStatus == Canceling ||
+              aStatus == Killing);
+ 
+   // Always abort the script.
+   return false;
+ }
+ 
+ void
+-WorkerErrorBase::AssignErrorBase(JSErrorBase* aReport)
+-{
+-  mFilename = NS_ConvertUTF8toUTF16(aReport->filename);
+-  mLineNumber = aReport->lineno;
+-  mColumnNumber = aReport->column;
+-  mErrorNumber = aReport->errorNumber;
+-}
+-
+-void
+-WorkerErrorNote::AssignErrorNote(JSErrorNotes::Note* aNote)
+-{
+-  WorkerErrorBase::AssignErrorBase(aNote);
+-  xpc::ErrorNote::ErrorNoteToMessageString(aNote, mMessage);
+-}
+-
+-void
+-WorkerErrorReport::AssignErrorReport(JSErrorReport* aReport)
+-{
+-  WorkerErrorBase::AssignErrorBase(aReport);
+-  xpc::ErrorReport::ErrorReportToMessageString(aReport, mMessage);
+-
+-  mLine.Assign(aReport->linebuf(), aReport->linebufLength());
+-  mFlags = aReport->flags;
+-  MOZ_ASSERT(aReport->exnType >= JSEXN_FIRST && aReport->exnType < JSEXN_LIMIT);
+-  mExnType = JSExnType(aReport->exnType);
+-  mMutedError = aReport->isMuted;
+-
+-  if (aReport->notes) {
+-    if (!mNotes.SetLength(aReport->notes->length(), fallible)) {
+-      return;
+-    }
+-
+-    size_t i = 0;
+-    for (auto&& note : *aReport->notes) {
+-      mNotes.ElementAt(i).AssignErrorNote(note.get());
+-      i++;
+-    }
+-  }
+-}
+-
+-void
+ WorkerPrivate::ReportError(JSContext* aCx, JS::ConstUTF8CharsZ aToStringResult,
+                            JSErrorReport* aReport)
+ {
+   AssertIsOnWorkerThread();
+ 
+   if (!MayContinueRunning() || mErrorHandlerRecursionCount == 2) {
+     return;
+   }
+@@ -5364,18 +5103,17 @@ WorkerPrivate::ReportError(JSContext* aC
+   mErrorHandlerRecursionCount++;
+ 
+   // Don't want to run the scope's error handler if this is a recursive error or
+   // if we ran out of memory.
+   bool fireAtScope = mErrorHandlerRecursionCount == 1 &&
+                      report.mErrorNumber != JSMSG_OUT_OF_MEMORY &&
+                      JS::CurrentGlobalOrNull(aCx);
+ 
+-  ReportErrorRunnable::ReportError(aCx, this, fireAtScope, nullptr, report, 0,
+-                                   exn);
++  workers::ReportError(aCx, this, fireAtScope, nullptr, report, 0, exn);
+ 
+   mErrorHandlerRecursionCount--;
+ }
+ 
+ // static
+ void
+ WorkerPrivate::ReportErrorToConsole(const char* aMessage)
+ {
+@@ -6175,77 +5913,14 @@ EventTarget::IsOnCurrentThreadInfallible
+   if (!mWorkerPrivate) {
+     NS_WARNING("A worker's event target was used after the worker has !");
+     return false;
+   }
+ 
+   return mWorkerPrivate->IsOnCurrentThread();
+ }
+ 
+-void
+-LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId)
+-{
+-  AssertIsOnMainThread();
+-
+-  RefPtr<nsScriptErrorBase> scriptError = new nsScriptError();
+-  NS_WARNING_ASSERTION(scriptError, "Failed to create script error!");
+-
+-  if (scriptError) {
+-    nsAutoCString category("Web Worker");
+-    if (NS_FAILED(scriptError->InitWithWindowID(aReport.mMessage,
+-                                                aReport.mFilename,
+-                                                aReport.mLine,
+-                                                aReport.mLineNumber,
+-                                                aReport.mColumnNumber,
+-                                                aReport.mFlags,
+-                                                category,
+-                                                aInnerWindowId))) {
+-      NS_WARNING("Failed to init script error!");
+-      scriptError = nullptr;
+-    }
+-
+-    for (size_t i = 0, len = aReport.mNotes.Length(); i < len; i++) {
+-      const WorkerErrorNote& note = aReport.mNotes.ElementAt(i);
+-
+-      nsScriptErrorNote* noteObject = new nsScriptErrorNote();
+-      noteObject->Init(note.mMessage, note.mFilename,
+-                       note.mLineNumber, note.mColumnNumber);
+-      scriptError->AddNote(noteObject);
+-    }
+-  }
+-
+-  nsCOMPtr<nsIConsoleService> consoleService =
+-    do_GetService(NS_CONSOLESERVICE_CONTRACTID);
+-  NS_WARNING_ASSERTION(consoleService, "Failed to get console service!");
+-
+-  if (consoleService) {
+-    if (scriptError) {
+-      if (NS_SUCCEEDED(consoleService->LogMessage(scriptError))) {
+-        return;
+-      }
+-      NS_WARNING("LogMessage failed!");
+-    } else if (NS_SUCCEEDED(consoleService->LogStringMessage(
+-                              aReport.mMessage.BeginReading()))) {
+-      return;
+-    }
+-    NS_WARNING("LogStringMessage failed!");
+-  }
+-
+-  NS_ConvertUTF16toUTF8 msg(aReport.mMessage);
+-  NS_ConvertUTF16toUTF8 filename(aReport.mFilename);
+-
+-  static const char kErrorString[] = "JS error in Web Worker: %s [%s:%u]";
+-
+-#ifdef ANDROID
+-  __android_log_print(ANDROID_LOG_INFO, "Gecko", kErrorString, msg.get(),
+-                      filename.get(), aReport.mLineNumber);
+-#endif
+-
+-  fprintf(stderr, kErrorString, msg.get(), filename.get(), aReport.mLineNumber);
+-  fflush(stderr);
+-}
+-
+ BEGIN_WORKERS_NAMESPACE
+ 
+ // Force instantiation.
+ template class WorkerPrivateParent<WorkerPrivate>;
+ 
+ END_WORKERS_NAMESPACE
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
+--- a/dom/workers/WorkerPrivate.h
++++ b/dom/workers/WorkerPrivate.h
+@@ -67,16 +67,17 @@ class ClientInfo;
+ class ClientSource;
+ class Function;
+ class MessagePort;
+ class MessagePortIdentifier;
+ class PerformanceStorage;
+ class PromiseNativeHandler;
+ class StructuredCloneHolder;
+ class WorkerDebuggerGlobalScope;
++class WorkerErrorReport;
+ class WorkerGlobalScope;
+ struct WorkerOptions;
+ } // namespace dom
+ namespace ipc {
+ class PrincipalInfo;
+ } // namespace ipc
+ } // namespace mozilla
+ 
+@@ -138,55 +139,16 @@ public:
+ 
+   void
+   AssertCurrentThreadOwns() const
+   {
+     mMutex->AssertCurrentThreadOwns();
+   }
+ };
+ 
+-class WorkerErrorBase {
+-public:
+-  nsString mMessage;
+-  nsString mFilename;
+-  uint32_t mLineNumber;
+-  uint32_t mColumnNumber;
+-  uint32_t mErrorNumber;
+-
+-  WorkerErrorBase()
+-  : mLineNumber(0),
+-    mColumnNumber(0),
+-    mErrorNumber(0)
+-  { }
+-
+-  void AssignErrorBase(JSErrorBase* aReport);
+-};
+-
+-class WorkerErrorNote : public WorkerErrorBase {
+-public:
+-  void AssignErrorNote(JSErrorNotes::Note* aNote);
+-};
+-
+-class WorkerErrorReport : public WorkerErrorBase {
+-public:
+-  nsString mLine;
+-  uint32_t mFlags;
+-  JSExnType mExnType;
+-  bool mMutedError;
+-  nsTArray<WorkerErrorNote> mNotes;
+-
+-  WorkerErrorReport()
+-  : mFlags(0),
+-    mExnType(JSEXN_ERR),
+-    mMutedError(false)
+-  { }
+-
+-  void AssignErrorReport(JSErrorReport* aReport);
+-};
+-
+ template <class Derived>
+ class WorkerPrivateParent : public DOMEventTargetHelper
+ {
+ protected:
+   class EventTarget;
+   friend class EventTarget;
+ 
+   typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
+@@ -1651,15 +1613,11 @@ public:
+   nsIEventTarget*
+   GetEventTarget() const
+   {
+     // This can be null if CreateNewSyncLoop() fails.
+     return mTarget;
+   }
+ };
+ 
+-// TODO: this will be removed in the next patch
+-void
+-LogErrorToConsole(const WorkerErrorReport& aReport, uint64_t aInnerWindowId);
+-
+ END_WORKERS_NAMESPACE
+ 
+ #endif /* mozilla_dom_workers_workerprivate_h__ */
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -45,16 +45,17 @@ UNIFIED_SOURCES += [
+     'MessageEventRunnable.cpp',
+     'Principal.cpp',
+     'RegisterBindings.cpp',
+     'RuntimeService.cpp',
+     'ScriptLoader.cpp',
+     'SharedWorker.cpp',
+     'WorkerDebugger.cpp',
+     'WorkerDebuggerManager.cpp',
++    'WorkerError.cpp',
+     'WorkerHolder.cpp',
+     'WorkerHolderToken.cpp',
+     'WorkerLoadInfo.cpp',
+     'WorkerLocation.cpp',
+     'WorkerNavigator.cpp',
+     'WorkerPrivate.cpp',
+     'WorkerRunnable.cpp',
+     'WorkerScope.cpp',

+ 111 - 0
mozilla-release/patches/1413112-6-60a1.patch

@@ -0,0 +1,111 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303609 -3600
+# Node ID aed2d290201e0cacee271b3bf9ff783553afc433
+# Parent  95b6ff0abee44eb21be3ad048b92f6941a3fe907
+Bug 1413112 - Move FileReaderSync into dom/file, r=me
+
+diff --git a/dom/workers/FileReaderSync.cpp b/dom/file/FileReaderSync.cpp
+rename from dom/workers/FileReaderSync.cpp
+rename to dom/file/FileReaderSync.cpp
+diff --git a/dom/workers/FileReaderSync.h b/dom/file/FileReaderSync.h
+rename from dom/workers/FileReaderSync.h
+rename to dom/file/FileReaderSync.h
+diff --git a/dom/file/StringBlobImpl.cpp b/dom/file/StringBlobImpl.cpp
+--- a/dom/file/StringBlobImpl.cpp
++++ b/dom/file/StringBlobImpl.cpp
+@@ -1,15 +1,15 @@
+ /* -*- 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 "StreamBlobImpl.h"
++#include "StringBlobImpl.h"
+ #include "nsStringStream.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ NS_IMPL_ISUPPORTS_INHERITED(StringBlobImpl, BlobImpl, nsIMemoryReporter)
+ 
+ /* static */ already_AddRefed<StringBlobImpl>
+diff --git a/dom/file/moz.build b/dom/file/moz.build
+--- a/dom/file/moz.build
++++ b/dom/file/moz.build
+@@ -26,16 +26,17 @@ EXPORTS.mozilla.dom += [
+     'Blob.h',
+     'BlobImpl.h',
+     'BlobSet.h',
+     'File.h',
+     'FileBlobImpl.h',
+     'FileCreatorHelper.h',
+     'FileList.h',
+     'FileReader.h',
++    'FileReaderSync.h',
+     'MemoryBlobImpl.h',
+     'MultipartBlobImpl.h',
+     'MutableBlobStorage.h',
+     'MutableBlobStreamListener.h',
+     'StreamBlobImpl.h',
+ ]
+ 
+ UNIFIED_SOURCES += [
+@@ -44,16 +45,17 @@ UNIFIED_SOURCES += [
+     'BlobImpl.cpp',
+     'BlobSet.cpp',
+     'EmptyBlobImpl.cpp',
+     'File.cpp',
+     'FileBlobImpl.cpp',
+     'FileCreatorHelper.cpp',
+     'FileList.cpp',
+     'FileReader.cpp',
++    'FileReaderSync.cpp',
+     'MemoryBlobImpl.cpp',
+     'MultipartBlobImpl.cpp',
+     'MutableBlobStorage.cpp',
+     'MutableBlobStreamListener.cpp',
+     'nsHostObjectProtocolHandler.cpp',
+     'nsHostObjectURI.cpp',
+     'StreamBlobImpl.cpp',
+     'StringBlobImpl.cpp',
+diff --git a/dom/workers/moz.build b/dom/workers/moz.build
+--- a/dom/workers/moz.build
++++ b/dom/workers/moz.build
+@@ -4,17 +4,16 @@
+ # 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/.
+ 
+ with Files("**"):
+     BUG_COMPONENT = ("Core", "DOM: Workers")
+ 
+ # Public stuff.
+ EXPORTS.mozilla.dom += [
+-    'FileReaderSync.h',
+     'WorkerLocation.h',
+     'WorkerNavigator.h',
+     'WorkerPrivate.h',
+     'WorkerRunnable.h',
+     'WorkerScope.h',
+ ]
+ 
+ EXPORTS.mozilla.dom.workers += [
+@@ -36,17 +35,16 @@ XPIDL_MODULE = 'dom_workers'
+ 
+ XPIDL_SOURCES += [
+     'nsIWorkerDebugger.idl',
+     'nsIWorkerDebuggerManager.idl',
+ ]
+ 
+ UNIFIED_SOURCES += [
+     'ChromeWorkerScope.cpp',
+-    'FileReaderSync.cpp',
+     'MessageEventRunnable.cpp',
+     'Principal.cpp',
+     'RegisterBindings.cpp',
+     'RuntimeService.cpp',
+     'ScriptLoader.cpp',
+     'SharedWorker.cpp',
+     'WorkerDebugger.cpp',
+     'WorkerDebuggerManager.cpp',

+ 556 - 0
mozilla-release/patches/1413112-7-60a1.patch

@@ -0,0 +1,556 @@
+# HG changeset patch
+# User Andrea Marchesini <amarchesini@mozilla.com>
+# Date 1517303640 -3600
+# Node ID 5c5431fce5ba9ba82952557e61fbd4420644fcb1
+# Parent  d29831d0bcef697084e64ccd433420a26cddea77
+Bug 1413112 - Fixing includes in dom/workers, r=bkelly
+
+diff --git a/dom/clients/manager/ClientManager.cpp b/dom/clients/manager/ClientManager.cpp
+--- a/dom/clients/manager/ClientManager.cpp
++++ b/dom/clients/manager/ClientManager.cpp
+@@ -10,16 +10,17 @@
+ #include "ClientManagerChild.h"
+ #include "ClientManagerOpChild.h"
+ #include "ClientPrefs.h"
+ #include "ClientSource.h"
+ #include "mozilla/dom/WorkerPrivate.h"
+ #include "mozilla/dom/workers/bindings/WorkerHolderToken.h"
+ #include "mozilla/ipc/BackgroundChild.h"
+ #include "mozilla/ipc/PBackgroundChild.h"
++#include "nsContentUtils.h"
+ #include "prthread.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ using mozilla::ipc::BackgroundChild;
+ using mozilla::ipc::PBackgroundChild;
+ using mozilla::ipc::PrincipalInfo;
+diff --git a/dom/file/FileReaderSync.cpp b/dom/file/FileReaderSync.cpp
+--- a/dom/file/FileReaderSync.cpp
++++ b/dom/file/FileReaderSync.cpp
+@@ -28,16 +28,17 @@
+ #include "nsIAsyncInputStream.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ 
+ #include "RuntimeService.h"
+ 
+ using namespace mozilla;
+ using namespace mozilla::dom;
++using namespace mozilla::dom::workers;
+ using mozilla::dom::Optional;
+ using mozilla::dom::GlobalObject;
+ 
+ // static
+ already_AddRefed<FileReaderSync>
+ FileReaderSync::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
+ {
+   RefPtr<FileReaderSync> frs = new FileReaderSync();
+diff --git a/dom/serviceworkers/ServiceWorkerInfo.h b/dom/serviceworkers/ServiceWorkerInfo.h
+--- a/dom/serviceworkers/ServiceWorkerInfo.h
++++ b/dom/serviceworkers/ServiceWorkerInfo.h
+@@ -5,16 +5,17 @@
+  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ 
+ #ifndef mozilla_dom_serviceworkerinfo_h
+ #define mozilla_dom_serviceworkerinfo_h
+ 
+ #include "MainThreadUtils.h"
+ #include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState
+ #include "mozilla/dom/workers/WorkerCommon.h"
++#include "mozilla/OriginAttributes.h"
+ #include "nsIServiceWorkerManager.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ class ServiceWorker;
+ class ServiceWorkerPrivate;
+ 
+diff --git a/dom/workers/MessageEventRunnable.h b/dom/workers/MessageEventRunnable.h
+--- a/dom/workers/MessageEventRunnable.h
++++ b/dom/workers/MessageEventRunnable.h
+@@ -6,17 +6,22 @@
+ 
+ #ifndef mozilla_dom_workers_MessageEventRunnable_h
+ #define mozilla_dom_workers_MessageEventRunnable_h
+ 
+ #include "WorkerCommon.h"
+ #include "WorkerRunnable.h"
+ #include "mozilla/dom/StructuredCloneHolder.h"
+ 
+-BEGIN_WORKERS_NAMESPACE
++namespace mozilla {
++
++class DOMEventTargetHelper;
++
++namespace dom {
++namespace workers {
+ 
+ class MessageEventRunnable final : public WorkerRunnable
+                                  , public StructuredCloneHolder
+ {
+ public:
+   MessageEventRunnable(WorkerPrivate* aWorkerPrivate,
+                        TargetAndBusyBehavior aBehavior);
+ 
+@@ -27,11 +32,13 @@ public:
+ private:
+   bool
+   WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override;
+ 
+   void
+   DispatchError(JSContext* aCx, DOMEventTargetHelper* aTarget);
+ };
+ 
+-END_WORKERS_NAMESPACE
++} // workers namespace
++} // dom namespace
++} // mozilla namespace
+ 
+ #endif // mozilla_dom_workers_MessageEventRunnable_h
+diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp
+--- a/dom/workers/RuntimeService.cpp
++++ b/dom/workers/RuntimeService.cpp
+@@ -71,16 +71,18 @@
+ #include "WorkerDebuggerManager.h"
+ #include "WorkerLoadInfo.h"
+ #include "WorkerPrivate.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "WorkerThread.h"
+ #include "prsystem.h"
+ 
++#define WORKERS_SHUTDOWN_TOPIC "web-workers-shutdown"
++
+ using namespace mozilla;
+ using namespace mozilla::dom;
+ using namespace mozilla::ipc;
+ 
+ USING_WORKERS_NAMESPACE
+ 
+ using mozilla::MutexAutoLock;
+ using mozilla::MutexAutoUnlock;
+diff --git a/dom/workers/SharedWorker.cpp b/dom/workers/SharedWorker.cpp
+--- a/dom/workers/SharedWorker.cpp
++++ b/dom/workers/SharedWorker.cpp
+@@ -16,16 +16,20 @@
+ #include "mozilla/Telemetry.h"
+ #include "nsContentUtils.h"
+ #include "nsIClassInfoImpl.h"
+ #include "nsIDOMEvent.h"
+ 
+ #include "RuntimeService.h"
+ #include "WorkerPrivate.h"
+ 
++#ifdef XP_WIN
++#undef PostMessage
++#endif
++
+ using mozilla::dom::Optional;
+ using mozilla::dom::Sequence;
+ using mozilla::dom::MessagePort;
+ using namespace mozilla;
+ 
+ USING_WORKERS_NAMESPACE
+ 
+ SharedWorker::SharedWorker(nsPIDOMWindowInner* aWindow,
+diff --git a/dom/workers/SharedWorker.h b/dom/workers/SharedWorker.h
+--- a/dom/workers/SharedWorker.h
++++ b/dom/workers/SharedWorker.h
+@@ -7,16 +7,20 @@
+ #ifndef mozilla_dom_workers_sharedworker_h__
+ #define mozilla_dom_workers_sharedworker_h__
+ 
+ #include "WorkerCommon.h"
+ 
+ #include "mozilla/dom/BindingDeclarations.h"
+ #include "mozilla/DOMEventTargetHelper.h"
+ 
++#ifdef XP_WIN
++#undef PostMessage
++#endif
++
+ class nsIDOMEvent;
+ class nsPIDOMWindowInner;
+ 
+ namespace mozilla {
+ class EventChainPreVisitor;
+ 
+ namespace dom {
+ class MessagePort;
+diff --git a/dom/workers/WorkerCommon.h b/dom/workers/WorkerCommon.h
+--- a/dom/workers/WorkerCommon.h
++++ b/dom/workers/WorkerCommon.h
+@@ -6,38 +6,30 @@
+ 
+ #ifndef mozilla_dom_workers_WorkerCommon_h
+ #define mozilla_dom_workers_WorkerCommon_h
+ 
+ #include "jsapi.h"
+ #include "mozilla/Attributes.h"
+ #include "mozilla/Maybe.h"
+ #include "mozilla/Mutex.h"
+-#include <stdint.h>
+ #include "nsAutoPtr.h"
+ #include "nsCOMPtr.h"
+-#include "nsDebug.h"
+ #include "nsString.h"
+ #include "nsTArray.h"
+ 
+-#include "nsILoadContext.h"
+-#include "nsIWeakReferenceUtils.h"
+-#include "mozilla/dom/ChannelInfo.h"
+ #include "mozilla/dom/ServiceWorkerDescriptor.h"
+-#include "mozilla/net/ReferrerPolicy.h"
+ 
+ #define BEGIN_WORKERS_NAMESPACE \
+   namespace mozilla { namespace dom { namespace workers {
+ #define END_WORKERS_NAMESPACE \
+   } /* namespace workers */ } /* namespace dom */ } /* namespace mozilla */
+ #define USING_WORKERS_NAMESPACE \
+   using namespace mozilla::dom::workers;
+ 
+-#define WORKERS_SHUTDOWN_TOPIC "web-workers-shutdown"
+-
+ class nsIGlobalObject;
+ class nsPIDOMWindowInner;
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+ // If you change this, the corresponding list in nsIWorkerDebugger.idl needs to
+ // be updated too.
+diff --git a/dom/workers/WorkerLoadInfo.h b/dom/workers/WorkerLoadInfo.h
+--- a/dom/workers/WorkerLoadInfo.h
++++ b/dom/workers/WorkerLoadInfo.h
+@@ -2,19 +2,24 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_WorkerLoadInfo_h
+ #define mozilla_dom_workers_WorkerLoadInfo_h
+ 
++#include "mozilla/dom/ChannelInfo.h"
+ #include "mozilla/dom/workers/WorkerCommon.h"
++#include "mozilla/net/ReferrerPolicy.h"
+ #include "nsIInterfaceRequestor.h"
++#include "nsILoadContext.h"
++#include "nsIRequest.h"
+ #include "nsISupportsImpl.h"
++#include "nsIWeakReferenceUtils.h"
+ 
+ class nsIChannel;
+ class nsIContentSecurityPolicy;
+ class nsILoadGroup;
+ class nsIPrincipal;
+ class nsIRunnable;
+ class nsIScriptContext;
+ class nsITabChild;
+diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
+--- a/dom/workers/WorkerPrivate.cpp
++++ b/dom/workers/WorkerPrivate.cpp
+@@ -2,124 +2,74 @@
+ /* 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 "WorkerPrivate.h"
+ 
+ #include "amIAddonManager.h"
+-#include "nsIClassInfo.h"
+-#include "nsIContentSecurityPolicy.h"
+-#include "nsIConsoleService.h"
+-#include "nsIDOMDOMException.h"
+-#include "nsIDOMEvent.h"
+-#include "nsIDocument.h"
+-#include "nsIDocShell.h"
+-#include "nsIInterfaceRequestor.h"
+-#include "nsIMemoryReporter.h"
+-#include "nsINamed.h"
+-#include "nsIPermissionManager.h"
+-#include "nsIScriptError.h"
+-#include "nsIScriptGlobalObject.h"
+-#include "nsIScriptSecurityManager.h"
+-#include "nsIScriptTimeoutHandler.h"
+-#include "nsITextToSubURI.h"
+-#include "nsIThreadInternal.h"
+-#include "nsITimer.h"
+-#include "nsIURI.h"
+-#include "nsIURL.h"
+-#include "nsIWeakReferenceUtils.h"
+-#include "nsIXPConnect.h"
+-#include "nsPIDOMWindow.h"
+-#include "nsGlobalWindow.h"
+-
+-#include <algorithm>
+-#include "ImageContainer.h"
+-#include "jsfriendapi.h"
+ #include "js/MemoryMetrics.h"
+ #include "MessageEventRunnable.h"
+-#include "mozilla/Assertions.h"
+-#include "mozilla/Attributes.h"
+-#include "mozilla/ContentEvents.h"
+-#include "mozilla/EventDispatcher.h"
+-#include "mozilla/Likely.h"
+-#include "mozilla/Move.h"
+-#include "mozilla/dom/BindingUtils.h"
+ #include "mozilla/dom/ClientManager.h"
+ #include "mozilla/dom/ClientSource.h"
+ #include "mozilla/dom/ClientState.h"
+ #include "mozilla/dom/Console.h"
+-#include "mozilla/dom/DocGroup.h"
++#include "mozilla/dom/DOMTypes.h"
+ #include "mozilla/dom/ErrorEvent.h"
+ #include "mozilla/dom/ErrorEventBinding.h"
+-#include "mozilla/dom/Exceptions.h"
+-#include "mozilla/dom/ExtendableMessageEventBinding.h"
++#include "mozilla/dom/Event.h"
+ #include "mozilla/dom/FunctionBinding.h"
+ #include "mozilla/dom/IndexedDatabaseManager.h"
+ #include "mozilla/dom/MessageEvent.h"
+ #include "mozilla/dom/MessageEventBinding.h"
+ #include "mozilla/dom/MessagePort.h"
+ #include "mozilla/dom/MessagePortBinding.h"
+ #include "mozilla/dom/nsCSPUtils.h"
+ #include "mozilla/dom/Performance.h"
+ #include "mozilla/dom/PerformanceStorageWorker.h"
+-#include "mozilla/dom/PMessagePort.h"
+-#include "mozilla/dom/Promise.h"
+ #include "mozilla/dom/PromiseDebugging.h"
+-#include "mozilla/dom/PromiseNativeHandler.h"
+-#include "mozilla/dom/ScriptSettings.h"
+-#include "mozilla/dom/StructuredCloneHolder.h"
+-#include "mozilla/dom/WorkerBinding.h"
+-#include "mozilla/Preferences.h"
+ #include "mozilla/ThreadEventQueue.h"
+ #include "mozilla/ThrottledEventQueue.h"
+ #include "mozilla/TimelineConsumers.h"
+ #include "mozilla/WorkerTimelineMarker.h"
+-#include "nsAlgorithm.h"
+-#include "nsContentUtils.h"
+ #include "nsCycleCollector.h"
+-#include "nsError.h"
+-#include "nsDOMJSUtils.h"
+-#include "nsHostObjectProtocolHandler.h"
+-#include "nsJSEnvironment.h"
+-#include "nsJSUtils.h"
+ #include "nsNetUtil.h"
++#include "nsIMemoryReporter.h"
++#include "nsIPermissionManager.h"
++#include "nsIScriptError.h"
++#include "nsIScriptTimeoutHandler.h"
++#include "nsIURI.h"
++#include "nsIURL.h"
+ #include "nsPrintfCString.h"
+-#include "nsProxyRelease.h"
+ #include "nsQueryObject.h"
+ #include "nsSandboxFlags.h"
+ #include "nsUTF8Utils.h"
+-#include "prthread.h"
+-#include "xpcpublic.h"
+-
+-#ifdef ANDROID
+-#include <android/log.h>
+-#endif
+-
+-#ifdef DEBUG
+-#include "nsThreadManager.h"
+-#endif
+-
+-#include "Navigator.h"
+-#include "Principal.h"
++
+ #include "RuntimeService.h"
+ #include "ScriptLoader.h"
+ #include "mozilla/dom/ServiceWorkerEvents.h"
+ #include "mozilla/dom/ServiceWorkerManager.h"
+ #include "SharedWorker.h"
+ #include "WorkerDebugger.h"
+ #include "WorkerDebuggerManager.h"
+ #include "WorkerError.h"
+-#include "WorkerHolder.h"
+ #include "WorkerNavigator.h"
+ #include "WorkerRunnable.h"
+ #include "WorkerScope.h"
+ #include "WorkerThread.h"
+ 
++#ifdef DEBUG
++#include "nsThreadManager.h"
++#endif
++
++#ifdef XP_WIN
++#undef PostMessage
++#endif
++
+ // JS_MaybeGC will run once every second during normal execution.
+ #define PERIODIC_GC_TIMER_DELAY_SEC 1
+ 
+ // A shrinking GC will run five seconds after the last event is processed.
+ #define IDLE_GC_TIMER_DELAY_SEC 5
+ 
+ #define PREF_WORKERS_ENABLED "dom.workers.enabled"
+ 
+diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
+--- a/dom/workers/WorkerPrivate.h
++++ b/dom/workers/WorkerPrivate.h
+@@ -3,100 +3,58 @@
+ /* 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/. */
+ 
+ #ifndef mozilla_dom_workers_workerprivate_h__
+ #define mozilla_dom_workers_workerprivate_h__
+ 
+ #include "WorkerCommon.h"
+-#include "WorkerLoadInfo.h"
+-
+-#include "js/CharacterEncoding.h"
+-#include "nsIContentPolicy.h"
++#include "mozilla/CondVar.h"
++#include "mozilla/DOMEventTargetHelper.h"
++#include "nsDOMNavigationTiming.h"
+ #include "nsIContentSecurityPolicy.h"
+-#include "nsILoadGroup.h"
+-#include "nsPIDOMWindow.h"
+-
+-#include "mozilla/Assertions.h"
+-#include "mozilla/Attributes.h"
+-#include "mozilla/CondVar.h"
+-#include "mozilla/ConsoleReportCollector.h"
+-#include "mozilla/DOMEventTargetHelper.h"
+-#include "mozilla/Move.h"
+-#include "mozilla/TimeStamp.h"
+-#include "mozilla/dom/BindingDeclarations.h"
+-#include "nsAutoPtr.h"
+-#include "nsCycleCollectionParticipant.h"
+-#include "nsDataHashtable.h"
+-#include "nsHashKeys.h"
+-#include "nsRefPtrHashtable.h"
+-#include "nsString.h"
+-#include "nsTArray.h"
++#include "nsIEventTarget.h"
+ #include "nsThreadUtils.h"
+ #include "nsTObserverArray.h"
+ 
+ #include "Queue.h"
+ #include "WorkerHolder.h"
++#include "WorkerLoadInfo.h"
+ 
+ #ifdef XP_WIN
+ #undef PostMessage
+ #endif
+ 
+-class nsIChannel;
+ class nsIConsoleReportCollector;
+-class nsIDocument;
+-class nsIEventTarget;
+-class nsIPrincipal;
+-class nsIScriptContext;
+-class nsIScriptTimeoutHandler;
+-class nsISerialEventTarget;
+-class nsISerializable;
+-class nsIThread;
+ class nsIThreadInternal;
+-class nsITimer;
+-class nsIURI;
+-template<class T> class nsMainThreadPtrHandle;
+-
+-namespace JS {
+-struct RuntimeStats;
+-} // namespace JS
+ 
+ namespace mozilla {
+-class ThrottledEventQueue;
+ namespace dom {
++
+ class ClientInfo;
+ class ClientSource;
+ class Function;
+ class MessagePort;
+ class MessagePortIdentifier;
+ class PerformanceStorage;
+-class PromiseNativeHandler;
+-class StructuredCloneHolder;
+ class WorkerDebuggerGlobalScope;
+ class WorkerErrorReport;
+ class WorkerGlobalScope;
+ struct WorkerOptions;
+-} // namespace dom
+-namespace ipc {
+-class PrincipalInfo;
+-} // namespace ipc
+-} // namespace mozilla
+ 
+-struct PRThread;
++} // dom namespace
++} // mozilla namespace
+ 
+ BEGIN_WORKERS_NAMESPACE
+ 
+-class AutoSyncLoopHolder;
+ class SharedWorker;
+-class ServiceWorkerClientInfo;
+-class WorkerEventTarget;
+ class WorkerControlRunnable;
+ class WorkerDebugger;
+-class WorkerPrivate;
++class WorkerEventTarget;
+ class WorkerRunnable;
+ class WorkerThread;
+ 
+ // SharedMutex is a small wrapper around an (internal) reference-counted Mutex
+ // object. It exists to avoid changing a lot of code to use Mutex* instead of
+ // Mutex&.
+ class SharedMutex
+ {
+diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp
+--- a/dom/workers/WorkerRunnable.cpp
++++ b/dom/workers/WorkerRunnable.cpp
+@@ -565,17 +565,17 @@ WorkerMainThreadRunnable::WorkerMainThre
+   : mozilla::Runnable("dom::workers::WorkerMainThreadRunnable")
+   , mWorkerPrivate(aWorkerPrivate)
+   , mTelemetryKey(aTelemetryKey)
+ {
+   mWorkerPrivate->AssertIsOnWorkerThread();
+ }
+ 
+ void
+-WorkerMainThreadRunnable::Dispatch(Status aFailStatus, ErrorResult& aRv)
++WorkerMainThreadRunnable::Dispatch(Status aFailStatus, mozilla::ErrorResult& aRv)
+ {
+   mWorkerPrivate->AssertIsOnWorkerThread();
+ 
+   TimeStamp startTime = TimeStamp::NowLoRes();
+ 
+   AutoSyncLoopHolder syncLoop(mWorkerPrivate, aFailStatus);
+ 
+   mSyncLoopTarget = syncLoop.GetEventTarget();
+diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
+--- a/dom/workers/WorkerScope.h
++++ b/dom/workers/WorkerScope.h
+@@ -9,16 +9,20 @@
+ 
+ #include "WorkerCommon.h"
+ #include "mozilla/DOMEventTargetHelper.h"
+ #include "mozilla/dom/Headers.h"
+ #include "mozilla/dom/RequestBinding.h"
+ #include "nsWeakReference.h"
+ #include "mozilla/dom/ImageBitmapSource.h"
+ 
++#ifdef XP_WIN
++#undef PostMessage
++#endif
++
+ namespace mozilla {
+ namespace dom {
+ 
+ class AnyCallback;
+ struct ChannelPixelLayout;
+ class ClientInfo;
+ class Clients;
+ class ClientState;

+ 128 - 0
mozilla-release/patches/1433568-60a1.patch

@@ -0,0 +1,128 @@
+# HG changeset patch
+# User Ben Kelly <ben@wanderview.com>
+# Date 1517241164 28800
+# Node ID 873831981ed89de7b81ccdacba966d206cc3b701
+# Parent  acfb6100186b4a5ce544f6b34a00ea38bbadffe8
+Bug 1433568 Remove the empty ServiceWorkerDescriptor() constructor. r=asuth
+
+diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.cpp b/dom/serviceworkers/ServiceWorkerDescriptor.cpp
+--- a/dom/serviceworkers/ServiceWorkerDescriptor.cpp
++++ b/dom/serviceworkers/ServiceWorkerDescriptor.cpp
+@@ -7,19 +7,28 @@
+ #include "ServiceWorkerDescriptor.h"
+ #include "mozilla/dom/IPCServiceWorkerDescriptor.h"
+ #include "mozilla/dom/ServiceWorkerBinding.h"
+ #include "mozilla/ipc/PBackgroundSharedTypes.h"
+ 
+ namespace mozilla {
+ namespace dom {
+ 
+-ServiceWorkerDescriptor::ServiceWorkerDescriptor()
++ServiceWorkerDescriptor::ServiceWorkerDescriptor(uint64_t aId,
++                                                 nsIPrincipal* aPrincipal,
++                                                 const nsACString& aScope,
++                                                 ServiceWorkerState aState)
+   : mData(MakeUnique<IPCServiceWorkerDescriptor>())
+ {
++  MOZ_ALWAYS_SUCCEEDS(
++    PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo()));
++
++  mData->id() = aId;
++  mData->scope() = aScope;
++  mData->state() = aState;
+ }
+ 
+ ServiceWorkerDescriptor::ServiceWorkerDescriptor(uint64_t aId,
+                                                  const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
+                                                  const nsACString& aScope,
+                                                  ServiceWorkerState aState)
+   : mData(MakeUnique<IPCServiceWorkerDescriptor>(aId, aPrincipalInfo,
+                                                  nsCString(aScope), aState))
+diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.h b/dom/serviceworkers/ServiceWorkerDescriptor.h
+--- a/dom/serviceworkers/ServiceWorkerDescriptor.h
++++ b/dom/serviceworkers/ServiceWorkerDescriptor.h
+@@ -1,16 +1,18 @@
+ /* -*- 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/. */
+ #ifndef _mozilla_dom_ServiceWorkerDescriptor_h
+ #define _mozilla_dom_ServiceWorkerDescriptor_h
+ 
++class nsIPrincipal;
++
+ namespace mozilla {
+ 
+ namespace ipc {
+ class PrincipalInfo;
+ } // namespace ipc
+ 
+ namespace dom {
+ 
+@@ -24,17 +26,20 @@ enum class ServiceWorkerState : uint8_t;
+ class ServiceWorkerDescriptor final
+ {
+   // This class is largely a wrapper wround an IPDL generated struct.  We
+   // need the wrapper class since IPDL generated code includes windows.h
+   // which is in turn incompatible with bindings code.
+   UniquePtr<IPCServiceWorkerDescriptor> mData;
+ 
+ public:
+-  ServiceWorkerDescriptor();
++  ServiceWorkerDescriptor(uint64_t aId,
++                          nsIPrincipal* aPrincipal,
++                          const nsACString& aScope,
++                          ServiceWorkerState aState);
+ 
+   ServiceWorkerDescriptor(uint64_t aId,
+                           const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
+                           const nsACString& aScope,
+                           ServiceWorkerState aState);
+ 
+   explicit ServiceWorkerDescriptor(const IPCServiceWorkerDescriptor& aDescriptor);
+ 
+diff --git a/dom/serviceworkers/ServiceWorkerInfo.cpp b/dom/serviceworkers/ServiceWorkerInfo.cpp
+--- a/dom/serviceworkers/ServiceWorkerInfo.cpp
++++ b/dom/serviceworkers/ServiceWorkerInfo.cpp
+@@ -216,16 +216,17 @@ ServiceWorkerInfo::UpdateState(ServiceWo
+ }
+ 
+ ServiceWorkerInfo::ServiceWorkerInfo(nsIPrincipal* aPrincipal,
+                                      const nsACString& aScope,
+                                      const nsACString& aScriptSpec,
+                                      const nsAString& aCacheName,
+                                      nsLoadFlags aImportsLoadFlags)
+   : mPrincipal(aPrincipal)
++  , mDescriptor(GetNextID(), aPrincipal, aScope, ServiceWorkerState::Parsed)
+   , mScriptSpec(aScriptSpec)
+   , mCacheName(aCacheName)
+   , mImportsLoadFlags(aImportsLoadFlags)
+   , mCreationTime(PR_Now())
+   , mCreationTimeStamp(TimeStamp::Now())
+   , mInstalledTime(0)
+   , mActivatedTime(0)
+   , mRedundantTime(0)
+@@ -238,22 +239,16 @@ ServiceWorkerInfo::ServiceWorkerInfo(nsI
+   mOriginAttributes = mPrincipal->OriginAttributesRef();
+   MOZ_ASSERT(!mScriptSpec.IsEmpty());
+   MOZ_ASSERT(!mCacheName.IsEmpty());
+ 
+   // Scripts of a service worker should always be loaded bypass service workers.
+   // Otherwise, we might not be able to update a service worker correctly, if
+   // there is a service worker generating the script.
+   MOZ_DIAGNOSTIC_ASSERT(mImportsLoadFlags & nsIChannel::LOAD_BYPASS_SERVICE_WORKER);
+-
+-  PrincipalInfo principalInfo;
+-  MOZ_ALWAYS_SUCCEEDS(PrincipalToPrincipalInfo(aPrincipal, &principalInfo));
+-
+-  mDescriptor = ServiceWorkerDescriptor(GetNextID(), principalInfo, aScope,
+-                                        ServiceWorkerState::Parsed);
+ }
+ 
+ ServiceWorkerInfo::~ServiceWorkerInfo()
+ {
+   MOZ_ASSERT(mServiceWorkerPrivate);
+   mServiceWorkerPrivate->NoteDeadServiceWorkerInfo();
+ }
+ 

+ 14 - 40
mozilla-release/patches/1445302-61a1.patch

@@ -2,7 +2,7 @@
 # User Miko Mynttinen <mikokm@gmail.com>
 # Date 1520949093 -3600
 # Node ID bceb565cfe14de56a10472e4965b4e9283b24307
-# Parent  8ce70b68946bcaa734cf9e2262548fbc5f163334
+# Parent  bbd1cf6d0b891e2d52d909aba99cf21b516e3b80
 Bug 1445302 - Replace TArray.RemoveElementAt(TArray.Length() - 1) pattern with TArray.RemoveLastElement() or TArray.PopLastElement() r=froydnj
 
 MozReview-Commit-ID: rGjabnP2iz
@@ -93,7 +93,7 @@ diff --git a/dom/base/nsDocumentEncoder.cpp b/dom/base/nsDocumentEncoder.cpp
 diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp
 --- a/dom/base/nsFrameMessageManager.cpp
 +++ b/dom/base/nsFrameMessageManager.cpp
-@@ -1100,17 +1100,17 @@ nsFrameMessageManager::ReceiveMessage(ns
+@@ -1101,17 +1101,17 @@ nsFrameMessageManager::ReceiveMessage(ns
            continue;
          }
          if (aRetVal) {
@@ -200,36 +200,10 @@ diff --git a/dom/media/webrtc/MediaTrackConstraints.cpp b/dom/media/webrtc/Media
  /* static */ const char*
  MediaConstraintsHelper::FindBadConstraint(
      const NormalizedConstraints& aConstraints,
-diff --git a/dom/workers/WorkerLoadInfo.cpp.1445302.later b/dom/workers/WorkerLoadInfo.cpp.1445302.later
-new file mode 100644
---- /dev/null
-+++ b/dom/workers/WorkerLoadInfo.cpp.1445302.later
-@@ -0,0 +1,21 @@
-+--- WorkerLoadInfo.cpp
-++++ WorkerLoadInfo.cpp
-+@@ -524,17 +524,17 @@ InterfaceRequestor::GetAnyLiveTabChild()
-+ 
-+     // Does this tab child still exist?  If so, return it.  We are done.  If the
-+     // PBrowser actor is no longer useful, don't bother returning this tab.
-+     if (tabChild && !static_cast<TabChild*>(tabChild.get())->IsDestroyed()) {
-+       return tabChild.forget();
-+     }
-+ 
-+     // Otherwise remove the stale weak reference and check the next one
-+-    mTabChildList.RemoveElementAt(mTabChildList.Length() - 1);
-++    mTabChildList.RemoveLastElement();
-+   }
-+ 
-+   return nullptr;
-+ }
-+ 
-+ NS_IMPL_ADDREF(WorkerLoadInfo::InterfaceRequestor)
-+ NS_IMPL_RELEASE(WorkerLoadInfo::InterfaceRequestor)
-+ NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor,
-diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
---- a/dom/workers/WorkerPrivate.cpp
-+++ b/dom/workers/WorkerPrivate.cpp
-@@ -2266,17 +2266,17 @@ InterfaceRequestor::GetAnyLiveTabChild()
+diff --git a/dom/workers/WorkerLoadInfo.cpp b/dom/workers/WorkerLoadInfo.cpp
+--- a/dom/workers/WorkerLoadInfo.cpp
++++ b/dom/workers/WorkerLoadInfo.cpp
+@@ -526,17 +526,17 @@ InterfaceRequestor::GetAnyLiveTabChild()
  
      // Does this tab child still exist?  If so, return it.  We are done.  If the
      // PBrowser actor is no longer useful, don't bother returning this tab.
@@ -247,7 +221,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
  
  NS_IMPL_ADDREF(WorkerLoadInfo::InterfaceRequestor)
  NS_IMPL_RELEASE(WorkerLoadInfo::InterfaceRequestor)
- NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor, nsIInterfaceRequestor)
+ NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor,
 diff --git a/dom/xbl/nsBindingManager.cpp b/dom/xbl/nsBindingManager.cpp
 --- a/dom/xbl/nsBindingManager.cpp
 +++ b/dom/xbl/nsBindingManager.cpp
@@ -470,7 +444,7 @@ diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp
 diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp
 --- a/image/imgLoader.cpp
 +++ b/image/imgLoader.cpp
-@@ -1018,17 +1018,17 @@ imgCacheQueue::Remove(imgCacheEntry* ent
+@@ -1020,17 +1020,17 @@ imgCacheQueue::Remove(imgCacheEntry* ent
    mSize -= mQueue[index]->GetDataSize();
  
    // If the queue is clean and this is the first entry,
@@ -489,7 +463,7 @@ diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp
    mQueue.RemoveElementAt(index);
  
    // If we only have one entry or the queue is empty, though,
-@@ -1064,18 +1064,17 @@ imgCacheQueue::Pop()
+@@ -1066,18 +1066,17 @@ imgCacheQueue::Pop()
    if (mQueue.IsEmpty()) {
      return nullptr;
    }
@@ -578,7 +552,7 @@ diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp
 diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
 --- a/layout/base/nsLayoutUtils.cpp
 +++ b/layout/base/nsLayoutUtils.cpp
-@@ -3259,17 +3259,17 @@ static bool gDumpEventList = false;
+@@ -3276,17 +3276,17 @@ static bool gDumpEventList = false;
  // maintaining a single paint count, we need a stack.
  StaticAutoPtr<nsTArray<int>> gPaintCountStack;
  
@@ -597,7 +571,7 @@ diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
  nsIFrame*
  nsLayoutUtils::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt, uint32_t aFlags)
  {
-@@ -5748,29 +5748,27 @@ nsLayoutUtils::ComputeBSizeDependentValu
+@@ -5765,29 +5765,27 @@ nsLayoutUtils::ComputeBSizeDependentValu
  nsLayoutUtils::MarkDescendantsDirty(nsIFrame *aSubtreeRoot)
  {
    AutoTArray<nsIFrame*, 4> subtrees;
@@ -629,7 +603,7 @@ diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp
          if (!nsLayoutUtils::IsProperAncestorFrame(subtreeRoot, oof)) {
            // We have another distinct subtree we need to mark.
            subtrees.AppendElement(oof);
-@@ -5792,18 +5790,17 @@ nsLayoutUtils::MarkDescendantsDirty(nsIF
+@@ -5809,18 +5807,17 @@ nsLayoutUtils::MarkDescendantsDirty(nsIF
  /* static */
  void
  nsLayoutUtils::MarkIntrinsicISizesDirtyIfDependentOnBSize(nsIFrame* aFrame)
@@ -786,7 +760,7 @@ diff --git a/layout/painting/nsDisplayList.h b/layout/painting/nsDisplayList.h
 diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp
 --- a/layout/style/FontFaceSet.cpp
 +++ b/layout/style/FontFaceSet.cpp
-@@ -1215,17 +1215,17 @@ FontFaceSet::FindOrCreateUserFontEntryFr
+@@ -1216,17 +1216,17 @@ FontFaceSet::FindOrCreateUserFontEntryFr
                // unknown format specified, mark to distinguish from the
                // case where no format hints are specified
                face->mFormatFlags |= gfxUserFontSet::FLAG_FORMAT_UNKNOWN;
@@ -862,7 +836,7 @@ diff --git a/netwerk/cache2/CacheIndexIterator.cpp b/netwerk/cache2/CacheIndexIt
 diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
 --- a/netwerk/protocol/http/nsHttpChannel.cpp
 +++ b/netwerk/protocol/http/nsHttpChannel.cpp
-@@ -8032,18 +8032,17 @@ nsHttpChannel::OnRedirectVerifyCallback(
+@@ -8047,18 +8047,17 @@ nsHttpChannel::OnRedirectVerifyCallback(
      mWaitingForRedirectCallback = false;
  
      if (mCanceled && NS_SUCCEEDED(result))

+ 5 - 5
mozilla-release/patches/1447409-61a1.patch

@@ -2,7 +2,7 @@
 # User Andrea Marchesini <amarchesini@mozilla.com>
 # Date 1521613479 -3600
 # Node ID 93cd9d50d653ab87e0dd8251950176e574c86c8e
-# Parent  eaab20d9b0595e9efbdd61a9e9513ddc35c0d51e
+# Parent  a8d0c5801780c5d0d255407b00025dc18aa33d7e
 Bug 1447409 - DOMPrefs.h must be included in WorkerScope, r=qdot
 
 diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
@@ -15,7 +15,7 @@ diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
  #ifndef mozilla_dom_workerscope_h__
  #define mozilla_dom_workerscope_h__
  
- #include "Workers.h"
+ #include "WorkerCommon.h"
  #include "mozilla/DOMEventTargetHelper.h"
 +#include "mozilla/dom/DOMPrefs.h"
  #include "mozilla/dom/Headers.h"
@@ -23,6 +23,6 @@ diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h
  #include "nsWeakReference.h"
  #include "mozilla/dom/ImageBitmapSource.h"
  
- namespace mozilla {
- namespace dom {
- 
+ #ifdef XP_WIN
+ #undef PostMessage
+ #endif

+ 37 - 37
mozilla-release/patches/1465585-3-std-62a1.patch

@@ -2,7 +2,7 @@
 # User Emilio Cobos Alvarez <emilio@crisal.io>
 # Date 1527707735 -7200
 # Node ID b54db66223586b4e04f5cb926fccdacf8a176b91
-# Parent  3a90e5f2ced4661fc09496c916df4ea570033039
+# Parent  193337722d215b912fc12b51b1419435b99f5811
 Bug 1465585: Switch from mozilla::Move to std::move. r=froydnj
 
 This was done automatically replacing:
@@ -5478,7 +5478,7 @@ diff --git a/dom/clients/manager/ClientInfo.cpp b/dom/clients/manager/ClientInfo
 diff --git a/dom/clients/manager/ClientManager.cpp b/dom/clients/manager/ClientManager.cpp
 --- a/dom/clients/manager/ClientManager.cpp
 +++ b/dom/clients/manager/ClientManager.cpp
-@@ -109,30 +109,30 @@ ClientManager::CreateSourceInternal(Clie
+@@ -110,30 +110,30 @@ ClientManager::CreateSourceInternal(Clie
    if (NS_WARN_IF(NS_FAILED(rv))) {
      // If we can't even get a UUID, at least make sure not to use a garbage
      // value.  Instead return a shutdown ClientSource with a zero'd id.
@@ -6266,6 +6266,28 @@ diff --git a/dom/file/Blob.cpp b/dom/file/Blob.cpp
    return file.forget();
  }
  
+diff --git a/dom/file/FileReaderSync.cpp b/dom/file/FileReaderSync.cpp
+--- a/dom/file/FileReaderSync.cpp
++++ b/dom/file/FileReaderSync.cpp
+@@ -475,17 +475,17 @@ FileReaderSync::SyncRead(nsIInputStream*
+   return SyncRead(aStream, aBuffer, aBufferSize, aRead);
+ }
+ 
+ nsresult
+ FileReaderSync::ConvertAsyncToSyncStream(uint64_t aStreamSize,
+                                          already_AddRefed<nsIInputStream> aAsyncStream,
+                                          nsIInputStream** aSyncStream)
+ {
+-  nsCOMPtr<nsIInputStream> asyncInputStream = Move(aAsyncStream);
++  nsCOMPtr<nsIInputStream> asyncInputStream = std::move(aAsyncStream);
+ 
+   // If the stream is not async, we just need it to be bufferable.
+   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(asyncInputStream);
+   if (!asyncStream) {
+     return NS_NewBufferedInputStream(aSyncStream, asyncInputStream.forget(), 4096);
+   }
+ 
+   nsAutoCString buffer;
 diff --git a/dom/file/MultipartBlobImpl.cpp b/dom/file/MultipartBlobImpl.cpp
 --- a/dom/file/MultipartBlobImpl.cpp
 +++ b/dom/file/MultipartBlobImpl.cpp
@@ -17229,7 +17251,7 @@ diff --git a/dom/security/nsCSPUtils.cpp b/dom/security/nsCSPUtils.cpp
 diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.cpp b/dom/serviceworkers/ServiceWorkerDescriptor.cpp
 --- a/dom/serviceworkers/ServiceWorkerDescriptor.cpp
 +++ b/dom/serviceworkers/ServiceWorkerDescriptor.cpp
-@@ -40,25 +40,25 @@ ServiceWorkerDescriptor&
+@@ -49,25 +49,25 @@ ServiceWorkerDescriptor&
  ServiceWorkerDescriptor::operator=(const ServiceWorkerDescriptor& aRight)
  {
    mData.reset();
@@ -18230,32 +18252,10 @@ diff --git a/dom/websocket/WebSocket.cpp b/dom/websocket/WebSocket.cpp
      aWorkerPrivate->AssertIsOnWorkerThread();
  
      // No messages when disconnected.
-diff --git a/dom/workers/FileReaderSync.cpp b/dom/workers/FileReaderSync.cpp
---- a/dom/workers/FileReaderSync.cpp
-+++ b/dom/workers/FileReaderSync.cpp
-@@ -474,17 +474,17 @@ FileReaderSync::SyncRead(nsIInputStream*
-   return SyncRead(aStream, aBuffer, aBufferSize, aRead);
- }
- 
- nsresult
- FileReaderSync::ConvertAsyncToSyncStream(uint64_t aStreamSize,
-                                          already_AddRefed<nsIInputStream> aAsyncStream,
-                                          nsIInputStream** aSyncStream)
- {
--  nsCOMPtr<nsIInputStream> asyncInputStream = Move(aAsyncStream);
-+  nsCOMPtr<nsIInputStream> asyncInputStream = std::move(aAsyncStream);
- 
-   // If the stream is not async, we just need it to be bufferable.
-   nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(asyncInputStream);
-   if (!asyncStream) {
-     return NS_NewBufferedInputStream(aSyncStream, asyncInputStream.forget(), 4096);
-   }
- 
-   nsAutoCString buffer;
 diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp
 --- a/dom/workers/RuntimeService.cpp
 +++ b/dom/workers/RuntimeService.cpp
-@@ -1585,17 +1585,17 @@ RuntimeService::RegisterWorker(WorkerPri
+@@ -1588,17 +1588,17 @@ RuntimeService::RegisterWorker(WorkerPri
             MOZ_CRASH("We should not instantiate a new SharedWorker!");
           }
        }
@@ -18356,7 +18356,7 @@ diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp
 diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
 --- a/dom/workers/WorkerPrivate.cpp
 +++ b/dom/workers/WorkerPrivate.cpp
-@@ -4716,17 +4716,17 @@ WorkerPrivate::Constructor(JSContext* aC
+@@ -3285,17 +3285,17 @@ WorkerPrivate::Constructor(JSContext* aC
    // WorkerThreadPrimaryRunnable::Run for workers just before running worker
    // code), so this is never SpiderMonkey's builtin default locale.
    JS::UniqueChars defaultLocale = JS_GetDefaultLocale(aCx);
@@ -18375,7 +18375,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
  
    worker->EnableDebugger();
  
-@@ -5273,17 +5273,17 @@ WorkerPrivate::DispatchToMainThread(nsIR
+@@ -3842,17 +3842,17 @@ WorkerPrivate::DispatchToMainThread(nsIR
    nsCOMPtr<nsIRunnable> r = aRunnable;
    return DispatchToMainThread(r.forget(), aFlags);
  }
@@ -18394,7 +18394,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
    return mWorkerControlEventTarget;
  }
  
-@@ -5361,17 +5361,17 @@ WorkerPrivate::GetClientInfo() const
+@@ -3930,17 +3930,17 @@ WorkerPrivate::GetClientInfo() const
  
  const ClientState
  WorkerPrivate::GetClientState() const
@@ -18413,7 +18413,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
    AssertIsOnWorkerThread();
    MOZ_DIAGNOSTIC_ASSERT(mClientSource);
    return mClientSource->GetController();
-@@ -7132,17 +7132,17 @@ WorkerPrivate::GetOrCreateGlobalScope(JS
+@@ -5659,17 +5659,17 @@ WorkerPrivate::GetOrCreateGlobalScope(JS
  
      JS::Rooted<JSObject*> global(aCx);
      NS_ENSURE_TRUE(globalScope->WrapGlobalObject(aCx, &global), nullptr);
@@ -18432,7 +18432,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
  
      JS_FireOnNewGlobalObject(aCx, global);
    }
-@@ -7163,17 +7163,17 @@ WorkerPrivate::CreateDebuggerGlobalScope
+@@ -5690,17 +5690,17 @@ WorkerPrivate::CreateDebuggerGlobalScope
    JS::Rooted<JSObject*> global(aCx);
    NS_ENSURE_TRUE(globalScope->WrapGlobalObject(aCx, &global), nullptr);
  
@@ -18454,7 +18454,7 @@ diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
 diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
 --- a/dom/workers/WorkerPrivate.h
 +++ b/dom/workers/WorkerPrivate.h
-@@ -322,17 +322,17 @@ public:
+@@ -239,17 +239,17 @@ public:
      AssertIsOnParentThread();
      MOZ_ASSERT(mSelfRef);
      mSelfRef = nullptr;
@@ -18473,7 +18473,7 @@ diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
    nsresult
    DispatchDebuggerRunnable(already_AddRefed<WorkerRunnable> aDebuggerRunnable);
  
-@@ -1185,17 +1185,17 @@ public:
+@@ -1062,17 +1062,17 @@ public:
    }
  
    JS::UniqueChars
@@ -18536,7 +18536,7 @@ diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp
 diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h
 --- a/dom/workers/WorkerRunnable.h
 +++ b/dom/workers/WorkerRunnable.h
-@@ -240,17 +240,17 @@ protected:
+@@ -241,17 +241,17 @@ protected:
                                 nsIEventTarget* aSyncLoopTarget)
    : WorkerSyncRunnable(aWorkerPrivate, aSyncLoopTarget)
    {
@@ -18558,7 +18558,7 @@ diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h
 diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
 --- a/dom/workers/WorkerScope.cpp
 +++ b/dom/workers/WorkerScope.cpp
-@@ -494,17 +494,17 @@ WorkerGlobalScope::CreateImageBitmap(JSC
+@@ -496,17 +496,17 @@ WorkerGlobalScope::CreateImageBitmap(JSC
      return nullptr;
    }
  }
@@ -18577,7 +18577,7 @@ diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
  {
    return mSerialEventTarget;
  }
-@@ -515,25 +515,25 @@ WorkerGlobalScope::AbstractMainThreadFor
+@@ -517,25 +517,25 @@ WorkerGlobalScope::AbstractMainThreadFor
    MOZ_CRASH("AbstractMainThreadFor not supported for workers.");
  }
  
@@ -18605,7 +18605,7 @@ diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp
    return mWorkerPrivate->GetController();
  }
  
-@@ -1095,17 +1095,17 @@ WorkerDebuggerGlobalScope::Dump(JSContex
+@@ -1097,17 +1097,17 @@ WorkerDebuggerGlobalScope::Dump(JSContex
      scope->Dump(aString);
    }
  }

+ 8 - 0
mozilla-release/patches/series

@@ -1319,6 +1319,7 @@ servo-19881-60a1.patch
 1433837-3-60a1.patch
 1433837-4-60a1.patch
 1433597-60a1.patch
+1433568-60a1.patch
 1433497-60a1.patch
 1430817-1-60a1.patch
 1430817-2-60a1.patch
@@ -1360,6 +1361,13 @@ servo-19824-60a1.patch
 1280162-1-60a1.patch
 1434171-60a1.patch
 1433117-60a1.patch
+1413112-1-60a1.patch
+1413112-2-60a1.patch
+1413112-3-60a1.patch
+1413112-4-60a1.patch
+1413112-5-60a1.patch
+1413112-6-60a1.patch
+1413112-7-60a1.patch
 1425340-60a1.patch
 1434219-60a1.patch
 1255379-60a1.patch