Bug 824823 part 7. Implement WebIDL CharacterData API on nsGenericDOMDataNode. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 04 Jan 2013 12:02:14 -0500
changeset 126733 71b8063ba668d11a94e861c2108227503fc8da8e
parent 126732 b1a25d0475a16b52a6b2f27f8a641bcda6618b14
child 126734 ee0e5b1c16403356bf3d542a084a8fe73350a36c
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)
reviewerspeterv
bugs824823
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 824823 part 7. Implement WebIDL CharacterData API on nsGenericDOMDataNode. r=peterv
content/base/src/nsGenericDOMDataNode.cpp
content/base/src/nsGenericDOMDataNode.h
dom/bindings/Bindings.conf
dom/bindings/Codegen.py
dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in
dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_interfaces.html.json
dom/webidl/CharacterData.webidl
dom/webidl/WebIDL.mk
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -171,39 +171,47 @@ nsGenericDOMDataNode::GetLength(uint32_t
   *aLength = mText.GetLength();
   return NS_OK;
 }
 
 nsresult
 nsGenericDOMDataNode::SubstringData(uint32_t aStart, uint32_t aCount,
                                     nsAString& aReturn)
 {
+  ErrorResult rv;
+  SubstringData(aStart, aCount, aReturn, rv);
+  return rv.ErrorCode();
+}
+
+void
+nsGenericDOMDataNode::SubstringData(uint32_t aStart, uint32_t aCount,
+                                    nsAString& aReturn, ErrorResult& rv)
+{
   aReturn.Truncate();
 
   uint32_t textLength = mText.GetLength();
   if (aStart > textLength) {
-    return NS_ERROR_DOM_INDEX_SIZE_ERR;
+    rv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    return;
   }
 
   uint32_t amount = aCount;
   if (amount > textLength - aStart) {
     amount = textLength - aStart;
   }
 
   if (mText.Is2b()) {
     aReturn.Assign(mText.Get2b() + aStart, amount);
   } else {
     // Must use Substring() since nsDependentCString() requires null
     // terminated strings.
 
     const char *data = mText.Get1b() + aStart;
     CopyASCIItoUTF16(Substring(data, data + amount), aReturn);
   }
-
-  return NS_OK;
 }
 
 //----------------------------------------------------------------------
 
 nsresult
 nsGenericDOMDataNode::AppendData(const nsAString& aData)
 {
   return SetTextInternal(mText.GetLength(), 0, aData.BeginReading(),
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -163,16 +163,44 @@ public:
     NS_ADDREF(*aResult);
 
     return NS_OK;
   }
 
   nsresult SplitData(uint32_t aOffset, nsIContent** aReturn,
                      bool aCloneAfterOriginal = true);
 
+  // WebIDL API
+  // Our XPCOM GetData is just fine for WebIDL
+  void SetData(const nsAString& aData, mozilla::ErrorResult& rv)
+  {
+    rv = SetData(aData);
+  }
+  // nsINode::Length() returns the right thing for our length attribute
+  void SubstringData(uint32_t aStart, uint32_t aCount, nsAString& aReturn,
+                     mozilla::ErrorResult& rv);
+  void AppendData(const nsAString& aData, mozilla::ErrorResult& rv)
+  {
+    rv = AppendData(aData);
+  }
+  void InsertData(uint32_t aOffset, const nsAString& aData,
+                  mozilla::ErrorResult& rv)
+  {
+    rv = InsertData(aOffset, aData);
+  }
+  void DeleteData(uint32_t aOffset, uint32_t aCount, mozilla::ErrorResult& rv)
+  {
+    rv = DeleteData(aOffset, aCount);
+  }
+  void ReplaceData(uint32_t aOffset, uint32_t aCount, const nsAString& aData,
+                   mozilla::ErrorResult& rv)
+  {
+    rv = ReplaceData(aOffset, aCount, aData);
+  }
+
   //----------------------------------------
 
 #ifdef DEBUG
   void ToCString(nsAString& aBuf, int32_t aOffset, int32_t aLen) const;
 #endif
 
   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsGenericDOMDataNode)
 
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -137,16 +137,22 @@ DOMInterfaces = {
         'mozFillRule': 'fillRule'
     }
 },
 
 'CaretPosition' : {                                                            
     'nativeType': 'nsDOMCaretPosition',                                        
 },                                                                             
 
