/* -*- 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 "nsIClassInfo.h" #include "nsIContentSecurityPolicy.h" #include "nsIConsoleService.h" #include "nsIDOMFile.h" #include "nsIDocument.h" #include "nsIDocShell.h" #include "nsIJSContextStack.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 "nsIXPCScriptNotify.h" #include "jsfriendapi.h" #include "jsdbgapi.h" #include "jsfriendapi.h" #include "jsprf.h" #include "js/MemoryMetrics.h" #include "nsAlgorithm.h" #include "nsContentUtils.h" #include "nsError.h" #include "nsDOMJSUtils.h" #include "nsGUIEvent.h" #include "nsJSEnvironment.h" #include "nsJSUtils.h" #include "nsNetUtil.h" #include "nsSandboxFlags.h" #include "nsThreadUtils.h" #include "xpcpublic.h" #include "mozilla/Attributes.h" #include "mozilla/Likely.h" #include #ifdef ANDROID #include #endif #include "Events.h" #include "Exceptions.h" #include "File.h" #include "ImageData.h" #include "Principal.h" #include "RuntimeService.h" #include "ScriptLoader.h" #include "Worker.h" #include "WorkerFeature.h" #include "WorkerScope.h" #if 0 // Define to run GC more often. #define EXTRA_GC #endif // 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::workers::exceptions::ThrowDOMExceptionForNSResult; USING_WORKERS_NAMESPACE using namespace mozilla::dom::workers::events; using namespace mozilla::dom; NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN(JsWorkerMallocSizeOf) namespace { const char gErrorChars[] = "error"; const char gMessageChars[] = "message"; 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