/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ /* vim: set ts=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 "nsIDOMFile.h" #include "nsIDOMMessageEvent.h" #include "nsIDocument.h" #include "nsIDocShell.h" #include "nsIMemoryReporter.h" #include "nsIPermissionManager.h" #include "nsIScriptError.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptSecurityManager.h" #include "nsPIDOMWindow.h" #include "nsITextToSubURI.h" #include "nsITimer.h" #include "nsIURI.h" #include "nsIURL.h" #include "nsIXPConnect.h" #include #include "jsfriendapi.h" #include "js/OldDebugAPI.h" #include "js/MemoryMetrics.h" #include "mozilla/ContentEvents.h" #include "mozilla/Likely.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ErrorEvent.h" #include "mozilla/dom/ErrorEventBinding.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/ImageData.h" #include "mozilla/dom/ImageDataBinding.h" #include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/MessagePortList.h" #include "mozilla/dom/WorkerBinding.h" #include "mozilla/Preferences.h" #include "mozilla/Util.h" #include "nsAlgorithm.h" #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsError.h" #include "nsEventDispatcher.h" #include "nsDOMMessageEvent.h" #include "nsDOMJSUtils.h" #include "nsHostObjectProtocolHandler.h" #include "nsJSEnvironment.h" #include "nsJSUtils.h" #include "nsNetUtil.h" #include "nsPrintfCString.h" #include "nsProxyRelease.h" #include "nsSandboxFlags.h" #include "xpcpublic.h" #ifdef ANDROID #include #endif #include "mozilla/dom/Exceptions.h" #include "File.h" #include "MessagePort.h" #include "Principal.h" #include "RuntimeService.h" #include "ScriptLoader.h" #include "SharedWorker.h" #include "WorkerFeature.h" #include "WorkerScope.h" // GC will run once every thirty seconds during normal execution. #define NORMAL_GC_TIMER_DELAY_MS 30000 // GC will run five seconds after the last event is processed. #define IDLE_GC_TIMER_DELAY_MS 5000 #define PREF_WORKERS_ENABLED "dom.workers.enabled" using mozilla::InternalScriptErrorEvent; using mozilla::MutexAutoLock; using mozilla::TimeDuration; using mozilla::TimeStamp; using mozilla::dom::Throw; using mozilla::AutoCxPusher; using mozilla::AutoPushJSContext; using mozilla::AutoSafeJSContext; USING_WORKERS_NAMESPACE using namespace mozilla::dom; NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(JsWorkerMallocSizeOf) namespace { template class AutoPtrComparator { typedef nsAutoPtr A; typedef T* B; public: bool Equals(const A& a, const B& b) const { return a && b ? *a == *b : !a && !b ? true : false; } bool LessThan(const A& a, const B& b) const { return a && b ? *a < *b : b ? true : false; } }; template inline AutoPtrComparator GetAutoPtrComparator(const nsTArray >&) { return AutoPtrComparator(); } // Specialize this if there's some class that has multiple nsISupports bases. template struct ISupportsBaseInfo { typedef T ISupportsBase; }; template