Bug 1424220 - Set mCurrentHtmlScriptIsAsyncOrDefer to false when restoring tree builder state. draft
authorHenri Sivonen <hsivonen@hsivonen.fi>
Mon, 15 Jan 2018 20:07:28 +0200
changeset 720490 ccb0235f6407a4fd48ac0064fee058dd2e665f49
parent 720439 d350d4735de6bdc5184abfdb3fe9a7f3108c349e
child 746083 9ab497115a3662d9afea06d7b4bd02aa751be4dd
push id95564
push userbmo:hsivonen@hsivonen.fi
push dateMon, 15 Jan 2018 18:07:47 +0000
bugs1424220
milestone59.0a1
Bug 1424220 - Set mCurrentHtmlScriptIsAsyncOrDefer to false when restoring tree builder state. MozReview-Commit-ID: 9gsFme52mOG
parser/html/javasrc/TreeBuilder.java
parser/html/nsHtml5AttributeName.h
parser/html/nsHtml5ElementName.h
parser/html/nsHtml5MetaScanner.h
parser/html/nsHtml5StackNode.h
parser/html/nsHtml5StateSnapshot.h
parser/html/nsHtml5Tokenizer.h
parser/html/nsHtml5TreeBuilder.cpp
parser/html/nsHtml5TreeBuilder.h
parser/html/nsHtml5UTF16Buffer.h
--- a/parser/html/javasrc/TreeBuilder.java
+++ b/parser/html/javasrc/TreeBuilder.java
@@ -6213,16 +6213,17 @@ public abstract class TreeBuilder<T> imp
             }
         }
         return true;
     }
 
     @SuppressWarnings("unchecked") public void loadState(
             TreeBuilderState<T> snapshot, Interner interner)
             throws SAXException {
+        // CPPONLY: mCurrentHtmlScriptIsAsyncOrDefer = false;
         StackNode<T>[] stackCopy = snapshot.getStack();
         int stackLen = snapshot.getStackLength();
         StackNode<T>[] listCopy = snapshot.getListOfActiveFormattingElements();
         int listLen = snapshot.getListOfActiveFormattingElementsLength();
         int[] templateModeStackCopy = snapshot.getTemplateModeStack();
         int templateModeStackLen = snapshot.getTemplateModeStackLength();
 
         for (int i = 0; i <= listPtr; i++) {
--- a/parser/html/nsHtml5AttributeName.h
+++ b/parser/html/nsHtml5AttributeName.h
@@ -53,33 +53,29 @@ class nsHtml5MetaScanner;
 class nsHtml5UTF16Buffer;
 class nsHtml5StateSnapshot;
 class nsHtml5Portability;
 
 class nsHtml5AttributeName
 {
 public:
   static int32_t* ALL_NO_NS;
-
 private:
   static int32_t* XMLNS_NS;
   static int32_t* XML_NS;
   static int32_t* XLINK_NS;
-
 public:
   static nsAtom** ALL_NO_PREFIX;
-
 private:
   static nsAtom** XMLNS_PREFIX;
   static nsAtom** XLINK_PREFIX;
   static nsAtom** XML_PREFIX;
   static nsAtom** SVG_DIFFERENT(nsAtom* name, nsAtom* camel);
   static nsAtom** MATH_DIFFERENT(nsAtom* name, nsAtom* camel);
   static nsAtom** COLONIFIED_LOCAL(nsAtom* name, nsAtom* suffix);
-
 public:
   static nsAtom** SAME_LOCAL(nsAtom* name);
   inline static int32_t levelOrderBinarySearch(jArray<int32_t, int32_t> data,
                                                int32_t key)
   {
     int32_t n = data.length;
     int32_t i = 0;
     while (i < n) {
@@ -157,17 +153,16 @@ public:
   static const int32_t SVG = 2;
 
 private:
   int32_t* uri;
   nsAtom** local;
   nsAtom** prefix;
   bool custom;
   nsHtml5AttributeName(int32_t* uri, nsAtom** local, nsAtom** prefix);
-
 public:
   nsHtml5AttributeName();
   inline bool isInterned() { return !custom; }
 
   inline void setNameForNonInterned(nsAtom* name)
   {
     MOZ_ASSERT(custom);
     local[0] = name;
@@ -668,19 +663,17 @@ public:
   static nsHtml5AttributeName* ATTR_RX;
   static nsHtml5AttributeName* ATTR_REFX;
   static nsHtml5AttributeName* ATTR_BY;
   static nsHtml5AttributeName* ATTR_CY;
   static nsHtml5AttributeName* ATTR_DY;
   static nsHtml5AttributeName* ATTR_FY;
   static nsHtml5AttributeName* ATTR_RY;
   static nsHtml5AttributeName* ATTR_REFY;
-
 private:
   static nsHtml5AttributeName** ATTRIBUTE_NAMES;
   static staticJArray<int32_t, int32_t> ATTRIBUTE_HASHES;
-
 public:
   static void initializeStatics();
   static void releaseStatics();
 };
 
 #endif
--- a/parser/html/nsHtml5ElementName.h
+++ b/parser/html/nsHtml5ElementName.h
@@ -75,17 +75,16 @@ public:
 
   static const int32_t OPTIONAL_END_TAG = (1 << 23);
 
 private:
   nsAtom* name;
   nsAtom* camelCaseName;
   mozilla::dom::HTMLContentCreatorFunction htmlCreator;
   mozilla::dom::SVGContentCreatorFunction svgCreator;
-
 public:
   int32_t flags;
   inline nsAtom* getName() { return name; }
 
   inline nsAtom* getCamelCaseName() { return camelCaseName; }
 
   inline mozilla::dom::HTMLContentCreatorFunction getHtmlCreator()
   {
@@ -400,19 +399,17 @@ public:
   static nsHtml5ElementName* ELT_VIEW;
   static nsHtml5ElementName* ELT_FECOLORMATRIX;
   static nsHtml5ElementName* ELT_FECONVOLVEMATRIX;
   static nsHtml5ElementName* ELT_BODY;
   static nsHtml5ElementName* ELT_FEMORPHOLOGY;
   static nsHtml5ElementName* ELT_RUBY;
   static nsHtml5ElementName* ELT_SUMMARY;
   static nsHtml5ElementName* ELT_TBODY;
-
 private:
   static nsHtml5ElementName** ELEMENT_NAMES;
   static staticJArray<int32_t, int32_t> ELEMENT_HASHES;
-
 public:
   static void initializeStatics();
   static void releaseStatics();
 };
 
 #endif
--- a/parser/html/nsHtml5MetaScanner.h
+++ b/parser/html/nsHtml5MetaScanner.h
@@ -115,60 +115,52 @@ private:
   static const int32_t HTTP_EQUIV_NOT_SEEN = 0;
 
   static const int32_t HTTP_EQUIV_CONTENT_TYPE = 1;
 
   static const int32_t HTTP_EQUIV_OTHER = 2;
 
 protected:
   nsHtml5ByteReadable* readable;
-
 private:
   int32_t metaState;
   int32_t contentIndex;
   int32_t charsetIndex;
   int32_t httpEquivIndex;
   int32_t contentTypeIndex;
-
 protected:
   int32_t stateSave;
-
 private:
   int32_t strBufLen;
   autoJArray<char16_t, int32_t> strBuf;
   nsHtml5String content;
   nsHtml5String charset;
   int32_t httpEquivState;
   nsHtml5TreeBuilder* treeBuilder;
-
 public:
   explicit nsHtml5MetaScanner(nsHtml5TreeBuilder* tb);
   ~nsHtml5MetaScanner();
-
 protected:
   void stateLoop(int32_t state);
-
 private:
   void handleCharInAttributeValue(int32_t c);
   inline int32_t toAsciiLowerCase(int32_t c)
   {
     if (c >= 'A' && c <= 'Z') {
       return c + 0x20;
     }
     return c;
   }
 
   void addToBuffer(int32_t c);
   void handleAttributeValue();
   bool handleTag();
   bool handleTagInner();
-
 protected:
   bool tryCharset(nsHtml5String encoding);
-
 public:
   static void initializeStatics();
   static void releaseStatics();
 
 #include "nsHtml5MetaScannerHSupplement.h"
 };
 
 #endif
--- a/parser/html/nsHtml5StackNode.h
+++ b/parser/html/nsHtml5StackNode.h
@@ -61,21 +61,19 @@ class nsHtml5StackNode
 public:
   int32_t idxInTreeBuilder;
   int32_t flags;
   nsAtom* name;
   nsAtom* popName;
   int32_t ns;
   nsIContentHandle* node;
   nsHtml5HtmlAttributes* attributes;
-
 private:
   int32_t refcount;
   mozilla::dom::HTMLContentCreatorFunction htmlCreator;
-
 public:
   inline int32_t getFlags() { return flags; }
 
   int32_t getGroup();
   bool isScoping();
   bool isSpecial();
   bool isFosterParenting();
   bool isHtmlIntegrationPoint();
@@ -101,17 +99,16 @@ public:
   void setValues(nsHtml5ElementName* elementName,
                  nsIContentHandle* node,
                  nsAtom* popName,
                  bool markAsIntegrationPoint);
 
 private:
   static int32_t prepareSvgFlags(int32_t flags);
   static int32_t prepareMathFlags(int32_t flags, bool markAsIntegrationPoint);
-
 public:
   ~nsHtml5StackNode();
   void dropAttributes();
   void retain();
   void release(nsHtml5TreeBuilder* owningTreeBuilder);
   bool isUnused();
   static void initializeStatics();
   static void releaseStatics();
--- a/parser/html/nsHtml5StateSnapshot.h
+++ b/parser/html/nsHtml5StateSnapshot.h
@@ -63,17 +63,16 @@ private:
   nsIContentHandle* formPointer;
   nsIContentHandle* headPointer;
   nsIContentHandle* deepTreeSurrogateParent;
   int32_t mode;
   int32_t originalMode;
   bool framesetOk;
   bool needToDropLF;
   bool quirks;
-
 public:
   nsHtml5StateSnapshot(
     jArray<nsHtml5StackNode*, int32_t> stack,
     jArray<nsHtml5StackNode*, int32_t> listOfActiveFormattingElements,
     jArray<int32_t, int32_t> templateModeStack,
     nsIContentHandle* formPointer,
     nsIContentHandle* headPointer,
     nsIContentHandle* deepTreeSurrogateParent,
--- a/parser/html/nsHtml5Tokenizer.h
+++ b/parser/html/nsHtml5Tokenizer.h
@@ -230,112 +230,93 @@ private:
   static staticJArray<char16_t, int32_t> STYLE_ARR;
   static staticJArray<char16_t, int32_t> PLAINTEXT_ARR;
   static staticJArray<char16_t, int32_t> XMP_ARR;
   static staticJArray<char16_t, int32_t> TEXTAREA_ARR;
   static staticJArray<char16_t, int32_t> IFRAME_ARR;
   static staticJArray<char16_t, int32_t> NOEMBED_ARR;
   static staticJArray<char16_t, int32_t> NOSCRIPT_ARR;
   static staticJArray<char16_t, int32_t> NOFRAMES_ARR;
-
 protected:
   nsHtml5TreeBuilder* tokenHandler;
   nsHtml5StreamParser* encodingDeclarationHandler;
   bool lastCR;
   int32_t stateSave;
-
 private:
   int32_t returnStateSave;
-
 protected:
   int32_t index;
-
 private:
   bool forceQuirks;
   char16_t additional;
   int32_t entCol;
   int32_t firstCharKey;
   int32_t lo;
   int32_t hi;
   int32_t candidate;
   int32_t charRefBufMark;
-
 protected:
   int32_t value;
-
 private:
   bool seenDigits;
-
 protected:
   int32_t cstart;
-
 private:
   nsHtml5String publicId;
   nsHtml5String systemId;
   autoJArray<char16_t, int32_t> strBuf;
   int32_t strBufLen;
   autoJArray<char16_t, int32_t> charRefBuf;
   int32_t charRefBufLen;
   autoJArray<char16_t, int32_t> bmpChar;
   autoJArray<char16_t, int32_t> astralChar;
-
 protected:
   nsHtml5ElementName* endTagExpectation;
-
 private:
   jArray<char16_t, int32_t> endTagExpectationAsArray;
-
 protected:
   bool endTag;
-
 private:
   bool containsHyphen;
   nsHtml5ElementName* tagName;
   nsHtml5ElementName* nonInternedTagName;
-
 protected:
   nsHtml5AttributeName* attributeName;
-
 private:
   nsHtml5AttributeName* nonInternedAttributeName;
   nsAtom* doctypeName;
   nsHtml5String publicIdentifier;
   nsHtml5String systemIdentifier;
   nsHtml5HtmlAttributes* attributes;
   bool newAttributesEachTime;
   bool shouldSuspend;
-
 protected:
   bool confident;
-
 private:
   int32_t line;
   int32_t attributeLine;
   nsHtml5AtomTable* interner;
   bool viewingXmlSource;
-
 public:
   nsHtml5Tokenizer(nsHtml5TreeBuilder* tokenHandler, bool viewingXmlSource);
   void setInterner(nsHtml5AtomTable* interner);
   void initLocation(nsHtml5String newPublicId, nsHtml5String newSystemId);
   bool isViewingXmlSource();
   void setStateAndEndTagExpectation(int32_t specialTokenizerState,
                                     nsAtom* endTagExpectation);
   void setStateAndEndTagExpectation(int32_t specialTokenizerState,
                                     nsHtml5ElementName* endTagExpectation);
 
 private:
   void endTagExpectationToArray();
-
 public:
   void setLineNumber(int32_t line);
   inline int32_t getLineNumber() { return line; }
 
   nsHtml5HtmlAttributes* emptyAttributes();
-
 private:
   inline void appendCharRefBuf(char16_t c)
   {
     MOZ_RELEASE_ASSERT(charRefBufLen < charRefBuf.length,
                        "Attempted to overrun charRefBuf!");
     charRefBuf[charRefBufLen++] = c;
   }
 
@@ -364,17 +345,16 @@ private:
         MOZ_CRASH("Unable to recover from buffer reallocation failure");
       }
     }
     strBuf[strBufLen++] = c;
   }
 
 protected:
   nsHtml5String strBufToString();
-
 private:
   void strBufToDoctypeName();
   void emitStrBuf();
   inline void appendSecondHyphenToBogusComment() { appendStrBuf('-'); }
 
   inline void adjustDoubleHyphenAndAppendToStrBufAndErr(char16_t c)
   {
     errConsecutiveHyphens();
@@ -384,31 +364,27 @@ private:
   void appendStrBuf(char16_t* buffer, int32_t offset, int32_t length);
   inline void appendCharRefBufToStrBuf()
   {
     appendStrBuf(charRefBuf, 0, charRefBufLen);
     charRefBufLen = 0;
   }
 
   void emitComment(int32_t provisionalHyphens, int32_t pos);
-
 protected:
   void flushChars(char16_t* buf, int32_t pos);
-
 private:
   void strBufToElementNameString();
   int32_t emitCurrentTagToken(bool selfClosing, int32_t pos);
   void attributeNameComplete();
   void addAttributeWithoutValue();
   void addAttributeWithValue();
-
 public:
   void start();
   bool tokenizeBuffer(nsHtml5UTF16Buffer* buffer);
-
 private:
   template<class P>
   int32_t stateLoop(int32_t state,
                     char16_t c,
                     int32_t pos,
                     char16_t* buf,
                     bool reconsume,
                     int32_t returnState,
@@ -450,33 +426,28 @@ protected:
 private:
   void emitCarriageReturn(char16_t* buf, int32_t pos);
   void emitReplacementCharacter(char16_t* buf, int32_t pos);
   void emitPlaintextReplacementCharacter(char16_t* buf, int32_t pos);
   void setAdditionalAndRememberAmpersandLocation(char16_t add);
   void bogusDoctype();
   void bogusDoctypeWithoutQuirks();
   void handleNcrValue(int32_t returnState);
-
 public:
   void eof();
-
 private:
   void emitDoctypeToken(int32_t pos);
-
 protected:
   inline char16_t checkChar(char16_t* buf, int32_t pos) { return buf[pos]; }
 
 public:
   bool internalEncodingDeclaration(nsHtml5String internalCharset);
-
 private:
   void emitOrAppendTwo(const char16_t* val, int32_t returnState);
   void emitOrAppendOne(const char16_t* val, int32_t returnState);
-
 public:
   void end();
   void requestSuspension();
   bool isInDataState();
   void resetToDataState();
   void loadState(nsHtml5Tokenizer* other);
   void initializeWithoutStarting();
   void setEncodingDeclarationHandler(
--- a/parser/html/nsHtml5TreeBuilder.cpp
+++ b/parser/html/nsHtml5TreeBuilder.cpp
@@ -4923,16 +4923,17 @@ nsHtml5TreeBuilder::snapshotMatches(nsAH
   }
   return true;
 }
 
 void
 nsHtml5TreeBuilder::loadState(nsAHtml5TreeBuilderState* snapshot,
                               nsHtml5AtomTable* interner)
 {
+  mCurrentHtmlScriptIsAsyncOrDefer = false;
   jArray<nsHtml5StackNode*, int32_t> stackCopy = snapshot->getStack();
   int32_t stackLen = snapshot->getStackLength();
   jArray<nsHtml5StackNode*, int32_t> listCopy =
     snapshot->getListOfActiveFormattingElements();
   int32_t listLen = snapshot->getListOfActiveFormattingElementsLength();
   jArray<int32_t, int32_t> templateModeStackCopy =
     snapshot->getTemplateModeStack();
   int32_t templateModeStackLen = snapshot->getTemplateModeStackLength();
--- a/parser/html/nsHtml5TreeBuilder.h
+++ b/parser/html/nsHtml5TreeBuilder.h
@@ -66,17 +66,16 @@ class nsHtml5MetaScanner;
 class nsHtml5UTF16Buffer;
 class nsHtml5StateSnapshot;
 class nsHtml5Portability;
 
 class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState
 {
 private:
   static char16_t REPLACEMENT_CHARACTER[];
-
 public:
   static const int32_t OTHER = 0;
 
   static const int32_t A = 1;
 
   static const int32_t BASE = 2;
 
   static const int32_t BODY = 3;
@@ -283,20 +282,18 @@ private:
   static const int32_t CHARSET_UNQUOTED = 11;
 
   static staticJArray<const char*, int32_t> QUIRKY_PUBLIC_IDS;
   static const int32_t NOT_FOUND_ON_STACK = INT32_MAX;
 
   int32_t mode;
   int32_t originalMode;
   bool framesetOk;
-
 protected:
   nsHtml5Tokenizer* tokenizer;
-
 private:
   bool scriptingEnabled;
   bool needToDropLF;
   bool fragment;
   nsAtom* contextName;
   int32_t contextNamespace;
   nsIContentHandle* contextNode;
   autoJArray<int32_t, int32_t> templateModeStack;
@@ -306,21 +303,19 @@ private:
   int32_t numStackNodes;
   autoJArray<nsHtml5StackNode*, int32_t> stack;
   int32_t currentPtr;
   autoJArray<nsHtml5StackNode*, int32_t> listOfActiveFormattingElements;
   int32_t listPtr;
   nsIContentHandle* formPointer;
   nsIContentHandle* headPointer;
   nsIContentHandle* deepTreeSurrogateParent;
-
 protected:
   autoJArray<char16_t, int32_t> charBuffer;
   int32_t charBufferLen;
-
 private:
   bool quirks;
   bool isSrcdocDocument;
   inline nsHtml5ContentCreatorFunction htmlCreator(
     mozilla::dom::HTMLContentCreatorFunction htmlCreator)
   {
     nsHtml5ContentCreatorFunction creator;
     creator.html = htmlCreator;
@@ -357,27 +352,24 @@ private:
                               nsHtml5HtmlAttributes* attributes);
   void startTagScriptInHead(nsHtml5ElementName* elementName,
                             nsHtml5HtmlAttributes* attributes);
   void startTagTemplateInHead(nsHtml5ElementName* elementName,
                               nsHtml5HtmlAttributes* attributes);
   bool isTemplateContents();
   bool isTemplateModeStackEmpty();
   bool isSpecialParentInForeign(nsHtml5StackNode* stackNode);
-
 public:
   static nsHtml5String extractCharsetFromContent(nsHtml5String attributeValue,
                                                  nsHtml5TreeBuilder* tb);
 
 private:
   void checkMetaCharset(nsHtml5HtmlAttributes* attributes);
-
 public:
   void endTag(nsHtml5ElementName* elementName);
-
 private:
   void endTagTemplateInHead();
   int32_t findLastInTableScopeOrRootTemplateTbodyTheadTfoot();
   int32_t findLast(nsAtom* name);
   int32_t findLastInTableScope(nsAtom* name);
   int32_t findLastInButtonScope(nsAtom* name);
   int32_t findLastInScope(nsAtom* name);
   int32_t findLastInListScope(nsAtom* name);
@@ -430,20 +422,18 @@ private:
     nsAtom* name,
     nsHtml5HtmlAttributes* attributes);
   int32_t findLastOrRoot(nsAtom* name);
   int32_t findLastOrRoot(int32_t group);
   bool addAttributesToBody(nsHtml5HtmlAttributes* attributes);
   void addAttributesToHtml(nsHtml5HtmlAttributes* attributes);
   void pushHeadPointerOntoStack();
   void reconstructTheActiveFormattingElements();
-
 public:
   void notifyUnusedStackNode(int32_t idxInStackNodes);
-
 private:
   nsHtml5StackNode* getUnusedStackNode();
   nsHtml5StackNode* createStackNode(
     int32_t flags,
     int32_t ns,
     nsAtom* name,
     nsIContentHandle* node,
     nsAtom* popName,
@@ -516,17 +506,16 @@ private:
     nsHtml5ElementName* elementName,
     nsHtml5HtmlAttributes* attributes);
   void appendVoidElementToCurrentMayFosterMathML(
     nsHtml5ElementName* elementName,
     nsHtml5HtmlAttributes* attributes);
   void appendVoidInputToCurrent(nsHtml5HtmlAttributes* attributes,
                                 nsIContentHandle* form);
   void appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes);
-
 protected:
   void accumulateCharacters(const char16_t* buf, int32_t start, int32_t length);
   void requestSuspension();
   nsIContentHandle* createElement(int32_t ns,
                                   nsAtom* name,
                                   nsHtml5HtmlAttributes* attributes,
                                   nsIContentHandle* intendedParent,
                                   nsHtml5ContentCreatorFunction creator);
@@ -574,42 +563,37 @@ protected:
   void markMalformedIfScript(nsIContentHandle* elt);
   void start(bool fragmentMode);
   void end();
   void appendDoctypeToDocument(nsAtom* name,
                                nsHtml5String publicIdentifier,
                                nsHtml5String systemIdentifier);
   void elementPushed(int32_t ns, nsAtom* name, nsIContentHandle* node);
   void elementPopped(int32_t ns, nsAtom* name, nsIContentHandle* node);
-
 public:
   inline bool cdataSectionAllowed() { return isInForeign(); }
 
 private:
   bool isInForeign();
   bool isInForeignButNotHtmlOrMathTextIntegrationPoint();
-
 public:
   void setFragmentContext(nsAtom* context,
                           int32_t ns,
                           nsIContentHandle* node,
                           bool quirks);
 
 protected:
   nsIContentHandle* currentNode();
-
 public:
   bool isScriptingEnabled();
   void setScriptingEnabled(bool scriptingEnabled);
   void setIsSrcdocDocument(bool isSrcdocDocument);
   void flushCharacters();
-
 private:
   bool charBufferContainsNonWhitespace();
-
 public:
   nsAHtml5TreeBuilderState* newSnapshot();
   bool snapshotMatches(nsAHtml5TreeBuilderState* snapshot);
   void loadState(nsAHtml5TreeBuilderState* snapshot,
                  nsHtml5AtomTable* interner);
 
 private:
   int32_t findInArray(nsHtml5StackNode* node,
--- a/parser/html/nsHtml5UTF16Buffer.h
+++ b/parser/html/nsHtml5UTF16Buffer.h
@@ -55,17 +55,16 @@ class nsHtml5StateSnapshot;
 class nsHtml5Portability;
 
 class nsHtml5UTF16Buffer
 {
 private:
   char16_t* buffer;
   int32_t start;
   int32_t end;
-
 public:
   int32_t getStart();
   void setStart(int32_t start);
   char16_t* getBuffer();
   int32_t getEnd();
   bool hasMore();
   int32_t getLength();
   void adjust(bool lastWasCR);