Changeset 69906 in webkit


Ignore:
Timestamp:
Oct 15, 2010 6:50:16 PM (14 years ago)
Author:
oliver@apple.com
Message:

2010-10-15 Oliver Hunt <oliver@apple.com>

Reviewed by Sam Weinig.

Automatic Semicolon Insertion incorrectly inserts semicolon after break, continue, and return followed by a newline
https://bugs.webkit.org/show_bug.cgi?id=47762

The old YACC parser depended on the lexer for some classes of semicolon insertion.
The new parser handles ASI entirely on its own so when the lexer inserts a semicolon
on its own the net result is a spurious semicolon in the input stream. This can result
in incorrect parsing in some cases:

if (0)

break

;else {}

Would result in a parse failure as the output from the lexer is essentially

if (0)

break

;;else

So the second semicolon is interpreted as a empty statement, which terminates the if,
making the else an error.

  • parser/JSParser.cpp: (JSC::JSParser::parseThrowStatement): Parsing of throw statement was wrong, and only worked due to the weird behaviour in the lexer
  • parser/Lexer.cpp: (JSC::Lexer::lex): Remove bogus semicolon insertion from the newline handling

2010-10-15 Oliver Hunt <oliver@apple.com>

Reviewed by Sam Weinig.

ASI incorrectly inserts semicolon after break, continue, and return followed by a newline
https://bugs.webkit.org/show_bug.cgi?id=47762

tests for correct ASI following break, continue, and return

  • fast/js/break-ASI-expected.txt: Added.
  • fast/js/break-ASI.html: Added.
  • fast/js/script-tests/break-ASI.js: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r69850 r69906  
     12010-10-15  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Automatic Semicolon Insertion incorrectly inserts semicolon after break, continue, and return followed by a newline
     6        https://bugs.webkit.org/show_bug.cgi?id=47762
     7
     8        The old YACC parser depended on the lexer for some classes of semicolon insertion.
     9        The new parser handles ASI entirely on its own so when the lexer inserts a semicolon
     10        on its own the net result is a spurious semicolon in the input stream.  This can result
     11        in incorrect parsing in some cases:
     12
     13        if (0)
     14            break
     15        ;else {}
     16
     17        Would result in a parse failure as the output from the lexer is essentially
     18
     19        if (0)
     20             break
     21        ;;else
     22
     23        So the second semicolon is interpreted as a empty statement, which terminates the if,
     24        making the else an error.
     25
     26
     27        * parser/JSParser.cpp:
     28        (JSC::JSParser::parseThrowStatement):
     29          Parsing of throw statement was wrong, and only worked due to the weird behaviour
     30          in the lexer
     31        * parser/Lexer.cpp:
     32        (JSC::Lexer::lex):
     33          Remove bogus semicolon insertion from the newline handling
     34
    1352010-10-15  Nikolas Zimmermann  <nzimmermann@rim.com>
    236
  • trunk/JavaScriptCore/parser/JSParser.cpp

    r69516 r69906  
    902902    int startLine = tokenLine();
    903903    next();
     904   
     905    failIfTrue(autoSemiColon());
    904906
    905907    TreeExpression expr = parseExpression(context);
     
    907909    int eEnd = lastTokenEnd();
    908910    int endLine = tokenLine();
    909     failIfFalse(autoSemiColon());
    910911
    911912    return context.createThrowStatement(expr, eStart, eEnd, startLine, endLine);
  • trunk/JavaScriptCore/parser/Lexer.cpp

    r69516 r69906  
    10291029        m_atLineStart = true;
    10301030        m_terminator = true;
    1031         if (lastTokenWasRestrKeyword()) {
    1032             token = SEMICOLON;
    1033             m_delimited = true;
    1034             goto returnToken;
    1035         }
    10361031        goto start;
    10371032    case CharacterInvalid:
  • trunk/LayoutTests/ChangeLog

    r69903 r69906  
     12010-10-15  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        ASI incorrectly inserts semicolon after break, continue, and return followed by a newline
     6        https://bugs.webkit.org/show_bug.cgi?id=47762
     7
     8        tests for correct ASI following break, continue, and return
     9
     10        * fast/js/break-ASI-expected.txt: Added.
     11        * fast/js/break-ASI.html: Added.
     12        * fast/js/script-tests/break-ASI.js: Added.
     13
    1142010-10-15  Mihai Parparita  <mihaip@chromium.org>
    215
Note: See TracChangeset for help on using the changeset viewer.