Bug 869002 - DocumentFragment should be constructable, r=Ms2ger
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 23 May 2013 03:59:00 -0700
changeset 133018 7684e8d04352110410c29ca527c6935dc80ffe6b
parent 133017 24d2497e1fa9df98e48481a923204aee034488b4
child 133019 ddcf4ed9674f5c83f1f8f7ab6896212b593ad2a9
push id28557
push userphilringnalda@gmail.com
push dateMon, 27 May 2013 03:45:57 +0000
treeherdermozilla-inbound@7684e8d04352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs869002
milestone24.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 869002 - DocumentFragment should be constructable, r=Ms2ger
content/base/src/DocumentFragment.cpp
content/base/src/DocumentFragment.h
content/base/test/Makefile.in
content/base/test/test_bug869002.html
dom/webidl/DocumentFragment.webidl
--- a/content/base/src/DocumentFragment.cpp
+++ b/content/base/src/DocumentFragment.cpp
@@ -102,16 +102,28 @@ DocumentFragment::DumpContent(FILE* out,
   fputs("</DocumentFragment>", out);
 
   if(aIndent) {
     fputs("\n", out);
   }
 }
 #endif
 
+/* static */ already_AddRefed<DocumentFragment>
+DocumentFragment::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
+{
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.Get());
+  if (!window || !window->GetDoc()) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  return window->GetDoc()->CreateDocumentFragment();
+}
+
 // QueryInterface implementation for DocumentFragment
 NS_INTERFACE_MAP_BEGIN(DocumentFragment)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
   NS_INTERFACE_MAP_ENTRY(nsIContent)
   NS_INTERFACE_MAP_ENTRY(nsINode)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
--- a/content/base/src/DocumentFragment.h
+++ b/content/base/src/DocumentFragment.h
@@ -136,16 +136,19 @@ public:
     return mHost;
   }
 
   void SetHost(HTMLTemplateElement* aHost)
   {
     mHost = aHost;
   }
 
+  static already_AddRefed<DocumentFragment>
+  Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
+
 #ifdef DEBUG
   virtual void List(FILE* out, int32_t aIndent) const;
   virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const;
 #endif
 
 protected:
   nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   mozilla::dom::HTMLTemplateElement* mHost; // Weak
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -623,16 +623,17 @@ MOCHITEST_FILES_C= \
 		file_bothCSPheaders.html \
 		file_bothCSPheaders.html^headers^ \
 		badMessageEvent2.eventsource \
 		badMessageEvent2.eventsource^headers^ \
 		test_object.html \
 		test_bug869006.html \
 		test_bug868999.html \
 		test_bug869000.html \
+		test_bug869002.html \
 		$(NULL)
 
 # OOP tests don't work on Windows (bug 763081) or native-fennec
 # (see Bug 774939)
 ifneq ($(OS_ARCH),WINNT)
 ifndef MOZ_ANDROID_OMTC
 MOCHITEST_FILES_B += \
 		test_messagemanager_assertpermission.html \
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug869002.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=868999
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 868999</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=868999">Mozilla Bug 869002</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 868999 **/
+
+var d = new DocumentFragment();
+ok(d, "DocumentFragment has been created");
+
+document.appendChild(d);
+ok(true, "DocumentFragment has been added to the document");
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/DocumentFragment.webidl
+++ b/dom/webidl/DocumentFragment.webidl
@@ -6,16 +6,17 @@
  * The origin of this IDL file is
  * http://www.w3.org/TR/2012/WD-dom-20120405/#interface-documentfragment
  * http://www.w3.org/TR/2012/WD-selectors-api-20120628/#interface-definitions
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
+[Constructor]
 interface DocumentFragment : Node {
   // NEW
   /*
     FIXME: not implemented yet
 
   void prepend((Node or DOMString)... nodes);
   void append((Node or DOMString)... nodes);
   */