Bug 824823 part 8. Convert nsTextNode to WebIDL. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 04 Jan 2013 12:02:14 -0500
changeset 126734 ee0e5b1c16403356bf3d542a084a8fe73350a36c
parent 126733 71b8063ba668d11a94e861c2108227503fc8da8e
child 126735 2861abcd2d7936f8899170a8cb6d1f59f4acd8ef
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 8. Convert nsTextNode to WebIDL. r=peterv
content/base/src/nsTextNode.cpp
content/base/src/nsTextNode.h
dom/bindings/Bindings.conf
dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
dom/webidl/Document.webidl
dom/webidl/Text.webidl
dom/webidl/WebIDL.mk
--- a/content/base/src/nsTextNode.cpp
+++ b/content/base/src/nsTextNode.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 /*
  * Implementation of DOM Core's nsIDOMText node.
  */
 
 #include "nsTextNode.h"
+#include "mozilla/dom/TextBinding.h"
 #include "nsContentUtils.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMMutationEvent.h"
 #include "nsIDocument.h"
 #include "nsThreadUtils.h"
 #include "nsStubMutationObserver.h"
 #ifdef DEBUG
@@ -107,23 +108,16 @@ NS_NewTextNode(nsIContent** aInstancePtr
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(*aInstancePtrResult = instance);
 
   return NS_OK;
 }
 
-nsTextNode::nsTextNode(already_AddRefed<nsINodeInfo> aNodeInfo)
-  : nsGenericDOMDataNode(aNodeInfo)
-{
-  NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE,
-                    "Bad NodeType in aNodeInfo");
-}
-
 nsTextNode::~nsTextNode()
 {
 }
 
 NS_IMPL_ADDREF_INHERITED(nsTextNode, nsGenericDOMDataNode)
 NS_IMPL_RELEASE_INHERITED(nsTextNode, nsGenericDOMDataNode)
 
 DOMCI_NODE_DATA(Text, nsTextNode)
@@ -131,16 +125,22 @@ DOMCI_NODE_DATA(Text, nsTextNode)
 // QueryInterface implementation for nsTextNode
 NS_INTERFACE_TABLE_HEAD(nsTextNode)
   NS_NODE_INTERFACE_TABLE3(nsTextNode, nsIDOMNode, nsIDOMText,
                            nsIDOMCharacterData)
   NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsTextNode)
   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Text)
 NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
 
+JSObject*
+nsTextNode::WrapNode(JSContext *aCx, JSObject *aScope, bool *aTriedToWrap)
+{
+  return TextBinding::Wrap(aCx, aScope, this, aTriedToWrap);
+}
+
 bool
 nsTextNode::IsNodeOfType(uint32_t aFlags) const
 {
   return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE));
 }
 
 nsGenericDOMDataNode*
 nsTextNode::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
