Changeset 221400 in webkit


Ignore:
Timestamp:
Aug 30, 2017 3:27:09 PM (7 years ago)
Author:
sbarati@apple.com
Message:

semicolon is being interpreted as an = in the LiteralParser
https://bugs.webkit.org/show_bug.cgi?id=176114

Reviewed by Oliver Hunt.

JSTests:

  • stress/jsonp-literal-parser-semicolon-is-not-assignment.js: Added.
  • stress/resources/literal-parser-test-case.js: Added.

Source/JavaScriptCore:

When lexing a semicolon in the LiteralParser, we were properly
setting the TokenType on the current token, however, we were
*returning* the wrong TokenType. The lex function both returns
the TokenType and sets it on the current token. Semicolon was
setting the TokenType to semicolon, but returning the TokenType
for '='. This caused programs like x;123 to be interpreted as
x=123.

  • runtime/LiteralParser.cpp:

(JSC::LiteralParser<CharType>::Lexer::lex):
(JSC::LiteralParser<CharType>::Lexer::next):

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r221358 r221400  
     12017-08-30  Saam Barati  <sbarati@apple.com>
     2
     3        semicolon is being interpreted as an = in the LiteralParser
     4        https://bugs.webkit.org/show_bug.cgi?id=176114
     5
     6        Reviewed by Oliver Hunt.
     7
     8        * stress/jsonp-literal-parser-semicolon-is-not-assignment.js: Added.
     9        * stress/resources/literal-parser-test-case.js: Added.
     10
    1112017-08-30  Oleksandr Skachkov  <gskachkov@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r221384 r221400  
     12017-08-30  Saam Barati  <sbarati@apple.com>
     2
     3        semicolon is being interpreted as an = in the LiteralParser
     4        https://bugs.webkit.org/show_bug.cgi?id=176114
     5
     6        Reviewed by Oliver Hunt.
     7
     8        When lexing a semicolon in the LiteralParser, we were properly
     9        setting the TokenType on the current token, however, we were
     10        *returning* the wrong TokenType. The lex function both returns
     11        the TokenType and sets it on the current token. Semicolon was
     12        setting the TokenType to semicolon, but returning the TokenType
     13        for '='. This caused programs like `x;123` to be interpreted as
     14        `x=123`.
     15
     16        * runtime/LiteralParser.cpp:
     17        (JSC::LiteralParser<CharType>::Lexer::lex):
     18        (JSC::LiteralParser<CharType>::Lexer::next):
     19
    1202017-08-22  Filip Pizlo  <fpizlo@apple.com>
    221
  • trunk/Source/JavaScriptCore/runtime/LiteralParser.cpp

    r208985 r221400  
    273273            token.type = TokSemi;
    274274            token.end = ++m_ptr;
    275             return TokAssign;
     275            return TokSemi;
    276276        }
    277277        if (isASCIIAlpha(*m_ptr) || *m_ptr == '_' || *m_ptr == '$')
     
    318318TokenType LiteralParser<CharType>::Lexer::next()
    319319{
     320    TokenType result;
    320321    if (m_mode == NonStrictJSON)
    321         return lex<NonStrictJSON>(m_currentToken);
    322     if (m_mode == JSONP)
    323         return lex<JSONP>(m_currentToken);
    324     return lex<StrictJSON>(m_currentToken);
     322        result = lex<NonStrictJSON>(m_currentToken);
     323    else if (m_mode == JSONP)
     324        result = lex<JSONP>(m_currentToken);
     325    else
     326        result = lex<StrictJSON>(m_currentToken);
     327    ASSERT(m_currentToken.type == result);
     328    return result;
    325329}
    326330
Note: See TracChangeset for help on using the changeset viewer.