Title: [219285] trunk/Source/_javascript_Core
Revision
219285
Author
utatane....@gmail.com
Date
2017-07-09 19:34:55 -0700 (Sun, 09 Jul 2017)

Log Message

[JSC] Drop LineNumberAdder since we no longer treat <LF><CR> (not <CR><LF>) as one line terminator
https://bugs.webkit.org/show_bug.cgi?id=174296

Reviewed by Mark Lam.

Previously, we treat <LF><CR> as one line terminator. So we increase line number by one.
It caused a problem in scanning template literals. While template literals normalize
<LF><CR> to <LF><LF>, we still needed to increase line number by only one.
To handle it correctly, LineNumberAdder is introduced.

As of r219263, <LF><CR> is counted as two line terminators. So we do not need to have
LineNumberAdder. Let's just use shiftLineTerminator() instead.

* parser/Lexer.cpp:
(JSC::Lexer<T>::parseTemplateLiteral):
(JSC::LineNumberAdder::LineNumberAdder): Deleted.
(JSC::LineNumberAdder::clear): Deleted.
(JSC::LineNumberAdder::add): Deleted.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (219284 => 219285)


--- trunk/Source/_javascript_Core/ChangeLog	2017-07-10 02:18:56 UTC (rev 219284)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-07-10 02:34:55 UTC (rev 219285)
@@ -1,3 +1,24 @@
+2017-07-09  Yusuke Suzuki  <utatane....@gmail.com>
+
+        [JSC] Drop LineNumberAdder since we no longer treat <LF><CR> (not <CR><LF>) as one line terminator
+        https://bugs.webkit.org/show_bug.cgi?id=174296
+
+        Reviewed by Mark Lam.
+
+        Previously, we treat <LF><CR> as one line terminator. So we increase line number by one.
+        It caused a problem in scanning template literals. While template literals normalize
+        <LF><CR> to <LF><LF>, we still needed to increase line number by only one.
+        To handle it correctly, LineNumberAdder is introduced.
+
+        As of r219263, <LF><CR> is counted as two line terminators. So we do not need to have
+        LineNumberAdder. Let's just use shiftLineTerminator() instead.
+
+        * parser/Lexer.cpp:
+        (JSC::Lexer<T>::parseTemplateLiteral):
+        (JSC::LineNumberAdder::LineNumberAdder): Deleted.
+        (JSC::LineNumberAdder::clear): Deleted.
+        (JSC::LineNumberAdder::add): Deleted.
+
 2017-07-09  Dan Bernstein  <m...@apple.com>
 
         [Xcode] ICU headers aren’t treated as system headers after r219155

Modified: trunk/Source/_javascript_Core/parser/Lexer.cpp (219284 => 219285)


--- trunk/Source/_javascript_Core/parser/Lexer.cpp	2017-07-10 02:18:56 UTC (rev 219284)
+++ trunk/Source/_javascript_Core/parser/Lexer.cpp	2017-07-10 02:34:55 UTC (rev 219285)
@@ -1375,54 +1375,6 @@
     return StringParsedSuccessfully;
 }
 
-// While the lexer accepts <LF><CR> (not <CR><LF>) sequence
-// as one line terminator and increments one line number,
-// TemplateLiteral considers it as two line terminators <LF> and <CR>.
-//
-// TemplateLiteral normalizes line terminators as follows.
-//
-// <LF> => <LF>
-// <CR> => <LF>
-// <CR><LF> => <LF>
-// <\u2028> => <\u2028>
-// <\u2029> => <\u2029>
-//
-// So, <LF><CR> should be normalized to <LF><LF>.
-// However, the lexer should increment the line number only once for <LF><CR>.
-//
-// To achieve this, LineNumberAdder holds the current status of line terminator sequence.
-// When TemplateLiteral lexer encounters a line terminator, it notifies to LineNumberAdder.
-// LineNumberAdder maintains the status and increments the line number when it's necessary.
-// For example, LineNumberAdder increments the line number only once for <LF><CR> and <CR><LF>.
-template<typename CharacterType>
-class LineNumberAdder {
-public:
-    LineNumberAdder(int& lineNumber)
-        : m_lineNumber(lineNumber)
-    {
-    }
-
-    void clear()
-    {
-        m_previous = 0;
-    }
-
-    void add(CharacterType character)
-    {
-        ASSERT(Lexer<CharacterType>::isLineTerminator(character));
-        if (m_previous == '\r' && character == '\n')
-            m_previous = 0;
-        else {
-            ++m_lineNumber;
-            m_previous = character;
-        }
-    }
-
-private:
-    int& m_lineNumber;
-    CharacterType m_previous { 0 };
-};
-
 template <typename T>
 typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData* tokenData, RawStringsBuildMode rawStringsBuildMode)
 {
@@ -1430,11 +1382,8 @@
     const T* stringStart = currentSourcePtr();
     const T* rawStringStart = currentSourcePtr();
 
-    LineNumberAdder<T> lineNumberAdder(m_lineNumber);
-
     while (m_current != '`') {
         if (UNLIKELY(m_current == '\\')) {
-            lineNumberAdder.clear();
             if (stringStart != currentSourcePtr())
                 append16(stringStart, currentSourcePtr() - stringStart);
             shift();
@@ -1455,18 +1404,10 @@
                         m_bufferForRawTemplateString16.append('\n');
                     }
 
-                    lineNumberAdder.add(m_current);
-                    shift();
-                    if (m_current == '\n') {
-                        lineNumberAdder.add(m_current);
-                        shift();
-                    }
-
+                    shiftLineTerminator();
                     rawStringStart = currentSourcePtr();
-                } else {
-                    lineNumberAdder.add(m_current);
-                    shift();
-                }
+                } else
+                    shiftLineTerminator();
             } else {
                 bool strictMode = true;
                 StringParseResult result = parseComplexEscape<true, LexerEscapeParseMode::Template>(strictMode, '`');
@@ -1493,7 +1434,7 @@
             // Unlike String, line terminator is allowed.
             if (atEnd()) {
                 m_lexErrorMessage = ASCIILiteral("Unexpected EOF");
-                return atEnd() ? StringUnterminated : StringCannotBeParsed;
+                return StringUnterminated;
             }
 
             if (isLineTerminator(m_current)) {
@@ -1507,24 +1448,16 @@
                     record16('\n');
                     if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings)
                         m_bufferForRawTemplateString16.append('\n');
-                    lineNumberAdder.add(m_current);
-                    shift();
-                    if (m_current == '\n') {
-                        lineNumberAdder.add(m_current);
-                        shift();
-                    }
+                    shiftLineTerminator();
                     stringStart = currentSourcePtr();
                     rawStringStart = currentSourcePtr();
-                } else {
-                    lineNumberAdder.add(m_current);
-                    shift();
-                }
+                } else
+                    shiftLineTerminator();
                 continue;
             }
             // Anything else is just a normal character
         }
 
-        lineNumberAdder.clear();
         shift();
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to