@@ -180,16 +180,27 @@ nsTextNode::BindToTree(nsIDocument* aDoc
 
 void nsTextNode::UnbindFromTree(bool aDeep, bool aNullParent)
 {
   ResetDirectionSetByTextNode(this);
 
   nsGenericDOMDataNode::UnbindFromTree(aDeep, aNullParent);
 }
 
+already_AddRefed<nsTextNode>
+nsTextNode::SplitText(uint32_t aOffset, ErrorResult& rv)
+{
+  nsCOMPtr<nsIContent> newChild;
+  rv = SplitData(aOffset, getter_AddRefs(newChild));
+  if (rv.Failed()) {
+    return nullptr;
+  }
+  return static_cast<nsTextNode*>(newChild.forget().get());
+}
+
 #ifdef DEBUG
 void
 nsTextNode::List(FILE* out, int32_t aIndent) const
 {
   int32_t index;
   for (index = aIndent; --index >= 0; ) fputs("  ", out);
 
   fprintf(out, "Text@%p", static_cast<const void*>(this));
@@ -325,8 +336,9 @@ void
 nsAttributeTextNode::UpdateText(bool aNotify)
 {
   if (mGrandparent) {
     nsAutoString attrValue;
     mGrandparent->GetAttr(mNameSpaceID, mAttrName, attrValue);
     SetText(attrValue, aNotify);
   }  
 }
+
--- a/content/base/src/nsTextNode.h
+++ b/content/base/src/nsTextNode.h
@@ -1,28 +1,39 @@
 /* -*- Mode: C++; 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/. */
 
+#ifndef nsTextNode_h
+#define nsTextNode_h
+
 /*
  * Implementation of DOM Core's nsIDOMText node.
  */
 
 #include "nsGenericDOMDataNode.h"
 #include "nsIDOMText.h"
+#include "nsDebug.h"
 
 /**
  * Class used to implement DOM text nodes
  */
 class nsTextNode : public nsGenericDOMDataNode,
                    public nsIDOMText
 {
 public:
-  nsTextNode(already_AddRefed<nsINodeInfo> aNodeInfo);
+  nsTextNode(already_AddRefed<nsINodeInfo> aNodeInfo)
+    : nsGenericDOMDataNode(aNodeInfo)
+  {
+    NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE,
+                      "Bad NodeType in aNodeInfo");
+    SetIsDOMBinding();
+  }
+
   virtual ~nsTextNode();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMNode
   NS_FORWARD_NSIDOMNODE_TO_NSINODE
 
@@ -46,13 +57,27 @@ public:
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true);
 
   nsresult AppendTextForNormalize(const PRUnichar* aBuffer, uint32_t aLength,
                                   bool aNotify, nsIContent* aNextSibling);
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 
+  // WebIDL API
+  already_AddRefed<nsTextNode> SplitText(uint32_t aOffset,
+                                         mozilla::ErrorResult& rv);
+  void GetWholeText(nsAString& aWholeText, mozilla::ErrorResult& rv)
+  {
+    rv = GetWholeText(aWholeText);
+  }
+
 #ifdef DEBUG
   virtual void List(FILE* out, int32_t aIndent) const;
   virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const;
 #endif
+
+protected:
+  virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope,
+                             bool *aTriedToWrap) MOZ_OVERRIDE;
 };