+'CharacterData': {
+    'nativeType': 'nsGenericDOMDataNode',
+    'hasXPConnectImpls': True,
+    'hasInstanceInterface': 'nsIDOMCharacterData',
+},
+
 'ClientRectList': {
     'nativeType': 'nsClientRectList',
     'headerFile': 'nsClientRect.h',
     'resultNotAddRefed': [ 'item' ]
 },
 
 'CSS': {
     'concrete': False,
@@ -449,16 +455,17 @@ DOMInterfaces = {
     'nativeType': 'nsDOMMutationRecord',
     'headerFile': 'nsDOMMutationObserver.h',
     'resultNotAddRefed': [ 'target', 'addedNodes', 'removedNodes',
                            'previousSibling', 'nextSibling' ]
 },
 
 'Node': {
     'nativeType': 'nsINode',
+    'concrete': False,
     'hasXPConnectImpls': True,
     'hasInstanceInterface': 'nsIDOMNode',
     'resultNotAddRefed': [ 'ownerDocument', 'parentNode', 'parentElement',
                            'childNodes', 'firstChild', 'lastChild',
                            'previousSibling', 'nextSibling', 'insertBefore',
                            'appendChild', 'replaceChild', 'removeChild',
                            'attributes' ]
 },
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -475,16 +475,20 @@ class CGHeaders(CGWrapper):
                 ancestors.append(iface.parent)
                 iface = iface.parent
         interfaceDeps.extend(ancestors)
         bindingIncludes = set(self.getDeclarationFilename(d) for d in interfaceDeps)
 
         # Grab all the implementation declaration files we need.
         implementationIncludes = set(d.headerFile for d in descriptors)
 
+        # Grab the includes for the things that involve hasInstanceInterface
+        hasInstanceIncludes = set(d.hasInstanceInterface + ".h" for d
+                                  in descriptors if d.hasInstanceInterface)
+
         # Now find all the things we'll need as arguments because we
         # need to wrap or unwrap them.
         bindingHeaders = set()
         def addHeadersForType(t, descriptor=None, dictionary=None):
             """
             Add the relevant headers for this type.  We use descriptor and
             dictionary, if passed, to decide what to do with interface types.
             """
@@ -536,16 +540,17 @@ class CGHeaders(CGWrapper):
         # Let the machinery do its thing.
         def _includeString(includes):
             return ''.join(['#include "%s"\n' % i for i in includes]) + '\n'
         CGWrapper.__init__(self, child,
                            declarePre=_includeString(sorted(declareIncludes)),
                            definePre=_includeString(sorted(set(defineIncludes) |
                                                            bindingIncludes |
                                                            bindingHeaders |
+                                                           hasInstanceIncludes |
                                                            implementationIncludes)))
     @staticmethod
     def getDeclarationFilename(decl):
         # Use our local version of the header, not the exported one, so that
         # test bindings, which don't export, will work correctly.
         basename = os.path.basename(decl.filename())
         return basename.replace('.webidl', 'Binding.h')
 
--- a/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
+++ b/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
@@ -86,26 +86,16 @@
   "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,
   "Attr interface: existence and properties of interface object": true,
   "Attr interface: existence and properties of interface prototype object": true,
   "Attr interface: existence and properties of interface prototype object's \"constructor\" property": true,
   "Attr interface: attribute name": true,
   "Attr interface: attribute value": true,
   "Stringification of document.querySelector(\"[id]\").attributes[0]": "debug",
-  "CharacterData interface: existence and properties of interface object": true,
-  "CharacterData interface: existence and properties of interface prototype object": true,
-  "CharacterData interface: existence and properties of interface prototype object's \"constructor\" property": true,
-  "CharacterData interface: attribute data": true,
-  "CharacterData interface: attribute length": true,
-  "CharacterData interface: operation substringData(unsigned long,unsigned long)": true,
-  "CharacterData interface: operation appendData(DOMString)": true,
-  "CharacterData interface: operation insertData(unsigned long,DOMString)": true,
-  "CharacterData interface: operation deleteData(unsigned long,unsigned long)": true,
-  "CharacterData interface: operation replaceData(unsigned long,unsigned long,DOMString)": true,
   "CharacterData interface: operation remove()": true,
   "Text interface: existence and properties of interface object": true,
   "Text interface: existence and properties of interface prototype object": true,
   "Text interface: existence and properties of interface prototype object's \"constructor\" property": true,
   "Text interface: attribute wholeText": true,
   "Stringification of document.createTextNode(\"abc\")": "debug",
   "Text interface: calling splitText(unsigned long) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
   "CharacterData interface: calling substringData(unsigned long,unsigned long) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
--- a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in
+++ b/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/Makefile.in
@@ -28,12 +28,11 @@ MOCHITEST_FILES := \
   test_Range-attributes.html.json \
   test_Range-commonAncestorContainer.html.json \
   test_Range-comparePoint.html.json \
   test_Range-detach.html.json \
   test_Range-intersectsNode-binding.html.json \
   test_attributes.html.json \
   test_case.html.json \
   test_historical.html.json \
-  test_interfaces.html.json \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/dom/imptests/failures/webapps/DOMCore/tests/submissions/Ms2ger/test_interfaces.html.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  "Should be able to delete CharacterData.": true
-}
--- a/dom/webidl/CharacterData.webidl
+++ b/dom/webidl/CharacterData.webidl
@@ -1,27 +1,26 @@
 /* -*- 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/#characterdata
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface CharacterData : Node {
-  [TreatNullAs=EmptyString] attribute DOMString data;
+  [TreatNullAs=EmptyString,SetterThrows] attribute DOMString data;
   readonly attribute unsigned long length;
+  [Throws]
   DOMString substringData(unsigned long offset, unsigned long count);
+  [Throws]
   void appendData(DOMString data);
+  [Throws]
   void insertData(unsigned long offset, DOMString data);
+  [Throws]
   void deleteData(unsigned long offset, unsigned long count);
+  [Throws]
   void replaceData(unsigned long offset, unsigned long count, DOMString data);
-
-  // NEW
-  void before((Node or DOMString)... nodes);
-  void after((Node or DOMString)... nodes);
-  void replace((Node or DOMString)... nodes);
-  void remove();
 };
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -16,16 +16,17 @@ webidl_files = \
   AudioListener.webidl \
   AudioNode.webidl \
   AudioParam.webidl \
   AudioSourceNode.webidl \
   BiquadFilterNode.webidl \
   Blob.webidl \
   CanvasRenderingContext2D.webidl \
   CaretPosition.webidl \
+  CharacterData.webidl \
   ClientRectList.webidl \
   CSS.webidl \
   CSSPrimitiveValue.webidl \
   CSSStyleDeclaration.webidl \
   CSSValue.webidl \
   CSSValueList.webidl \
   DelayNode.webidl \
   Document.webidl \