Changeset 106297 in webkit


Ignore:
Timestamp:
Jan 30, 2012 3:59:20 PM (12 years ago)
Author:
oliver@apple.com
Message:

Unexpected syntax error
https://bugs.webkit.org/show_bug.cgi?id=77340

Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

Function calls and new expressions have the same semantics for
assignment, so should simply share their lhs handling.

  • parser/Parser.cpp:

(JSC::::parseMemberExpression):

LayoutTests:

Add new tests for correct parsing of new expressions

  • fast/js/parser-syntax-check-expected.txt:
  • fast/js/script-tests/parser-syntax-check.js:

(runTest):
(invalid):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106294 r106297  
     12012-01-30  Oliver Hunt  <oliver@apple.com>
     2
     3        Unexpected syntax error
     4        https://bugs.webkit.org/show_bug.cgi?id=77340
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Add new tests for correct parsing of new expressions
     9
     10        * fast/js/parser-syntax-check-expected.txt:
     11        * fast/js/script-tests/parser-syntax-check.js:
     12        (runTest):
     13        (invalid):
     14
    1152012-01-30  Tony Chang  <tony@chromium.org>
    216
  • trunk/LayoutTests/fast/js/parser-syntax-check-expected.txt

    r89228 r106297  
    568568PASS Valid:   "if (0) obj.foo\u03bb; "
    569569PASS Valid:   "function f() { if (0) obj.foo\u03bb;  }"
     570PASS Valid:   "if (0) new a(b+c).d = 5"
     571PASS Valid:   "function f() { if (0) new a(b+c).d = 5 }"
     572PASS Valid:   "if (0) new a(b+c) = 5"
     573PASS Valid:   "function f() { if (0) new a(b+c) = 5 }"
    570574PASS e.line is 1
    571575PASS foo is 'PASS'
  • trunk/LayoutTests/fast/js/script-tests/parser-syntax-check.js

    r98407 r106297  
    33);
    44
    5 function runTest(_a, throws)
     5function runTest(_a, errorType)
    66{
    77    var success;
     
    1414        success = !(e instanceof SyntaxError);
    1515    }
    16     if (throws == !success) {
    17         if (throws)
     16    if ((!!errorType) == !success) {
     17        if (errorType)
    1818            testPassed('Invalid: "' + _a + '"');
    1919        else
    2020            testPassed('Valid:   "' + _a + '"');
    2121    } else {
    22         if (throws)
    23             testFailed('Invalid: "' + _a + '" should throw SyntaxError: Parse error');
     22        if (errorType)
     23            testFailed('Invalid: "' + _a + '" should throw ' + errorType.name);
    2424        else
    25             testFailed('Valid:   "' + _a + '" should NOT throw SyntaxError: Parse error');
     25            testFailed('Valid:   "' + _a + '" should NOT throw ');
    2626    }
    2727}
     
    3434}
    3535
    36 function invalid(_a)
     36function invalid(_a, _type)
    3737{
     38    _type = _type || SyntaxError;
    3839    // Test both the grammar and the syntax checker
    3940    runTest(_a, true);
     
    361362valid("if (0) obj.foo_; ")
    362363valid("if (0) obj.foo\\u03bb; ")
     364valid("if (0) new a(b+c).d = 5");
     365valid("if (0) new a(b+c) = 5");
    363366
    364367try { eval("a.b.c = {};"); } catch(e1) { e=e1; shouldBe("e.line", "1") }
  • trunk/Source/JavaScriptCore/ChangeLog

    r106296 r106297  
     12012-01-30  Oliver Hunt  <oliver@apple.com>
     2
     3        Unexpected syntax error
     4        https://bugs.webkit.org/show_bug.cgi?id=77340
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Function calls and new expressions have the same semantics for
     9        assignment, so should simply share their lhs handling.
     10
     11        * parser/Parser.cpp:
     12        (JSC::::parseMemberExpression):
     13
    1142012-01-30  Gavin Barraclough  <barraclough@apple.com>
    215
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r105638 r106297  
    15131513        case OPENPAREN: {
    15141514            m_nonTrivialExpressionCount++;
     1515            int nonLHSCount = m_nonLHSCount;
    15151516            if (newCount) {
    15161517                newCount--;
    1517                 if (match(OPENPAREN)) {
    1518                     int exprEnd = lastTokenEnd();
    1519                     TreeArguments arguments = parseArguments(context);
    1520                     failIfFalse(arguments);
    1521                     base = context.createNewExpr(m_lexer->lastLineNumber(), base, arguments, start, exprEnd, lastTokenEnd());
    1522                 } else
    1523                     base = context.createNewExpr(m_lexer->lastLineNumber(), base, start, lastTokenEnd());               
     1518                int exprEnd = lastTokenEnd();
     1519                TreeArguments arguments = parseArguments(context);
     1520                failIfFalse(arguments);
     1521                base = context.createNewExpr(m_lexer->lastLineNumber(), base, arguments, start, exprEnd, lastTokenEnd());           
    15241522            } else {
    1525                 int nonLHSCount = m_nonLHSCount;
    15261523                int expressionEnd = lastTokenEnd();
    15271524                TreeArguments arguments = parseArguments(context);
    15281525                failIfFalse(arguments);
    15291526                base = context.makeFunctionCallNode(m_lexer->lastLineNumber(), base, arguments, expressionStart, expressionEnd, lastTokenEnd());
    1530                 m_nonLHSCount = nonLHSCount;
    15311527            }
     1528            m_nonLHSCount = nonLHSCount;
    15321529            break;
    15331530        }
Note: See TracChangeset for help on using the changeset viewer.