Bug 824603 Part 1: Enable binding for DocumentType r=bz
authorDavid Zbarsky <dzbarsky@gmail.com>
Fri, 28 Dec 2012 20:34:02 -0500
changeset 126309 0ed0898de7b509b5fe273b760c351ac64b79ef1c
parent 126308 abfe3957551b2a11ba2dc601a0d5a24ba24e8f38
child 126310 d128b15214cb806f604b9caab653485c28e07a8a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs824603
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 824603 Part 1: Enable binding for DocumentType r=bz
content/base/src/DOMImplementation.cpp
content/base/src/DOMImplementation.h
content/base/src/nsDOMDocumentType.cpp
content/base/src/nsDOMDocumentType.h
dom/bindings/Bindings.conf
dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
dom/webidl/DOMImplementation.webidl
dom/webidl/DocumentType.webidl
dom/webidl/WebIDL.mk
--- a/content/base/src/DOMImplementation.cpp
+++ b/content/base/src/DOMImplementation.cpp
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/DOMImplementation.h"
 
 #include "mozilla/dom/DOMImplementationBinding.h"
 #include "nsContentCreatorFunctions.h"
 #include "nsContentUtils.h"
 #include "nsDOMClassInfoID.h"
-#include "nsIDOMDocumentType.h"
+#include "nsDOMDocumentType.h"
 
 namespace mozilla {
 namespace dom {
 
 // QueryInterface implementation for DOMImplementation
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMImplementation)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIDOMDOMImplementation)
@@ -45,47 +45,54 @@ NS_IMETHODIMP
 DOMImplementation::HasFeature(const nsAString& aFeature,
                               const nsAString& aVersion,
                               bool* aReturn)
 {
   *aReturn = HasFeature(aFeature, aVersion);
   return NS_OK;
 }
 
-already_AddRefed<nsIDOMDocumentType>
+already_AddRefed<nsDOMDocumentType>
 DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
                                       const nsAString& aPublicId,
                                       const nsAString& aSystemId,
                                       ErrorResult& aRv)
 {
-  nsCOMPtr<nsIDOMDocumentType> doctype;
-  aRv = CreateDocumentType(aQualifiedName, aPublicId, aSystemId,
-                           getter_AddRefs(doctype));
-  return doctype.forget();
+  if (!mOwner) {
+    aRv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
+
+  aRv = nsContentUtils::CheckQName(aQualifiedName);
+  if (aRv.Failed()) {
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIAtom> name = do_GetAtom(aQualifiedName);
+  if (!name) {
+    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
+    return nullptr;
+  }
+
+  // Indicate that there is no internal subset (not just an empty one)
+  nsRefPtr<nsDOMDocumentType> docType =
+    NS_NewDOMDocumentType(mOwner->NodeInfoManager(), name, aPublicId,
+                          aSystemId, NullString(), aRv);
+  return docType.forget();
 }
 
 NS_IMETHODIMP
 DOMImplementation::CreateDocumentType(const nsAString& aQualifiedName,
                                       const nsAString& aPublicId,
                                       const nsAString& aSystemId,
                                       nsIDOMDocumentType** aReturn)
 {
-  *aReturn = nullptr;
-  NS_ENSURE_STATE(mOwner);
-
-  nsresult rv = nsContentUtils::CheckQName(aQualifiedName);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIAtom> name = do_GetAtom(aQualifiedName);
-  NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
-
-  // Indicate that there is no internal subset (not just an empty one)
-  return NS_NewDOMDocumentType(aReturn, mOwner->NodeInfoManager(),
-                               name, aPublicId,
-                               aSystemId, NullString());
+  ErrorResult rv;
+  *aReturn = CreateDocumentType(aQualifiedName, aPublicId, aSystemId, rv).get();
+  return rv.ErrorCode();
 }
 
 nsresult
 DOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
                                   const nsAString& aQualifiedName,
                                   nsIDOMDocumentType* aDoctype,
                                   nsIDocument** aDocument,
                                   nsIDOMDocument** aDOMDocument)
--- a/content/base/src/DOMImplementation.h
+++ b/content/base/src/DOMImplementation.h
@@ -14,17 +14,17 @@
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDocument.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIURI.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsStringGlue.h"
 
 class nsIDOMDocument;
-class nsIDOMDocumentType;
+class nsDOMDocumentType;
 
 namespace mozilla {
 namespace dom {
 
 class DOMImplementation MOZ_FINAL : public nsIDOMDOMImplementation
                                   , public nsWrapperCache
 {
 public:
@@ -56,17 +56,17 @@ public:
   virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
                                bool* aTriedToWrap) MOZ_OVERRIDE;
 
   // nsIDOMDOMImplementation
   NS_DECL_NSIDOMDOMIMPLEMENTATION
 
   bool HasFeature(const nsAString& aFeature, const nsAString& aVersion);
 
-  already_AddRefed<nsIDOMDocumentType>
+  already_AddRefed<nsDOMDocumentType>
   CreateDocumentType(const nsAString& aQualifiedName,
                      const nsAString& aPublicId,
                      const nsAString& aSystemId,
                      ErrorResult& aRv);
 
   already_AddRefed<nsIDocument>
   CreateDocument(const nsAString& aNamespaceURI,
                  const nsAString& aQualifiedName,
--- a/content/base/src/nsDOMDocumentType.cpp
+++ b/content/base/src/nsDOMDocumentType.cpp
@@ -12,51 +12,79 @@
 #include "nsIDOMNamedNodeMap.h"
 #include "nsGkAtoms.h"
 #include "nsCOMPtr.h"
 #include "nsDOMString.h"
 #include "nsNodeInfoManager.h"
 #include "nsIXPConnect.h"
 #include "xpcpublic.h"
 #include "nsWrapperCacheInlines.h"
+#include "mozilla/dom/DocumentTypeBinding.h"
+
+using namespace mozilla;
+
+JSObject*
+nsDOMDocumentType::WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap)
+{
+  return dom::DocumentTypeBinding::Wrap(cx, scope, this, triedToWrap);
+}
 
 nsresult
 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
                       nsNodeInfoManager *aNodeInfoManager,
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset)
 {
   NS_ENSURE_ARG_POINTER(aDocType);
-  NS_ENSURE_ARG_POINTER(aName);
+  ErrorResult rv;
+  *aDocType = NS_NewDOMDocumentType(aNodeInfoManager, aName, aPublicId,
+                                    aSystemId, aInternalSubset, rv).get();
+  return rv.ErrorCode();
+}
+
+already_AddRefed<nsDOMDocumentType>
+NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager,
+                      nsIAtom *aName,
+                      const nsAString& aPublicId,
+                      const nsAString& aSystemId,
+                      const nsAString& aInternalSubset,
+                      ErrorResult& rv)
+{
+  if (!aName) {
+    rv.Throw(NS_ERROR_INVALID_POINTER);
+    return nullptr;
+  }
 
   nsCOMPtr<nsINodeInfo> ni =
     aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nullptr,
                                   kNameSpaceID_None,
                                   nsIDOMNode::DOCUMENT_TYPE_NODE,
                                   aName);
-  NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
+  if (!ni) {
+    rv.Throw(NS_ERROR_OUT_OF_MEMORY);
+    return nullptr;
+  }
 
-  *aDocType = new nsDOMDocumentType(ni.forget(), aPublicId, aSystemId,
-                                    aInternalSubset);
-  NS_ADDREF(*aDocType);
-
-  return NS_OK;
+  nsRefPtr<nsDOMDocumentType> docType =
+    new nsDOMDocumentType(ni.forget(), aPublicId, aSystemId, aInternalSubset);
+  return docType.forget();
 }
 
 nsDOMDocumentType::nsDOMDocumentType(already_AddRefed<nsINodeInfo> aNodeInfo,
                                      const nsAString& aPublicId,
                                      const nsAString& aSystemId,
                                      const nsAString& aInternalSubset) :
   nsDOMDocumentTypeForward(aNodeInfo),
   mPublicId(aPublicId),
   mSystemId(aSystemId),
   mInternalSubset(aInternalSubset)
 {
+  SetIsDOMBinding();
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
                     "Bad NodeType in aNodeInfo");
 }
 
 nsDOMDocumentType::~nsDOMDocumentType()
 {
 }
 
