Skip to content
Permalink
Browse files
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.

Canonical link: https://commits.webkit.org/60477@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@69906 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ojhunt committed Oct 16, 2010
1 parent 3aea533 commit b2899517de6d7e43fa4f5c4671c8fc26944609df
Showing 7 changed files with 87 additions and 6 deletions.
@@ -1,3 +1,37 @@
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 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Dirk Schulze.
@@ -901,12 +901,13 @@ template <class TreeBuilder> TreeStatement JSParser::parseThrowStatement(TreeBui
int eStart = tokenStart();
int startLine = tokenLine();
next();

failIfTrue(autoSemiColon());

TreeExpression expr = parseExpression(context);
failIfFalse(expr);
int eEnd = lastTokenEnd();
int endLine = tokenLine();
failIfFalse(autoSemiColon());

return context.createThrowStatement(expr, eStart, eEnd, startLine, endLine);
}
@@ -1028,11 +1028,6 @@ JSTokenType Lexer::lex(JSTokenData* lvalp, JSTokenInfo* llocp, LexType lexType,
shiftLineTerminator();
m_atLineStart = true;
m_terminator = true;
if (lastTokenWasRestrKeyword()) {
token = SEMICOLON;
m_delimited = true;
goto returnToken;
}
goto start;
case CharacterInvalid:
goto returnError;
@@ -1,3 +1,16 @@
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.

2010-10-15 Mihai Parparita <mihaip@chromium.org>

Reviewed by James Robinson.
@@ -0,0 +1,17 @@
Test to make sure we don't incorrectly insert a semi colon after a break statement

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS do { if(0) break
;else true; } while (0) is true
PASS do { if(0) continue
;else true; } while (0) is true
PASS (function(){if (0) return
;else return true;})() is true
PASS if (0) throw
'Shouldn't have parsed this.'; threw exception SyntaxError: Parse error.
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="resources/js-test-style.css">
<script src="resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script src="script-tests/break-ASI.js"></script>
<script src="resources/js-test-post.js"></script>
</body>
</html>
@@ -0,0 +1,8 @@
description("Test to make sure we don't incorrectly insert a semi colon after a break statement");

shouldBeTrue("do { if(0) break\n;else true; } while (0)")
shouldBeTrue("do { if(0) continue\n;else true; } while (0)")
shouldBeTrue("(function(){if (0) return\n;else return true;})()")
shouldThrow("if (0) throw\n'Shouldn\'t have parsed this.';")

var successfullyParsed = true;

0 comments on commit b289951

Please sign in to comment.