Bug 898912 (part 8) - Remove the no-effect TSF_IN_HTML_COMMENT flag. r=till.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 29 Jul 2013 23:29:05 -0700
changeset 140877 7e2904bafdc49abccc1b6408317c3a6b6c9e1bba
parent 140876 06176970ae879003f09baf0db4a724de2e0f9c46
child 140878 7a02c72ed5ed0a2ef96429cf1adac726dc0c065d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerstill
bugs898912
milestone25.0a1
Bug 898912 (part 8) - Remove the no-effect TSF_IN_HTML_COMMENT flag. r=till.
js/src/frontend/TokenStream.cpp
js/src/frontend/TokenStream.h
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1515,20 +1515,18 @@ TokenStream::getTokenInternal()
         else
             tt = TOK_NOT;
         break;
 
       case '<':
         /* NB: treat HTML begin-comment as comment-till-end-of-line */
         if (matchChar('!')) {
             if (matchChar('-')) {
-                if (matchChar('-')) {
-                    flags |= TSF_IN_HTML_COMMENT;
+                if (matchChar('-'))
                     goto skipline;
-                }
                 ungetChar('-');
             }
             ungetChar('!');
         }
         if (matchChar('<')) {
             tt = matchChar('=') ? TOK_LSHASSIGN : TOK_LSH;
         } else {
             tt = matchChar('=') ? TOK_LE : TOK_LT;
@@ -1556,27 +1554,19 @@ TokenStream::getTokenInternal()
          */
         if (matchChar('/')) {
             c = peekChar();
             if (c == '@' || c == '#') {
                 if (!getSourceMappingURL(false, getChar() == '@'))
                     goto error;
             }
 
-  skipline:
-            /* Optimize line skipping if we are not in an HTML comment. */
-            if (flags & TSF_IN_HTML_COMMENT) {
-                while ((c = getChar()) != EOF && c != '\n') {
-                    if (c == '-' && matchChar('-') && matchChar('>'))
-                        flags &= ~TSF_IN_HTML_COMMENT;
-                }
-            } else {
-                while ((c = getChar()) != EOF && c != '\n')
-                    continue;
-            }
+        skipline:
+            while ((c = getChar()) != EOF && c != '\n')
+                continue;
             ungetChar(c);
             cursor = (cursor - 1) & ntokensMask;
             goto retry;
         }
 
         /*
          * Look for a multi-line comment.
          */
@@ -1665,20 +1655,18 @@ TokenStream::getTokenInternal()
         break;
 
       case '%':
         tt = matchChar('=') ? TOK_MODASSIGN : TOK_MOD;
         break;
 
       case '-':
         if (matchChar('-')) {
-            if (peekChar() == '>' && !(flags & TSF_DIRTYLINE)) {
-                flags &= ~TSF_IN_HTML_COMMENT;
+            if (peekChar() == '>' && !(flags & TSF_DIRTYLINE))
                 goto skipline;
-            }
             tt = TOK_DEC;
         } else {
             tt = matchChar('=') ? TOK_SUBASSIGN : TOK_MINUS;
         }
         break;
 
       badchar:
       default:
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -319,38 +319,17 @@ enum TokenStreamFlags
 {
     TSF_EOF = 0x02,             /* hit end of file */
     TSF_EOL = 0x04,             /* an EOL was hit in whitespace or a multi-line comment */
     TSF_OPERAND = 0x08,         /* looking for operand, not operator */
     TSF_UNEXPECTED_EOF = 0x10,  /* unexpected end of input, i.e. TOK_EOF not at top-level. */
     TSF_KEYWORD_IS_NAME = 0x20, /* Ignore keywords and return TOK_NAME instead to the parser. */
     TSF_DIRTYLINE = 0x40,       /* non-whitespace since start of line */
     TSF_OCTAL_CHAR = 0x80,      /* observed a octal character escape */
-    TSF_HAD_ERROR = 0x100,      /* returned TOK_ERROR from getToken */
-
-    /*
-     * To handle the hard case of contiguous HTML comments, we want to clear the
-     * TSF_DIRTYINPUT flag at the end of each such comment.  But we'd rather not
-     * scan for --> within every //-style comment unless we have to.  So we set
-     * TSF_IN_HTML_COMMENT when a <!-- is scanned as an HTML begin-comment, and
-     * clear it (and TSF_DIRTYINPUT) when we scan --> either on a clean line, or
-     * only if (ts->flags & TSF_IN_HTML_COMMENT), in a //-style comment.
-     *
-     * This still works as before given a malformed comment hiding hack such as:
-     *
-     *    <script>
-     *      <!-- comment hiding hack #1
-     *      code goes here
-     *      // --> oops, markup for script-unaware browsers goes here!
-     *    </script>
-     *
-     * It does not cope with malformed comment hiding hacks where --> is hidden
-     * by C-style comments, or on a dirty line.  Such cases are already broken.
-     */
-    TSF_IN_HTML_COMMENT = 0x200
+    TSF_HAD_ERROR = 0x100       /* returned TOK_ERROR from getToken */
 };
 
 struct CompileError {
     JSContext *cx;
     JSErrorReport report;
     char *message;
     ErrorArgumentsType argumentsType;
     CompileError(JSContext *cx)