--- a/content/base/src/nsDOMDocumentType.h
+++ b/content/base/src/nsDOMDocumentType.h
@@ -68,22 +68,33 @@ public:
   virtual const nsTextFragment* GetText();
 
   virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo,
                                               bool aCloneText) const;
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
+
+  virtual JSObject* WrapNode(JSContext *cx, JSObject *scope, bool *triedToWrap);
+
 protected:
   nsString mPublicId;
   nsString mSystemId;
   nsString mInternalSubset;
 };
 
+already_AddRefed<nsDOMDocumentType>
+NS_NewDOMDocumentType(nsNodeInfoManager* aNodeInfoManager,
+                      nsIAtom *aName,
+                      const nsAString& aPublicId,
+                      const nsAString& aSystemId,
+                      const nsAString& aInternalSubset,
+                      mozilla::ErrorResult& rv);
+
 nsresult
 NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
                       nsNodeInfoManager* aNodeInfoManager,
                       nsIAtom *aName,
                       const nsAString& aPublicId,
                       const nsAString& aSystemId,
                       const nsAString& aInternalSubset);
 
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -201,16 +201,21 @@ DOMInterfaces = {
 'DOMParser': {
     'nativeType': 'nsDOMParser',
 },
 
 'DocumentFragment': {
     'resultNotAddRefed': [ 'querySelector' ]
 },
 
+'DocumentType': {
+    'nativeType': 'nsDOMDocumentType',
+    'hasInstanceInterface': 'nsIDOMDocumentType'
+},
+
 'DOMSettableTokenList': {
     'nativeType': 'nsDOMSettableTokenList',
     'binaryNames': {
         '__stringifier': 'Stringify'
     }
 },
 
 'DOMStringMap': {
@@ -1005,17 +1010,16 @@ addExternalHTMLElement('HTMLVideoElement
 addExternalIface('Attr')
 addExternalIface('CanvasGradient', headerFile='nsIDOMCanvasRenderingContext2D.h')
 addExternalIface('CanvasPattern', headerFile='nsIDOMCanvasRenderingContext2D.h')
 addExternalIface('CDATASection')
 addExternalIface('ClientRect')
 addExternalIface('Comment', nativeType='mozilla::dom::Comment')
 addExternalIface("Counter")
 addExternalIface('CSSRule')
-addExternalIface('DocumentType', headerFile="nsDOMDocumentType.h")
 addExternalIface('DOMRequest')
 addExternalIface('DOMStringList')
 addExternalIface('File')
 addExternalIface('HitRegionOptions', nativeType='nsISupports')
 addExternalIface('HTMLHeadElement', nativeType='mozilla::dom::Element')
 addExternalIface('LockedFile')
 addExternalIface('MediaStream')
 addExternalIface('NamedNodeMap')
--- a/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
+++ b/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
@@ -70,28 +70,18 @@
   "MutationCallback interface: operation handleEvent(MutationRecord,MutationObserver)": true,
   "XMLDocument interface: existence and properties of interface object": true,
   "XMLDocument interface: existence and properties of interface prototype object": true,
   "XMLDocument interface: existence and properties of interface prototype object's \"constructor\" property": true,
   "Stringification of xmlDoc": "debug",
   "EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on xmlDoc with too few arguments must throw TypeError": true,
   "EventTarget interface: calling removeEventListener(DOMString,EventListener,boolean) on xmlDoc with too few arguments must throw TypeError": true,
   "EventTarget interface: calling dispatchEvent(Event) on xmlDoc with too few arguments must throw TypeError": true,
-  "DocumentType interface: existence and properties of interface object": true,
-  "DocumentType interface: existence and properties of interface prototype object": true,
-  "DocumentType interface: existence and properties of interface prototype object's \"constructor\" property": true,
-  "DocumentType interface: attribute name": true,
-  "DocumentType interface: attribute publicId": true,
-  "DocumentType interface: attribute systemId": true,
   "DocumentType interface: operation remove()": true,
-  "Stringification of document.doctype": "debug",
   "DocumentType interface: document.doctype must inherit property \"remove\" with the proper type (3)": true,
-  "EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.doctype with too few arguments must throw TypeError": true,
-  "EventTarget interface: calling removeEventListener(DOMString,EventListener,boolean) on document.doctype with too few arguments must throw TypeError": true,
-  "EventTarget interface: calling dispatchEvent(Event) on document.doctype with too few arguments must throw TypeError": true,
   "Element interface: attribute namespaceURI": true,
   "Element interface: attribute prefix": true,
   "Element interface: attribute localName": true,
   "Element interface: attribute attributes": true,
   "Element interface: attribute className": true,
   "Element interface: operation remove()": true,
   "Element interface: element must inherit property \"className\" with the proper type (5)": true,
   "Element interface: element must inherit property \"remove\" with the proper type (25)": true,
--- a/dom/webidl/DOMImplementation.webidl
+++ b/dom/webidl/DOMImplementation.webidl
@@ -6,18 +6,16 @@
  * The origin of this IDL file is
  * http://dom.spec.whatwg.org/#interface-domimplementation
  *
  * Copyright:
  * To the extent possible under law, the editors have waived all copyright and
  * related or neighboring rights to this work.
  */
 
-interface DocumentType;
-
 interface DOMImplementation {
   boolean hasFeature(DOMString feature,
                      [TreatNullAs=EmptyString] DOMString version);
 
   [Throws]
   DocumentType createDocumentType(DOMString qualifiedName, DOMString publicId,
                                   DOMString systemId);
   [Throws]
--- a/dom/webidl/DocumentType.webidl
+++ b/dom/webidl/DocumentType.webidl
@@ -1,23 +1,28 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/.
  *
  * The origin of this IDL file is
- * http://www.w3.org/TR/2012/WD-dom-20120105/
+ * http://dom.spec.whatwg.org/#documenttype
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface DocumentType : Node {
   readonly attribute DOMString name;
   readonly attribute DOMString publicId;
   readonly attribute DOMString systemId;
 
+  /* Not implemented
   // NEW
   void before((Node or DOMString)... nodes);
   void after((Node or DOMString)... nodes);
   void replace((Node or DOMString)... nodes);
   void remove();
+  */
+
+  // Mozilla extension
+  readonly attribute DOMString? internalSubset;
 };
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -25,16 +25,17 @@ webidl_files = \
   CSS.webidl \
   CSSPrimitiveValue.webidl \
   CSSStyleDeclaration.webidl \
   CSSValue.webidl \
   CSSValueList.webidl \
   DelayNode.webidl \
   Document.webidl \
   DocumentFragment.webidl \
+  DocumentType.webidl \
   DOMImplementation.webidl \
   DOMParser.webidl \
   DOMSettableTokenList.webidl \
   DOMStringMap.webidl \
   DOMTokenList.webidl \
   DynamicsCompressorNode.webidl \
   Element.webidl \
   EventHandler.webidl \