Bug 1376154 - Preserve nsHtml5MetaScanner::mEncoding initialization when re-translating parser. r?wchen. draft
authorHenri Sivonen <hsivonen@hsivonen.fi>
Mon, 03 Jul 2017 14:52:19 +0300
changeset 603281 419b8f03f2c420a3d9faf50458605d7cb3b2781d
parent 603266 dc534de59f01266c25c5d3577d955522d81f3f81
child 635863 9b14c57f0c734257958f401ddb5150290a2f780d
push id66716
push userbmo:hsivonen@hsivonen.fi
push dateMon, 03 Jul 2017 11:52:44 +0000
reviewerswchen
bugs1376154
milestone56.0a1
Bug 1376154 - Preserve nsHtml5MetaScanner::mEncoding initialization when re-translating parser. r?wchen. MozReview-Commit-ID: I2vM178Rq6e
parser/html/javasrc/MetaScanner.java
parser/html/nsHtml5MetaScanner.cpp
parser/html/nsHtml5MetaScanner.h
parser/html/nsHtml5TreeBuilder.h
--- a/parser/html/javasrc/MetaScanner.java
+++ b/parser/html/javasrc/MetaScanner.java
@@ -1,48 +1,48 @@
 /*
  * Copyright (c) 2007 Henri Sivonen
  * Copyright (c) 2008-2015 Mozilla Foundation
  *
- * Permission is hereby granted, free of charge, to any person obtaining a 
- * copy of this software and associated documentation files (the "Software"), 
- * to deal in the Software without restriction, including without limitation 
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
- * and/or sell copies of the Software, and to permit persons to whom the 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in 
+ * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 package nu.validator.htmlparser.impl;
 
 import java.io.IOException;
 
+import org.xml.sax.SAXException;
+
 import nu.validator.htmlparser.annotation.Auto;
 import nu.validator.htmlparser.annotation.Inline;
 import nu.validator.htmlparser.common.ByteReadable;
 
-import org.xml.sax.SAXException;
-
 public abstract class MetaScanner {
 
     /**
      * Constant for "charset".
      */
     private static final char[] CHARSET = { 'h', 'a', 'r', 's', 'e', 't' };
-    
+
     /**
      * Constant for "content".
      */
     private static final char[] CONTENT = { 'o', 'n', 't', 'e', 'n', 't' };
 
     /**
      * Constant for "http-equiv".
      */