+
+#endif // nsTextNode_h
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -141,16 +141,17 @@ DOMInterfaces = {
 'CaretPosition' : {                                                            
     'nativeType': 'nsDOMCaretPosition',                                        
 },                                                                             
 
 'CharacterData': {
     'nativeType': 'nsGenericDOMDataNode',
     'hasXPConnectImpls': True,
     'hasInstanceInterface': 'nsIDOMCharacterData',
+    'concrete': False
 },
 
 'ClientRectList': {
     'nativeType': 'nsClientRectList',
     'headerFile': 'nsClientRect.h',
     'resultNotAddRefed': [ 'item' ]
 },
 
@@ -699,16 +700,21 @@ DOMInterfaces = {
 },
 
 'SVGTransformList': {
     'nativeType': 'mozilla::DOMSVGTransformList',
     'headerFile': 'DOMSVGTransformList.h',
     'resultNotAddRefed': [ 'getItem' ]
 },
 
+'Text': {
+    'nativeType': 'nsTextNode',
+    'hasInstanceInterface': 'nsIDOMText',
+},
+
 'TextDecoder': [
 {
     'workers': True,
 }],
 
 'TextEncoder': [
 {
     'implicitJSContext': [ 'encode' ],
@@ -1090,17 +1096,16 @@ addExternalIface('Principal', nativeType
 addExternalIface('ProcessingInstruction', nativeType='nsXMLProcessingInstruction')
 addExternalIface('Range', nativeType='nsRange')
 addExternalIface('Selection', nativeType='nsISelection')
 addExternalIface('StyleSheetList')
 addExternalIface('SVGAnimatedString')
 addExternalIface('SVGLength')
 addExternalIface('SVGNumber')
 addExternalIface('SVGSVGElement', nativeType='nsSVGSVGElement')
-addExternalIface('Text', nativeType='nsTextNode')
 addExternalIface('TextMetrics', headerFile='nsIDOMCanvasRenderingContext2D.h')
 addExternalIface('TreeWalker')
 addExternalIface('Touch', headerFile='nsIDOMTouchEvent.h')
 addExternalIface('TouchList', headerFile='nsIDOMTouchEvent.h')
 addExternalIface('URI', nativeType='nsIURI', headerFile='nsIURI.h',
                  notflattened=True)
 addExternalIface('UserDataHandler')
 addExternalIface('Window')
--- a/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
+++ b/dom/imptests/failures/webapps/DOMCore/tests/approved/test_interfaces.html.json
@@ -87,31 +87,17 @@
   "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: 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,
-  "CharacterData interface: calling appendData(DOMString) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
-  "CharacterData interface: calling insertData(unsigned long,DOMString) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
-  "CharacterData interface: calling deleteData(unsigned long,unsigned long) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
-  "CharacterData interface: calling replaceData(unsigned long,unsigned long,DOMString) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
   "CharacterData interface: document.createTextNode(\"abc\") must inherit property \"remove\" with the proper type (7)": true,
-  "EventTarget interface: calling addEventListener(DOMString,EventListener,boolean) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
-  "EventTarget interface: calling removeEventListener(DOMString,EventListener,boolean) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
-  "EventTarget interface: calling dispatchEvent(Event) on document.createTextNode(\"abc\") with too few arguments must throw TypeError": true,
   "ProcessingInstruction interface: existence and properties of interface object": true,
   "ProcessingInstruction interface: existence and properties of interface prototype object": true,
   "ProcessingInstruction interface: existence and properties of interface prototype object's \"constructor\" property": true,
   "ProcessingInstruction interface: attribute target": true,
   "Stringification of xmlDoc.createProcessingInstruction(\"abc\", \"def\")": "debug",
   "CharacterData interface: calling substringData(unsigned long,unsigned long) on xmlDoc.createProcessingInstruction(\"abc\", \"def\") with too few arguments must throw TypeError": true,
   "CharacterData interface: calling appendData(DOMString) on xmlDoc.createProcessingInstruction(\"abc\", \"def\") with too few arguments must throw TypeError": true,
   "CharacterData interface: calling insertData(unsigned long,DOMString) on xmlDoc.createProcessingInstruction(\"abc\", \"def\") with too few arguments must throw TypeError": true,
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -17,17 +17,16 @@
 
 interface Attr;
 interface CDATASection;
 interface Comment;
 interface NodeIterator;
 interface ProcessingInstruction;
 interface Range;
 interface StyleSheetList;
-interface Text;
 interface Touch;
 interface TouchList;
 interface TreeWalker;
 interface WindowProxy;
 interface nsISupports;
 
 enum VisibilityState { "hidden", "visible" };
 
--- a/dom/webidl/Text.webidl
+++ b/dom/webidl/Text.webidl
@@ -6,11 +6,13 @@
  * The origin of this IDL file is
  * http://www.w3.org/TR/2012/WD-dom-20120105/
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 interface Text : CharacterData {
+  [Throws]
   Text splitText(unsigned long offset);
+  [Throws]
   readonly attribute DOMString wholeText;
 };
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -97,16 +97,17 @@ webidl_files = \
   SVGNumberList.webidl \
   SVGPathSeg.webidl \
   SVGPathSegList.webidl \
   SVGPoint.webidl \
   SVGPointList.webidl \
   SVGPreserveAspectRatio.webidl \
   SVGTransform.webidl \
   SVGTransformList.webidl \
+  Text.webidl \
   TextDecoder.webidl \
   TextEncoder.webidl \
   URL.webidl \
   WebSocket.webidl \
   XMLHttpRequest.webidl \
   XMLHttpRequestEventTarget.webidl \
   XMLHttpRequestUpload.webidl \
   XMLSerializer.webidl \