/* -*- 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 "nsIDOMFile.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 "nsPrintfCString.h" #include "nsHostObjectProtocolHandler.h" #include #include "jsfriendapi.h" #include "js/OldDebugAPI.h" #include "js/MemoryMetrics.h" #include "mozilla/Attributes.h" #include "mozilla/ContentEvents.h" #include "mozilla/Likely.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ImageData.h" #include "mozilla/dom/ImageDataBinding.h" #include "nsAlgorithm.h" #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsError.h" #include "nsDOMJSUtils.h" #include "nsJSEnvironment.h" #include "nsJSUtils.h" #include "nsNetUtil.h" #include "nsProxyRelease.h" #include "nsSandboxFlags.h" #include "nsThreadUtils.h" #include "xpcpublic.h" #ifdef ANDROID #include #endif #include "Events.h" #include "mozilla/dom/Exceptions.h" #include "File.h" #include "Principal.h" #include "RuntimeService.h" #include "ScriptLoader.h" #include "Worker.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 using mozilla::MutexAutoLock; using mozilla::TimeDuration; using mozilla::TimeStamp; using mozilla::dom::Throw; using mozilla::AutoPushJSContext; using mozilla::AutoSafeJSContext; USING_WORKERS_NAMESPACE using namespace mozilla::dom::workers::events; 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