@@ -53,23 +53,23 @@ public abstract class MetaScanner {
      * Constant for "content-type".
      */
     private static final char[] CONTENT_TYPE = { 'c', 'o', 'n', 't', 'e', 'n',
             't', '-', 't', 'y', 'p', 'e' };
 
     private static final int NO = 0;
 
     private static final int M = 1;
-    
+
     private static final int E = 2;
-    
+
     private static final int T = 3;
 
     private static final int A = 4;
-    
+
     private static final int DATA = 0;
 
     private static final int TAG_OPEN = 1;
 
     private static final int SCAN_UNTIL_GT = 2;
 
     private static final int TAG_NAME = 3;
 
@@ -85,52 +85,52 @@ public abstract class MetaScanner {
 
     private static final int ATTRIBUTE_VALUE_SINGLE_QUOTED = 9;
 
     private static final int ATTRIBUTE_VALUE_UNQUOTED = 10;
 
     private static final int AFTER_ATTRIBUTE_VALUE_QUOTED = 11;
 
     private static final int MARKUP_DECLARATION_OPEN = 13;
-    
+
     private static final int MARKUP_DECLARATION_HYPHEN = 14;
 
     private static final int COMMENT_START = 15;
 
     private static final int COMMENT_START_DASH = 16;
 
     private static final int COMMENT = 17;
 
     private static final int COMMENT_END_DASH = 18;
 
     private static final int COMMENT_END = 19;
-    
+
     private static final int SELF_CLOSING_START_TAG = 20;
-    
+
     private static final int HTTP_EQUIV_NOT_SEEN = 0;
-    
+
     private static final int HTTP_EQUIV_CONTENT_TYPE = 1;
 
     private static final int HTTP_EQUIV_OTHER = 2;
 
     /**
      * The data source.
      */
     protected ByteReadable readable;
-    
+
     /**
      * The state of the state machine that recognizes the tag name "meta".
      */
     private int metaState = NO;
 
     /**
      * The current position in recognizing the attribute name "content".
      */
     private int contentIndex = Integer.MAX_VALUE;
-    
+
     /**
      * The current position in recognizing the attribute name "charset".
      */
     private int charsetIndex = Integer.MAX_VALUE;
 
     /**
      * The current position in recognizing the attribute name "http-equive".
      */
@@ -150,23 +150,23 @@ public abstract class MetaScanner {
      * The currently filled length of strBuf.
      */
     private int strBufLen;
 
     /**
      * Accumulation buffer for attribute values.
      */
     private @Auto char[] strBuf;
-    
+
     private String content;
-    
+
     private String charset;
-    
+
     private int httpEquivState;
-    
+
     // CPPONLY: private TreeBuilder treeBuilder;
 
     public MetaScanner(
         // CPPONLY: TreeBuilder tb
     ) {
         this.readable = null;
         this.metaState = NO;
         this.contentIndex = Integer.MAX_VALUE;
@@ -175,28 +175,29 @@ public abstract class MetaScanner {
         this.contentTypeIndex = Integer.MAX_VALUE;
         this.stateSave = DATA;
         this.strBufLen = 0;
         this.strBuf = new char[36];
         this.content = null;
         this.charset = null;
         this.httpEquivState = HTTP_EQUIV_NOT_SEEN;
         // CPPONLY: this.treeBuilder = tb;
+        // CPPONLY: this.mEncoding = null;
     }
-    
+
     @SuppressWarnings("unused") private void destructor() {
         Portability.releaseString(content);
         Portability.releaseString(charset);
     }
 
     // [NOCPP[
-    
+
     /**
      * Reads a byte from the data source.
-     * 
+     *
      * -1 means end.
      * @return
      * @throws IOException
      */
     protected int read() throws IOException {
         return readable.readByte();
     }
 
@@ -238,17 +239,17 @@ public abstract class MetaScanner {
                         switch (c) {
                             case -1:
                                 break stateloop;
                             case 'm':
                             case 'M':
                                 metaState = M;
                                 state = MetaScanner.TAG_NAME;
                                 break tagopenloop;
-                                // continue stateloop;                                
+                                // continue stateloop;
                             case '!':
                                 state = MetaScanner.MARKUP_DECLARATION_OPEN;
                                 continue stateloop;
                             case '?':
                             case '/':
                                 state = MetaScanner.SCAN_UNTIL_GT;
                                 continue stateloop;
                             case '>':
@@ -345,25 +346,25 @@ public abstract class MetaScanner {
                                 continue stateloop;
                             case 'c':
                             case 'C':
                                 contentIndex = 0;
                                 charsetIndex = 0;
                                 httpEquivIndex = Integer.MAX_VALUE;
                                 contentTypeIndex = Integer.MAX_VALUE;
                                 state = MetaScanner.ATTRIBUTE_NAME;
-                                break beforeattributenameloop;                                
+                                break beforeattributenameloop;
                             case 'h':
                             case 'H':
                                 contentIndex = Integer.MAX_VALUE;
                                 charsetIndex = Integer.MAX_VALUE;
                                 httpEquivIndex = 0;
                                 contentTypeIndex = Integer.MAX_VALUE;
                                 state = MetaScanner.ATTRIBUTE_NAME;
-                                break beforeattributenameloop;                                
+                                break beforeattributenameloop;
                             default:
                                 contentIndex = Integer.MAX_VALUE;
                                 charsetIndex = Integer.MAX_VALUE;
                                 httpEquivIndex = Integer.MAX_VALUE;
                                 contentTypeIndex = Integer.MAX_VALUE;
                                 state = MetaScanner.ATTRIBUTE_NAME;
                                 break beforeattributenameloop;
                             // continue stateloop;
@@ -411,17 +412,17 @@ public abstract class MetaScanner {
                                         ++charsetIndex;
                                     } else {
                                         charsetIndex = Integer.MAX_VALUE;
                                     }
                                     if (httpEquivIndex < HTTP_EQUIV.length && c == HTTP_EQUIV[httpEquivIndex]) {
                                         ++httpEquivIndex;
                                     } else {
                                         httpEquivIndex = Integer.MAX_VALUE;
-                                    }                                    
+                                    }
                                 }
                                 continue;
                         }
                     }
                     // FALLTHRU DON'T REORDER
                 case BEFORE_ATTRIBUTE_VALUE:
                     beforeattributevalueloop: for (;;) {
                         c = read();
@@ -818,17 +819,17 @@ public abstract class MetaScanner {
         boolean stop = handleTagInner();
         Portability.releaseString(content);
         content = null;
         Portability.releaseString(charset);
         charset = null;
         httpEquivState = HTTP_EQUIV_NOT_SEEN;
         return stop;
     }
-    
+
     private boolean handleTagInner() throws SAXException {
         if (charset != null && tryCharset(charset)) {
                 return true;
         }
         if (content != null && httpEquivState == HTTP_EQUIV_CONTENT_TYPE) {
             String extract = TreeBuilder.extractCharsetFromContent(content
                 // CPPONLY: , treeBuilder
             );
@@ -839,16 +840,16 @@ public abstract class MetaScanner {
             Portability.releaseString(extract);
             return success;
         }
         return false;
     }
 
     /**
      * Tries to switch to an encoding.
-     * 
+     *
      * @param encoding
      * @return <code>true</code> if successful
      * @throws SAXException
      */
     protected abstract boolean tryCharset(String encoding) throws SAXException;
-    
+
 }
--- a/parser/html/nsHtml5MetaScanner.cpp
+++ b/parser/html/nsHtml5MetaScanner.cpp
@@ -1,28 +1,28 @@
 /*
  * Copyright (c) 2007 Henri Sivonen
  * Copyright (c) 2008-2015 Mozilla Foundation
  *
- * Permission is hereby granted, free of charge, to any person obtaining a 
- * copy of this software and associated documentation files (the "Software"), 
- * to deal in the Software without restriction, including without limitation 
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
- * and/or sell copies of the Software, and to permit persons to whom the 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in 
+ * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 /*
  * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
  * Please edit MetaScanner.java instead and regenerate.
  */
 
--- a/parser/html/nsHtml5MetaScanner.h
+++ b/parser/html/nsHtml5MetaScanner.h
@@ -1,28 +1,28 @@
 /*
  * Copyright (c) 2007 Henri Sivonen
  * Copyright (c) 2008-2015 Mozilla Foundation
  *
- * Permission is hereby granted, free of charge, to any person obtaining a 
- * copy of this software and associated documentation files (the "Software"), 
- * to deal in the Software without restriction, including without limitation 
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
- * and/or sell copies of the Software, and to permit persons to whom the 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
  * Software is furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in 
+ * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  */
 
 /*
  * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
  * Please edit MetaScanner.java instead and regenerate.
  */
 
--- a/parser/html/nsHtml5TreeBuilder.h
+++ b/parser/html/nsHtml5TreeBuilder.h
@@ -399,20 +399,18 @@ class nsHtml5TreeBuilder : public nsAHtm
     int32_t findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom* name);
     void maybeForgetEarlierDuplicateFormattingElement(nsIAtom* name, nsHtml5HtmlAttributes* attributes);
     int32_t findLastOrRoot(nsIAtom* 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,
                                       nsIAtom* name,
                                       nsIContentHandle* node,
                                       nsIAtom* popName,
                                       nsHtml5HtmlAttributes* attributes);