From ddd36fec56eae8000fbc2822db58b5964fef734b Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Sat, 28 Jan 2017 00:42:47 +0900 Subject: [PATCH] Bug 1332245 - Move nsScriptError from js/xpconnect to dom/bindings. r=bz --HG-- rename : js/xpconnect/idl/nsIScriptError.idl => dom/bindings/nsIScriptError.idl rename : js/xpconnect/src/nsScriptError.cpp => dom/bindings/nsScriptError.cpp rename : js/xpconnect/src/nsScriptErrorWithStack.cpp => dom/bindings/nsScriptErrorWithStack.cpp --- b2g/installer/package-manifest.in | 1 + browser/installer/package-manifest.in | 1 + dom/bindings/moz.build | 8 ++ .../idl => dom/bindings}/nsIScriptError.idl | 0 .../src => dom/bindings}/nsScriptError.cpp | 6 +- dom/bindings/nsScriptError.h | 86 +++++++++++++++++++ .../bindings}/nsScriptErrorWithStack.cpp | 4 +- js/ipc/JavaScriptParent.cpp | 1 + js/xpconnect/idl/moz.build | 1 - js/xpconnect/src/XPCComponents.cpp | 2 + js/xpconnect/src/XPCConvert.cpp | 2 + js/xpconnect/src/XPCModule.h | 4 - js/xpconnect/src/XPCWrappedJSClass.cpp | 1 + js/xpconnect/src/XPCWrappedNativeInfo.cpp | 1 + js/xpconnect/src/moz.build | 3 +- js/xpconnect/src/nsXPConnect.cpp | 2 + js/xpconnect/src/xpcprivate.h | 72 ---------------- layout/build/moz.build | 1 + layout/build/nsLayoutModule.cpp | 9 ++ mobile/android/installer/package-manifest.in | 1 + 20 files changed, 123 insertions(+), 83 deletions(-) rename {js/xpconnect/idl => dom/bindings}/nsIScriptError.idl (100%) rename {js/xpconnect/src => dom/bindings}/nsScriptError.cpp (98%) create mode 100644 dom/bindings/nsScriptError.h rename {js/xpconnect/src => dom/bindings}/nsScriptErrorWithStack.cpp (97%) diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 38ce27182aa4..7ab76fb2ae43 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -149,6 +149,7 @@ @RESPATH@/components/dom_activities.xpt @RESPATH@/components/dom_audiochannel.xpt @RESPATH@/components/dom_base.xpt +@RESPATH@/components/dom_bindings.xpt @RESPATH@/components/dom_file.xpt @RESPATH@/components/dom_system.xpt @RESPATH@/components/dom_workers.xpt diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 6f6bacdb4e97..2afc4f2e6bc7 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -196,6 +196,7 @@ @RESPATH@/components/docshell.xpt @RESPATH@/components/dom.xpt @RESPATH@/components/dom_base.xpt +@RESPATH@/components/dom_bindings.xpt @RESPATH@/components/dom_file.xpt @RESPATH@/components/dom_system.xpt @RESPATH@/components/dom_canvas.xpt diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index ad0f03a1e203..aec931c3b27b 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -6,6 +6,12 @@ TEST_DIRS += ['test'] +XPIDL_SOURCES += [ + 'nsIScriptError.idl' +] + +XPIDL_MODULE = 'dom_bindings' + EXPORTS.ipc += [ 'ErrorIPCUtils.h', ] @@ -91,6 +97,8 @@ UNIFIED_SOURCES += [ 'DOMJSProxyHandler.cpp', 'Exceptions.cpp', 'IterableIterator.cpp', + 'nsScriptError.cpp', + 'nsScriptErrorWithStack.cpp', 'SimpleGlobalObject.cpp', 'ToJSValue.cpp', 'WebIDLGlobalNameHash.cpp', diff --git a/js/xpconnect/idl/nsIScriptError.idl b/dom/bindings/nsIScriptError.idl similarity index 100% rename from js/xpconnect/idl/nsIScriptError.idl rename to dom/bindings/nsIScriptError.idl diff --git a/js/xpconnect/src/nsScriptError.cpp b/dom/bindings/nsScriptError.cpp similarity index 98% rename from js/xpconnect/src/nsScriptError.cpp rename to dom/bindings/nsScriptError.cpp index ff687bc441aa..686b0f7fc120 100644 --- a/js/xpconnect/src/nsScriptError.cpp +++ b/dom/bindings/nsScriptError.cpp @@ -5,15 +5,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* - * nsIScriptError implementation. Defined here, lacking a JS-specific - * place to put XPCOM things. + * nsIScriptError implementation. */ -#include "xpcprivate.h" +#include "nsScriptError.h" #include "jsprf.h" #include "MainThreadUtils.h" #include "mozilla/Assertions.h" #include "nsGlobalWindow.h" +#include "nsNetUtil.h" #include "nsPIDOMWindow.h" #include "nsILoadContext.h" #include "nsIDocShell.h" diff --git a/dom/bindings/nsScriptError.h b/dom/bindings/nsScriptError.h new file mode 100644 index 000000000000..da59e3082791 --- /dev/null +++ b/dom/bindings/nsScriptError.h @@ -0,0 +1,86 @@ +/* -*- 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_nsScriptError_h +#define mozilla_dom_nsScriptError_h + +#include "mozilla/Atomics.h" + +#include + +#include "jsapi.h" +#include "js/RootingAPI.h" + +#include "nsIScriptError.h" +#include "nsString.h" + +// Definition of nsScriptError.. +class nsScriptErrorBase : public nsIScriptError { +public: + nsScriptErrorBase(); + + NS_DECL_NSICONSOLEMESSAGE + NS_DECL_NSISCRIPTERROR + +protected: + virtual ~nsScriptErrorBase(); + + void + InitializeOnMainThread(); + + nsString mMessage; + nsString mMessageName; + nsString mSourceName; + uint32_t mLineNumber; + nsString mSourceLine; + uint32_t mColumnNumber; + uint32_t mFlags; + nsCString mCategory; + // mOuterWindowID is set on the main thread from InitializeOnMainThread(). + uint64_t mOuterWindowID; + uint64_t mInnerWindowID; + int64_t mTimeStamp; + // mInitializedOnMainThread and mIsFromPrivateWindow are set on the main + // thread from InitializeOnMainThread(). + mozilla::Atomic mInitializedOnMainThread; + bool mIsFromPrivateWindow; +}; + +class nsScriptError final : public nsScriptErrorBase { +public: + nsScriptError() {} + NS_DECL_THREADSAFE_ISUPPORTS + +private: + virtual ~nsScriptError() {} +}; + +class nsScriptErrorWithStack : public nsScriptErrorBase { +public: + explicit nsScriptErrorWithStack(JS::HandleObject); + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsScriptErrorWithStack) + + NS_IMETHOD Init(const nsAString& message, + const nsAString& sourceName, + const nsAString& sourceLine, + uint32_t lineNumber, + uint32_t columnNumber, + uint32_t flags, + const char* category) override; + + NS_IMETHOD GetStack(JS::MutableHandleValue) override; + NS_IMETHOD ToString(nsACString& aResult) override; + +private: + virtual ~nsScriptErrorWithStack(); + // Complete stackframe where the error happened. + // Must be SavedFrame object. + JS::Heap mStack; +}; + +#endif /* mozilla_dom_nsScriptError_h */ diff --git a/js/xpconnect/src/nsScriptErrorWithStack.cpp b/dom/bindings/nsScriptErrorWithStack.cpp similarity index 97% rename from js/xpconnect/src/nsScriptErrorWithStack.cpp rename to dom/bindings/nsScriptErrorWithStack.cpp index 50407da23c35..74c00999fd71 100644 --- a/js/xpconnect/src/nsScriptErrorWithStack.cpp +++ b/dom/bindings/nsScriptErrorWithStack.cpp @@ -10,12 +10,14 @@ * that can store a SavedFrame stack trace object. */ -#include "xpcprivate.h" +#include "nsScriptError.h" #include "MainThreadUtils.h" #include "mozilla/Assertions.h" +#include "mozilla/dom/ScriptSettings.h" #include "nsGlobalWindow.h" #include "nsCycleCollectionParticipant.h" +using namespace mozilla::dom; namespace { diff --git a/js/ipc/JavaScriptParent.cpp b/js/ipc/JavaScriptParent.cpp index 8f5740c667b0..1473ca402e5e 100644 --- a/js/ipc/JavaScriptParent.cpp +++ b/js/ipc/JavaScriptParent.cpp @@ -9,6 +9,7 @@ #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ScriptSettings.h" #include "nsJSUtils.h" +#include "nsIScriptError.h" #include "jsfriendapi.h" #include "jswrapper.h" #include "js/Proxy.h" diff --git a/js/xpconnect/idl/moz.build b/js/xpconnect/idl/moz.build index 2438b1a5a84e..0808d3450610 100644 --- a/js/xpconnect/idl/moz.build +++ b/js/xpconnect/idl/moz.build @@ -7,7 +7,6 @@ XPIDL_SOURCES += [ 'mozIJSSubScriptLoader.idl', 'nsIAddonInterposition.idl', - 'nsIScriptError.idl', 'nsIXPConnect.idl', 'nsIXPCScriptable.idl', 'xpccomponents.idl', diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index 7bb0b15d1f6a..7a4f71975ecd 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -34,9 +34,11 @@ #include "nsDOMClassInfo.h" #include "ShimInterfaceInfo.h" #include "nsIAddonInterposition.h" +#include "nsIScriptError.h" #include "nsISimpleEnumerator.h" #include "nsPIDOMWindow.h" #include "nsGlobalWindow.h" +#include "nsScriptError.h" using namespace mozilla; using namespace JS; diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index 85a048194da1..cff14b991cf5 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -11,9 +11,11 @@ #include "xpcprivate.h" #include "nsIAtom.h" +#include "nsIScriptError.h" #include "nsWrapperCache.h" #include "nsJSUtils.h" #include "nsQueryObject.h" +#include "nsScriptError.h" #include "WrapperFactory.h" #include "nsWrapperCacheInlines.h" diff --git a/js/xpconnect/src/XPCModule.h b/js/xpconnect/src/XPCModule.h index d627646254b3..506e8945a483 100644 --- a/js/xpconnect/src/XPCModule.h +++ b/js/xpconnect/src/XPCModule.h @@ -23,7 +23,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect, nsXPConnect::GetSingleton) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError) NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSComponentLoader) NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader) @@ -31,14 +30,12 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader) NS_DEFINE_NAMED_CID(NS_JS_ID_CID); NS_DEFINE_NAMED_CID(NS_XPCONNECT_CID); NS_DEFINE_NAMED_CID(NS_XPCEXCEPTION_CID); -NS_DEFINE_NAMED_CID(NS_SCRIPTERROR_CID); NS_DEFINE_NAMED_CID(MOZJSCOMPONENTLOADER_CID); NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID); #define XPCONNECT_CIDENTRIES \ { &kNS_JS_ID_CID, false, nullptr, nsJSIDConstructor }, \ { &kNS_XPCONNECT_CID, false, nullptr, nsIXPConnectConstructor }, \ - { &kNS_SCRIPTERROR_CID, false, nullptr, nsScriptErrorConstructor }, \ { &kMOZJSCOMPONENTLOADER_CID, false, nullptr, mozJSComponentLoaderConstructor },\ { &kMOZ_JSSUBSCRIPTLOADER_CID, false, nullptr, mozJSSubScriptLoaderConstructor }, @@ -46,7 +43,6 @@ NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID); { XPC_ID_CONTRACTID, &kNS_JS_ID_CID }, \ { XPC_XPCONNECT_CONTRACTID, &kNS_XPCONNECT_CID }, \ { XPC_CONTEXT_STACK_CONTRACTID, &kNS_XPCONNECT_CID }, \ - { NS_SCRIPTERROR_CONTRACTID, &kNS_SCRIPTERROR_CID }, \ { MOZJSCOMPONENTLOADER_CONTRACTID, &kMOZJSCOMPONENTLOADER_CID }, \ { MOZJSSUBSCRIPTLOADER_CONTRACTID, &kMOZ_JSSUBSCRIPTLOADER_CID }, diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 8f666137d817..69727771388e 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -10,6 +10,7 @@ #include "jsprf.h" #include "nsArrayEnumerator.h" #include "nsContentUtils.h" +#include "nsIScriptError.h" #include "nsWrapperCache.h" #include "AccessCheck.h" #include "nsJSUtils.h" diff --git a/js/xpconnect/src/XPCWrappedNativeInfo.cpp b/js/xpconnect/src/XPCWrappedNativeInfo.cpp index 302454fb53d0..4b0330af6279 100644 --- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp +++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp @@ -11,6 +11,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/XPTInterfaceInfoManager.h" +#include "nsIScriptError.h" #include "nsPrintfCString.h" using namespace JS; diff --git a/js/xpconnect/src/moz.build b/js/xpconnect/src/moz.build index 7e787bb566f2..7d9cd5b37ff3 100644 --- a/js/xpconnect/src/moz.build +++ b/js/xpconnect/src/moz.build @@ -14,8 +14,6 @@ EXPORTS += [ UNIFIED_SOURCES += [ 'ExportHelpers.cpp', - 'nsScriptError.cpp', - 'nsScriptErrorWithStack.cpp', 'nsXPConnect.cpp', 'Sandbox.cpp', 'XPCCallContext.cpp', @@ -58,6 +56,7 @@ LOCAL_INCLUDES += [ '../wrappers', '/caps', '/dom/base', + '/dom/bindings', '/dom/html', '/dom/svg', '/dom/workers', diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 86b304682aa4..ef6099c6cfd2 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -33,7 +33,9 @@ #include "nsIObjectOutputStream.h" #include "nsScriptSecurityManager.h" #include "nsIPermissionManager.h" +#include "nsIScriptError.h" #include "nsContentUtils.h" +#include "nsScriptError.h" #include "jsfriendapi.h" using namespace mozilla; diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index 5622821d35a4..b9145d73495d 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -127,7 +127,6 @@ #include "MainThreadUtils.h" #include "nsIConsoleService.h" -#include "nsIScriptError.h" #include "nsIException.h" #include "nsVariant.h" @@ -2408,77 +2407,6 @@ extern char* xpc_PrintJSStack(JSContext* cx, bool showArgs, bool showLocals, bool showThisProps); -/***************************************************************************/ - -// Definition of nsScriptError, defined here because we lack a place to put -// XPCOM objects associated with the JavaScript engine. -class nsScriptErrorBase : public nsIScriptError { -public: - nsScriptErrorBase(); - - // TODO - do something reasonable on getting null from these babies. - - NS_DECL_NSICONSOLEMESSAGE - NS_DECL_NSISCRIPTERROR - -protected: - virtual ~nsScriptErrorBase(); - - void - InitializeOnMainThread(); - - nsString mMessage; - nsString mMessageName; - nsString mSourceName; - uint32_t mLineNumber; - nsString mSourceLine; - uint32_t mColumnNumber; - uint32_t mFlags; - nsCString mCategory; - // mOuterWindowID is set on the main thread from InitializeOnMainThread(). - uint64_t mOuterWindowID; - uint64_t mInnerWindowID; - int64_t mTimeStamp; - // mInitializedOnMainThread and mIsFromPrivateWindow are set on the main - // thread from InitializeOnMainThread(). - mozilla::Atomic mInitializedOnMainThread; - bool mIsFromPrivateWindow; -}; - -class nsScriptError final : public nsScriptErrorBase { -public: - nsScriptError() {} - NS_DECL_THREADSAFE_ISUPPORTS - -private: - virtual ~nsScriptError() {} -}; - -class nsScriptErrorWithStack : public nsScriptErrorBase { -public: - explicit nsScriptErrorWithStack(JS::HandleObject); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsScriptErrorWithStack) - - NS_IMETHOD Init(const nsAString& message, - const nsAString& sourceName, - const nsAString& sourceLine, - uint32_t lineNumber, - uint32_t columnNumber, - uint32_t flags, - const char* category) override; - - NS_IMETHOD GetStack(JS::MutableHandleValue) override; - NS_IMETHOD ToString(nsACString& aResult) override; - -private: - virtual ~nsScriptErrorWithStack(); - // Complete stackframe where the error happened. - // Must be SavedFrame object. - JS::Heap mStack; -}; - /****************************************************************************** * Handles pre/post script processing. */ diff --git a/layout/build/moz.build b/layout/build/moz.build index 400eb610a9df..f7941b5061b3 100644 --- a/layout/build/moz.build +++ b/layout/build/moz.build @@ -32,6 +32,7 @@ LOCAL_INCLUDES += [ '/docshell/base', '/dom/audiochannel', '/dom/base', + '/dom/bindings', '/dom/canvas', '/dom/filesystem', '/dom/geolocation', diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 5b272126e76e..0356664782ec 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -35,6 +35,7 @@ #include "nsIObserver.h" #include "nsIObserverService.h" #include "nsIScriptNameSpaceManager.h" +#include "nsIScriptError.h" #include "nsISelection.h" #include "nsCaret.h" #include "nsPlainTextSerializer.h" @@ -210,6 +211,8 @@ static void Shutdown(); #include "mozilla/dom/PresentationDeviceManager.h" #include "mozilla/dom/PresentationTCPSessionTransport.h" +#include "nsScriptError.h" + #include "mozilla/TextInputProcessor.h" using namespace mozilla; @@ -602,6 +605,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(UDPSocketChild) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(GeckoMediaPluginService, GeckoMediaPluginService::GetGeckoMediaPluginService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptError) + #ifdef ACCESSIBILITY #include "xpcAccessibilityService.h" @@ -781,6 +786,8 @@ NS_DEFINE_NAMED_CID(TEXT_INPUT_PROCESSOR_CID); NS_DEFINE_NAMED_CID(NS_HARDWARE_KEY_HANDLER_CID); #endif +NS_DEFINE_NAMED_CID(NS_SCRIPTERROR_CID); + static nsresult CreateWindowCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -1052,6 +1059,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kPRESENTATION_DEVICE_MANAGER_CID, false, nullptr, PresentationDeviceManagerConstructor }, { &kPRESENTATION_TCP_SESSION_TRANSPORT_CID, false, nullptr, PresentationTCPSessionTransportConstructor }, { &kTEXT_INPUT_PROCESSOR_CID, false, nullptr, TextInputProcessorConstructor }, + { &kNS_SCRIPTERROR_CID, false, nullptr, nsScriptErrorConstructor }, { nullptr } }; @@ -1199,6 +1207,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { #ifdef MOZ_B2G { NS_HARDWARE_KEY_HANDLER_CONTRACTID, &kNS_HARDWARE_KEY_HANDLER_CID }, #endif + { NS_SCRIPTERROR_CONTRACTID, &kNS_SCRIPTERROR_CID }, { nullptr } }; diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index fe1fb5c54a6c..cd22b9b5ff38 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -113,6 +113,7 @@ @BINPATH@/components/docshell.xpt @BINPATH@/components/dom.xpt @BINPATH@/components/dom_base.xpt +@BINPATH@/components/dom_bindings.xpt @BINPATH@/components/dom_canvas.xpt @BINPATH@/components/dom_core.xpt @BINPATH@/components/dom_css.xpt