Changeset 219285 in webkit


Ignore:
Timestamp:
Jul 9, 2017 7:34:55 PM (7 years ago)
Author:
Yusuke Suzuki
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.

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r219282 r219285  
     12017-07-09  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Drop LineNumberAdder since we no longer treat <LF><CR> (not <CR><LF>) as one line terminator
     4        https://bugs.webkit.org/show_bug.cgi?id=174296
     5
     6        Reviewed by Mark Lam.
     7
     8        Previously, we treat <LF><CR> as one line terminator. So we increase line number by one.
     9        It caused a problem in scanning template literals. While template literals normalize
     10        <LF><CR> to <LF><LF>, we still needed to increase line number by only one.
     11        To handle it correctly, LineNumberAdder is introduced.
     12
     13        As of r219263, <LF><CR> is counted as two line terminators. So we do not need to have
     14        LineNumberAdder. Let's just use shiftLineTerminator() instead.
     15
     16        * parser/Lexer.cpp:
     17        (JSC::Lexer<T>::parseTemplateLiteral):
     18        (JSC::LineNumberAdder::LineNumberAdder): Deleted.
     19        (JSC::LineNumberAdder::clear): Deleted.
     20        (JSC::LineNumberAdder::add): Deleted.
     21
    1222017-07-09  Dan Bernstein  <mitz@apple.com>
    223
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r219263 r219285  
    13761376}
    13771377
    1378 // While the lexer accepts <LF><CR> (not <CR><LF>) sequence
    1379 // as one line terminator and increments one line number,
    1380 // TemplateLiteral considers it as two line terminators <LF> and <CR>.
    1381 //
    1382 // TemplateLiteral normalizes line terminators as follows.
    1383 //
    1384 // <LF> => <LF>
    1385 // <CR> => <LF>
    1386 // <CR><LF> => <LF>
    1387 // <\u2028> => <\u2028>
    1388 // <\u2029> => <\u2029>
    1389 //
    1390 // So, <LF><CR> should be normalized to <LF><LF>.
    1391 // However, the lexer should increment the line number only once for <LF><CR>.
    1392 //
    1393 // To achieve this, LineNumberAdder holds the current status of line terminator sequence.
    1394 // When TemplateLiteral lexer encounters a line terminator, it notifies to LineNumberAdder.
    1395 // LineNumberAdder maintains the status and increments the line number when it's necessary.
    1396 // For example, LineNumberAdder increments the line number only once for <LF><CR> and <CR><LF>.
    1397 template<typename CharacterType>
    1398 class LineNumberAdder {
    1399 public:
    1400     LineNumberAdder(int& lineNumber)
    1401         : m_lineNumber(lineNumber)
    1402     {
    1403     }
    1404 
    1405     void clear()
    1406     {
    1407         m_previous = 0;
    1408     }
    1409 
    1410     void add(CharacterType character)
    1411     {
    1412         ASSERT(Lexer<CharacterType>::isLineTerminator(character));
    1413         if (m_previous == '\r' && character == '\n')
    1414             m_previous = 0;
    1415         else {
    1416             ++m_lineNumber;
    1417             m_previous = character;
    1418         }
    1419     }
    1420 
    1421 private:
    1422     int& m_lineNumber;
    1423     CharacterType m_previous { 0 };
    1424 };
    1425 
    14261378template <typename T>
    14271379typename Lexer<T>::StringParseResult Lexer<T>::parseTemplateLiteral(JSTokenData* tokenData, RawStringsBuildMode rawStringsBuildMode)
     
    14311383    const T* rawStringStart = currentSourcePtr();
    14321384
    1433     LineNumberAdder<T> lineNumberAdder(m_lineNumber);
    1434 
    14351385    while (m_current != '`') {
    14361386        if (UNLIKELY(m_current == '\\')) {
    1437             lineNumberAdder.clear();
    14381387            if (stringStart != currentSourcePtr())
    14391388                append16(stringStart, currentSourcePtr() - stringStart);
     
    14561405                    }
    14571406
    1458                     lineNumberAdder.add(m_current);
    1459                     shift();
    1460                     if (m_current == '\n') {
    1461                         lineNumberAdder.add(m_current);
    1462                         shift();
    1463                     }
    1464 
     1407                    shiftLineTerminator();
    14651408                    rawStringStart = currentSourcePtr();
    1466                 } else {
    1467                     lineNumberAdder.add(m_current);
    1468                     shift();
    1469                 }
     1409                } else
     1410                    shiftLineTerminator();
    14701411            } else {
    14711412                bool strictMode = true;
     
    14941435            if (atEnd()) {
    14951436                m_lexErrorMessage = ASCIILiteral("Unexpected EOF");
    1496                 return atEnd() ? StringUnterminated : StringCannotBeParsed;
     1437                return StringUnterminated;
    14971438            }
    14981439
     
    15081449                    if (rawStringsBuildMode == RawStringsBuildMode::BuildRawStrings)
    15091450                        m_bufferForRawTemplateString16.append('\n');
    1510                     lineNumberAdder.add(m_current);
    1511                     shift();
    1512                     if (m_current == '\n') {
    1513                         lineNumberAdder.add(m_current);
    1514                         shift();
    1515                     }
     1451                    shiftLineTerminator();
    15161452                    stringStart = currentSourcePtr();
    15171453                    rawStringStart = currentSourcePtr();
    1518                 } else {
    1519                     lineNumberAdder.add(m_current);
    1520                     shift();
    1521                 }
     1454                } else
     1455                    shiftLineTerminator();
    15221456                continue;
    15231457            }
     
    15251459        }
    15261460
    1527         lineNumberAdder.clear();
    15281461        shift();
    15291462    }
Note: See TracChangeset for help on using the changeset viewer.