Bug 816410 - Part 2: Remove legacy constructor functions. r=bz
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Mon, 03 Dec 2012 20:26:16 -0500
changeset 114868 7a751769149c
parent 114867 436999015159
child 114869 4184752489ef
push id23947
push useremorley@mozilla.com
push date2012-12-04 14:54 +0000
treeherdermozilla-central@0035f77045bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs816410
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 816410 - Part 2: Remove legacy constructor functions. r=bz
content/base/public/nsIDOMParser.idl
content/base/src/nsDOMParser.cpp
content/base/src/nsDOMParser.h
dom/base/nsDOMClassInfo.cpp
--- a/content/base/public/nsIDOMParser.idl
+++ b/content/base/public/nsIDOMParser.idl
@@ -87,31 +87,16 @@ interface nsIDOMParser : nsISupports
    *                     can be got.
    */
   [noscript] void init(in nsIPrincipal principal,
                        in nsIURI documentURI,
                        in nsIURI baseURI,
                        in nsIScriptGlobalObject scriptObject);
 };
 
-/**
- * The nsIDOMParserJS interface provides a scriptable way of calling init().
- * Do NOT use this interface from languages other than JavaScript.
- */
-[scriptable, uuid(ba6bcd6c-63d8-49b3-bc8a-1e5e895645bc)]
-interface nsIDOMParserJS : nsISupports
-{
-  /**
-   * Just like nsIDOMParser.init, but callable from JS.
-   */
-  void init([optional] in nsIPrincipal principal,
-            [optional] in nsIURI documentURI,
-            [optional] in nsIURI baseURI);
-};
-
 %{ C++
 #define NS_DOMPARSER_CID                            \
  { /* 3a8a3a50-512c-11d4-9a54-000064657374 */       \
    0x3a8a3a50, 0x512c, 0x11d4,                      \
   {0x9a, 0x54, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74} }
 #define NS_DOMPARSER_CONTRACTID \
 "@mozilla.org/xmlextras/domparser;1"
 %}
--- a/content/base/src/nsDOMParser.cpp
+++ b/content/base/src/nsDOMParser.cpp
@@ -42,19 +42,17 @@ nsDOMParser::~nsDOMParser()
 
 DOMCI_DATA(DOMParser, nsDOMParser)
 
 // QueryInterface implementation for nsDOMParser
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMParser)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMParser)
   NS_INTERFACE_MAP_ENTRY(nsIDOMParser)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMParserJS)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
-  NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DOMParser)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMParser, mOwner)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMParser)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMParser)
 
@@ -354,84 +352,16 @@ nsDOMParser::Init(nsIPrincipal* principa
   // documentURI as the base.  Otherwise for null principals we'll get
   // nsDocument::SetBaseURI giving errors.
 
   NS_POSTCONDITION(mPrincipal, "Must have principal");
   NS_POSTCONDITION(mOriginalPrincipal, "Must have original principal");
   NS_POSTCONDITION(mDocumentURI, "Must have document URI");
   return NS_OK;
 }
