Bug 818976 - Part 1: Add supplement code and new tree op to support generated code in HTML5 parser. r=hsivonen
authorWilliam Chen <wchen@mozilla.com>
Tue, 26 Mar 2013 00:15:23 -0700
changeset 126205 a9862de183ff
parent 126204 ef964d6a833b
child 126206 f704985a8246
push id25348
push userwchen@mozilla.com
push dateTue, 26 Mar 2013 07:18:51 +0000
treeherdermozilla-inbound@833a9f1cce27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs818976
milestone22.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 818976 - Part 1: Add supplement code and new tree op to support generated code in HTML5 parser. r=hsivonen
parser/html/nsHtml5ArrayCopy.h
parser/html/nsHtml5TreeBuilderCppSupplement.h
parser/html/nsHtml5TreeBuilderHSupplement.h
parser/html/nsHtml5TreeOperation.cpp
parser/html/nsHtml5TreeOperation.h
--- a/parser/html/nsHtml5ArrayCopy.h
+++ b/parser/html/nsHtml5ArrayCopy.h
@@ -42,16 +42,22 @@ class nsHtml5ArrayCopy {
 
     static inline void
     arraycopy(PRUnichar* source, PRUnichar* target, int32_t length)
     {
       memcpy(target, source, length * sizeof(PRUnichar));
     }
 
     static inline void
+    arraycopy(int32_t* source, int32_t* target, int32_t length)
+    {
+      memcpy(target, source, length * sizeof(int32_t));
+    }
+
+    static inline void
     arraycopy(nsString** source, nsString** target, int32_t length)
     {
       memcpy(target, source, length * sizeof(nsString*));
     }
 
     static inline void
     arraycopy(nsHtml5AttributeName** source, nsHtml5AttributeName** target, int32_t length)
     {
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -748,16 +748,26 @@ nsHtml5TreeBuilder::StartPlainTextBody()
 void
 nsHtml5TreeBuilder::documentMode(nsHtml5DocumentMode m)
 {
   nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
   NS_ASSERTION(treeOp, "Tree op allocation failed.");
   treeOp->Init(m);
 }
 
+nsIContent**
+nsHtml5TreeBuilder::getDocumentFragmentForTemplate(nsIContent** aTemplate)
+{
+  nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
+  NS_ASSERTION(treeOp, "Tree op allocation failed.");
+  nsIContent** fragHandle = AllocateContentHandle();
+  treeOp->Init(eTreeOpGetDocumentFragmentForTemplate, aTemplate, fragHandle);
+  return fragHandle;
+}
+
 // Error reporting
 
 void
 nsHtml5TreeBuilder::EnableViewSource(nsHtml5Highlighter* aHighlighter)
 {
   mViewSource = aHighlighter;
 }
 
--- a/parser/html/nsHtml5TreeBuilderHSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderHSupplement.h
@@ -21,16 +21,18 @@
 #endif
 
     // DocumentModeHandler
     /**
      * Tree builder uses this to report quirkiness of the document
      */
     void documentMode(nsHtml5DocumentMode m);
 
+    nsIContent** getDocumentFragmentForTemplate(nsIContent** aTemplate);
+
     /**
      * Using nsIContent** instead of nsIContent* is the parser deals with DOM
      * nodes in a way that works off the main thread. Non-main-thread code
      * can't refcount or otherwise touch nsIContent objects in any way.
      * Yet, the off-the-main-thread code needs to have a way to hold onto a
      * particular node and repeatedly operate on the same node.
      *
      * The way this works is that the off-the-main-thread code has an
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -26,16 +26,17 @@
 #include "nsIDOMDocumentType.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
 #include "nsIMutationObserver.h"
 #include "nsIFormProcessor.h"
 #include "nsIServiceManager.h"
 #include "nsEscape.h"
 #include "mozilla/dom/Element.h"
+#include "mozilla/dom/HTMLTemplateElement.h"
 #include "nsHtml5SVGLoadDispatcher.h"
 #include "nsIURI.h"
 #include "nsIProtocolHandler.h"
 #include "nsNetUtil.h"
 #include "nsIHTMLDocument.h"
 #include "mozilla/Likely.h"
 
 namespace dom = mozilla::dom;
@@ -553,16 +554,23 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
                             name,
                             publicId,
                             systemId,
                             voidString);
       NS_ASSERTION(docType, "Doctype creation failed.");
       nsCOMPtr<nsIContent> asContent = do_QueryInterface(docType);
       return AppendToDocument(asContent, aBuilder);
     }
+    case eTreeOpGetDocumentFragmentForTemplate: {
+      dom::HTMLTemplateElement* tempElem =
+        static_cast<dom::HTMLTemplateElement*>(*mOne.node);
+      nsRefPtr<dom::DocumentFragment> frag = tempElem->Content();
+      *mTwo.node = frag.get();
+      return rv;
+    }
     case eTreeOpMarkAsBroken: {
       aBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
       return rv;
     }
     case eTreeOpRunScript: {
       nsIContent* node = *(mOne.node);
       nsAHtml5TreeBuilderState* snapshot = mTwo.state;
       if (snapshot) {
@@ -806,8 +814,9 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       return rv;
     }
     default: {
       NS_NOTREACHED("Bogus tree op");
     }
   }
   return rv; // keep compiler happy
 }
+
--- a/parser/html/nsHtml5TreeOperation.h
+++ b/parser/html/nsHtml5TreeOperation.h
@@ -29,16 +29,17 @@ enum eHtml5TreeOperation {
   eTreeOpCreateElementNotNetwork,
   eTreeOpSetFormElement,
   eTreeOpAppendText,
   eTreeOpAppendIsindexPrompt,
   eTreeOpFosterParentText,
   eTreeOpAppendComment,
   eTreeOpAppendCommentToDocument,
   eTreeOpAppendDoctypeToDocument,
+  eTreeOpGetDocumentFragmentForTemplate,
   // Gecko-specific on-pop ops
   eTreeOpMarkAsBroken,
   eTreeOpRunScript,
   eTreeOpRunScriptAsyncDefer,
   eTreeOpPreventScriptExecution,
   eTreeOpDoneAddingChildren,
   eTreeOpDoneCreatingElement,
   eTreeOpFlushPendingAppendNotifications,