-  
-static nsQueryInterface
-JSvalToInterface(JSContext* cx, JS::Value val, nsIXPConnect* xpc, bool* wasNull)
-{
-  if (val.isNull()) {
-    *wasNull = true;
-    return nsQueryInterface(nullptr);
-  }
-  
-  *wasNull = false;
-  if (val.isObject()) {
-    JSObject* arg = &val.toObject();
-
-    nsCOMPtr<nsIXPConnectWrappedNative> native;
-    xpc->GetWrappedNativeOfJSObject(cx, arg, getter_AddRefs(native));
-
-    // do_QueryWrappedNative is not null-safe
-    if (native) {
-      return do_QueryWrappedNative(native);
-    }
-  }
-  
-  return nsQueryInterface(nullptr);
-}
-
-static nsresult
-GetInitArgs(JSContext *cx, uint32_t argc, jsval *argv,
-            nsIPrincipal** aPrincipal, nsIURI** aDocumentURI,
-            nsIURI** aBaseURI)
-{
-  if (!nsContentUtils::IsCallerChrome()) {
-    return NS_ERROR_DOM_SECURITY_ERR;
-  }
-  
-  nsIXPConnect* xpc = nsContentUtils::XPConnect();
-  
-  // First arg is our principal.  If someone passes something that's
-  // not a principal and not null, die to prevent privilege escalation.
-  bool wasNull;
-  nsCOMPtr<nsIPrincipal> prin = JSvalToInterface(cx, argv[0], xpc, &wasNull);
-  if (!prin && !wasNull) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  nsCOMPtr<nsIURI> documentURI;
-  nsCOMPtr<nsIURI> baseURI;
-  if (argc > 1) {
-    // Grab our document URI too.  Again, if it's something unexpected bail
-    // out.
-    documentURI = JSvalToInterface(cx, argv[1], xpc, &wasNull);
-    if (!documentURI && !wasNull) {
-      return NS_ERROR_INVALID_ARG;
-    }
-
-    if (argc > 2) {
-      // Grab our base URI as well
-      baseURI = JSvalToInterface(cx, argv[2], xpc, &wasNull);
-      if (!baseURI && !wasNull) {
-        return NS_ERROR_INVALID_ARG;
-      }
-    }
-  }
-
-  NS_IF_ADDREF(*aPrincipal = prin);
-  NS_IF_ADDREF(*aDocumentURI = documentURI);
-  NS_IF_ADDREF(*aBaseURI = baseURI);
-  return NS_OK;
-}
 
 /*static */already_AddRefed<nsDOMParser>
 nsDOMParser::Constructor(nsISupports* aOwner, nsIPrincipal* aPrincipal,
                          nsIURI* aDocumentURI, nsIURI* aBaseURI,
                          ErrorResult& rv)
 {
   if (!nsContentUtils::IsCallerChrome()) {
     rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
@@ -440,41 +370,46 @@ nsDOMParser::Constructor(nsISupports* aO
   nsRefPtr<nsDOMParser> domParser = new nsDOMParser(aOwner);
   rv = domParser->InitInternal(aOwner, aPrincipal, aDocumentURI, aBaseURI);
   if (rv.Failed()) {
     return nullptr;
   }
   return domParser.forget();
 }
 
-NS_IMETHODIMP
-nsDOMParser::Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
-                        uint32_t argc, jsval *argv)
+/*static */already_AddRefed<nsDOMParser>
+nsDOMParser::Constructor(nsISupports* aOwner, mozilla::ErrorResult& rv)
 {
   nsCOMPtr<nsIPrincipal> prin;
   nsCOMPtr<nsIURI> documentURI;
   nsCOMPtr<nsIURI> baseURI;
-  if (argc > 0) {
-    nsresult rv = GetInitArgs(cx, argc, argv, getter_AddRefs(prin),
-                              getter_AddRefs(documentURI),
-                              getter_AddRefs(baseURI));
-    NS_ENSURE_SUCCESS(rv, rv);
-  } else {
-    // No arguments; use the subject principal
-    nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
-    NS_ENSURE_TRUE(secMan, NS_ERROR_UNEXPECTED);
+  // No arguments; use the subject principal
+  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
+  if (!secMan) {
+    rv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
 
-    nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(prin));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // We're called from JS; there better be a subject principal, really.
-    NS_ENSURE_TRUE(prin, NS_ERROR_UNEXPECTED);
+  rv = secMan->GetSubjectPrincipal(getter_AddRefs(prin));
+  if (rv.Failed()) {
+    return nullptr;
   }
 
-  return InitInternal(aOwner, prin, documentURI, baseURI);
+  // We're called from JS; there better be a subject principal, really.
+  if (!prin) {
+    rv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
+
+  nsRefPtr<nsDOMParser> domParser = new nsDOMParser(aOwner);
+  rv = domParser->InitInternal(aOwner, prin, documentURI, baseURI);
+  if (rv.Failed()) {
+    return nullptr;
+  }
+  return domParser.forget();
 }
 
 nsresult
 nsDOMParser::InitInternal(nsISupports* aOwner, nsIPrincipal* prin,
                           nsIURI* documentURI, nsIURI* baseURI)
 {
   AttemptedInitMarker marker(&mAttemptedInit);
   if (!documentURI) {
@@ -504,42 +439,53 @@ nsDOMParser::InitInternal(nsISupports* a
     baseURI = doc->GetDocBaseURI();
     documentURI = doc->GetDocumentURI();
   }
 
   nsCOMPtr<nsIScriptGlobalObject> scriptglobal = do_QueryInterface(aOwner);
   return Init(prin, documentURI, baseURI, scriptglobal);
 }
 
-NS_IMETHODIMP
-nsDOMParser::Init(nsIPrincipal *aPrincipal, nsIURI *aDocumentURI,
-                  nsIURI *aBaseURI)
+void
+nsDOMParser::Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
+                  nsIURI* aBaseURI, mozilla::ErrorResult& rv)
 {
   AttemptedInitMarker marker(&mAttemptedInit);
 
   JSContext *cx = nsContentUtils::GetCurrentJSContext();
-  NS_ENSURE_TRUE(cx, NS_ERROR_UNEXPECTED);
+  if (!cx) {
+    rv.Throw(NS_ERROR_UNEXPECTED);
+    return;
+  }
 
   nsIScriptContext* scriptContext = GetScriptContextFromJSContext(cx);
 
   nsCOMPtr<nsIPrincipal> principal = aPrincipal;
 
   if (!principal && !aDocumentURI) {
     nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
-    NS_ENSURE_TRUE(secMan, NS_ERROR_UNEXPECTED);
+    if (!secMan) {
+      rv.Throw(NS_ERROR_UNEXPECTED);
+      return;
+    }
 
-    nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
-    NS_ENSURE_SUCCESS(rv, rv);
+    rv = secMan->GetSubjectPrincipal(getter_AddRefs(principal));
+    if (rv.Failed()) {
+      return;
+    }
 
     // We're called from JS; there better be a subject principal, really.
-    NS_ENSURE_TRUE(principal, NS_ERROR_UNEXPECTED);
+    if (!principal) {
+      rv.Throw(NS_ERROR_UNEXPECTED);
+      return;
+    }
   }
 
-  return Init(principal, aDocumentURI, aBaseURI,
-              scriptContext ? scriptContext->GetGlobalObject() : nullptr);
+  rv = Init(principal, aDocumentURI, aBaseURI,
+            scriptContext ? scriptContext->GetGlobalObject() : nullptr);
 }
 
 nsresult
 nsDOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult)
 {
   nsCOMPtr<nsIScriptGlobalObject> scriptHandlingObject =
     do_QueryReferent(mScriptHandlingObject);
   nsresult rv;
--- a/content/base/src/nsDOMParser.h
+++ b/content/base/src/nsDOMParser.h
@@ -15,50 +15,33 @@
 #include "nsWrapperCache.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/DOMParserBinding.h"
 #include "mozilla/dom/TypedArray.h"
 
 class nsIInputStream;
 
 class nsDOMParser MOZ_FINAL : public nsIDOMParser,
-                              public nsIDOMParserJS,
-                              public nsIJSNativeInitializer,
                               public nsSupportsWeakReference,
                               public nsWrapperCache
 {
 public: 
   nsDOMParser();
   virtual ~nsDOMParser();
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDOMParser,
                                                          nsIDOMParser)
 
   // nsIDOMParser
   NS_DECL_NSIDOMPARSER
 
-  // nsIDOMParserJS
-  NS_DECL_NSIDOMPARSERJS
-
-  // nsIJSNativeInitializer
-  NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
-                        uint32_t argc, jsval *argv);
-
   // WebIDL API
   static already_AddRefed<nsDOMParser>
-  Constructor(nsISupports* aOwner, mozilla::ErrorResult& rv)
-  {
-    nsRefPtr<nsDOMParser> domParser = new nsDOMParser(aOwner);
-    rv = domParser->Initialize(aOwner, nullptr, nullptr, 0, nullptr);
-    if (rv.Failed()) {
-      return nullptr;
-    }
-    return domParser.forget();
-  }
+  Constructor(nsISupports* aOwner, mozilla::ErrorResult& rv);
 
   static already_AddRefed<nsDOMParser>
   Constructor(nsISupports* aOwner, nsIPrincipal* aPrincipal,
               nsIURI* aDocumentURI, nsIURI* aBaseURI,
               mozilla::ErrorResult& rv);
 
   already_AddRefed<nsIDocument>
   ParseFromString(const nsAString& aStr, mozilla::dom::SupportedType aType,
@@ -75,20 +58,17 @@ public:
                   mozilla::ErrorResult& rv);
 
   already_AddRefed<nsIDocument>
   ParseFromStream(nsIInputStream* aStream, const nsAString& aCharset,
                   int32_t aContentLength, mozilla::dom::SupportedType aType,
                   mozilla::ErrorResult& rv);
 
   void Init(nsIPrincipal* aPrincipal, nsIURI* aDocumentURI,
-            nsIURI* aBaseURI, mozilla::ErrorResult& rv)
-  {
-    rv = Init(aPrincipal, aDocumentURI, aBaseURI);
-  }
+            nsIURI* aBaseURI, mozilla::ErrorResult& rv);
 
   nsISupports* GetParentObject() const
   {
     return mOwner;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
                                bool* aTriedToWrap) MOZ_OVERRIDE
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -1704,63 +1704,61 @@ static nsDOMClassInfoData sClassInfoData
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   NS_DEFINE_CLASSINFO_DATA(AudioChannelManager, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
 #endif
 };
 
 #define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id)                           \
-  nsresult                                                                      \
+  static nsresult                                                               \
   _class##Ctor(nsISupports** aInstancePtrResult)                                \
   {                                                                             \
     nsresult rv = NS_OK;                                                        \
     nsCOMPtr<nsISupports> native = do_CreateInstance(_contract_id, &rv);        \
     native.forget(aInstancePtrResult);                                          \
     return rv;                                                                  \
   }
 
-NS_DEFINE_CONTRACT_CTOR(DOMParser, NS_DOMPARSER_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(FileReader, NS_FILEREADER_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(ArchiveReader, NS_ARCHIVEREADER_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(FormData, NS_FORMDATA_CONTRACTID)
-NS_DEFINE_CONTRACT_CTOR(XMLSerializer, NS_XMLSERIALIZER_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(XSLTProcessor,
                         "@mozilla.org/document-transformer;1?type=xslt")
 NS_DEFINE_CONTRACT_CTOR(EventSource, NS_EVENTSOURCE_CONTRACTID)
 NS_DEFINE_CONTRACT_CTOR(MutationObserver, NS_DOMMUTATIONOBSERVER_CONTRACTID)
 #ifdef MOZ_SYS_MSG
 NS_DEFINE_CONTRACT_CTOR(MozActivity, NS_DOMACTIVITY_CONTRACTID)
 #endif
 
 #undef NS_DEFINE_CONTRACT_CTOR
 
 #define NS_DEFINE_EVENT_CTOR(_class)                        \
-  nsresult                                                  \
+  static nsresult                                           \
   NS_DOM##_class##Ctor(nsISupports** aInstancePtrResult)    \
   {                                                         \
-    nsIDOMEvent* e = nullptr;                                \
-    nsresult rv = NS_NewDOM##_class(&e, nullptr, nullptr);    \
+    nsIDOMEvent* e = nullptr;                               \
+    nsresult rv = NS_NewDOM##_class(&e, nullptr, nullptr);  \
     *aInstancePtrResult = e;                                \
     return rv;                                              \
   }
 
 NS_DEFINE_EVENT_CTOR(Event)
 NS_DEFINE_EVENT_CTOR(UIEvent)
 NS_DEFINE_EVENT_CTOR(MouseEvent)
 NS_DEFINE_EVENT_CTOR(WheelEvent)
 
 #define MOZ_GENERATED_EVENT_LIST
 #define MOZ_GENERATED_EVENT(_event_interface) \
   NS_DEFINE_EVENT_CTOR(_event_interface)
 #include "GeneratedEvents.h"
 #undef MOZ_GENERATED_EVENT_LIST
 
-nsresult
+static nsresult
 NS_XMLHttpRequestCtor(nsISupports** aInstancePtrResult)
 {
   nsXMLHttpRequest* xhr = new nsXMLHttpRequest();
   return CallQueryInterface(xhr, aInstancePtrResult);
 }
 
 struct nsConstructorFuncMapData
 {
@@ -1785,31 +1783,32 @@ static const nsConstructorFuncMapData kC
 #ifdef MOZ_B2G_RIL
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozWifiStatusChangeEvent)
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(MozWifiConnectionInfoEvent)
 #endif
 #define MOZ_GENERATED_EVENT_LIST
 #define MOZ_GENERATED_EVENT(_event_interface) \
   NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA(_event_interface)
 #include "GeneratedEvents.h"
+#undef MOZ_GENERATED_EVENT_LIST
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XMLHttpRequest, NS_XMLHttpRequestCtor)
-  NS_DEFINE_CONSTRUCTOR_FUNC_DATA(DOMParser, DOMParserCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FileReader, FileReaderCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ArchiveReader, ArchiveReaderCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FormData, FormDataCtor)
-  NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XMLSerializer, XMLSerializerCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XPathEvaluator, XPathEvaluatorCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(EventSource, EventSourceCtor)
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MutationObserver, MutationObserverCtor)
 #ifdef MOZ_SYS_MSG
   NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozActivity, MozActivityCtor)
 #endif
 };
+#undef NS_DEFINE_CONSTRUCTOR_FUNC_DATA
+#undef NS_DEFINE_EVENT_CONSTRUCTOR_FUNC_DATA
 
 nsIXPConnect *nsDOMClassInfo::sXPConnect = nullptr;
 nsIScriptSecurityManager *nsDOMClassInfo::sSecMan = nullptr;
 bool nsDOMClassInfo::sIsInitialized = false;
 bool nsDOMClassInfo::sDisableDocumentAllSupport = false;
 bool nsDOMClassInfo::sDisableGlobalScopePollutionSupport = false;
 
 
@@ -3925,17 +3924,16 @@ nsDOMClassInfo::Init()
 
   DOM_CLASSINFO_MAP_BEGIN(StorageItem, nsIDOMStorageItem)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorageItem)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMToString)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(DOMParser, nsIDOMParser)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMParser)
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMParserJS)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XMLSerializer, nsIDOMSerializer)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMSerializer)
   DOM_CLASSINFO_MAP_END
 
   DOM_CLASSINFO_MAP_BEGIN(XMLHttpRequest, nsIXMLHttpRequest)
     DOM_CLASSINFO_MAP_ENTRY(nsIXMLHttpRequest)