⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181829 in webkit


Ignore:
Timestamp:
Mar 21, 2015, 8:14:47 PM (11 years ago)
Author:
Joseph Pecoraro
Message:

Computed Property names should allow only AssignmentExpressions not any Expression
https://bugs.webkit.org/show_bug.cgi?id=142902

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseProperty):
Limit computed expressions to just assignment expressions instead of
any expression (which allowed comma expressions).

LayoutTests:

  • js/basic-computed-property-name-expected.txt:
  • js/object-literal-computed-methods-expected.txt:
  • js/script-tests/basic-computed-property-name.js:

(runTest.runTest.runTest.runTest.runTest.runTest.runTest.runTestThrow):

  • js/script-tests/object-literal-computed-methods.js:

Test that comma expressions are not allowed in computed property/method names.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181827 r181829  
     12015-03-21  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Computed Property names should allow only AssignmentExpressions not any Expression
     4        https://bugs.webkit.org/show_bug.cgi?id=142902
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * js/basic-computed-property-name-expected.txt:
     9        * js/object-literal-computed-methods-expected.txt:
     10        * js/script-tests/basic-computed-property-name.js:
     11        (runTest.runTest.runTest.runTest.runTest.runTest.runTest.runTestThrow):
     12        * js/script-tests/object-literal-computed-methods.js:
     13        Test that comma expressions are not allowed in computed property/method names.
     14
    1152015-03-21  Benjamin Poulain  <bpoulain@apple.com>
    216
  • trunk/LayoutTests/js/basic-computed-property-name-expected.txt

    r181807 r181829  
    77PASS 'use strict';({[a]: true}.propertyName) is true
    88PASS (function(){'use strict';return ({[a]: true}.propertyName)})() is true
     9PASS ({[(1,a)]: true}.propertyName) is true
     10PASS 'use strict';({[(1,a)]: true}.propertyName) is true
     11PASS (function(){'use strict';return ({[(1,a)]: true}.propertyName)})() is true
    912PASS ({[a+1]: true}.propertyName1) is true
    1013PASS 'use strict';({[a+1]: true}.propertyName1) is true
     
    4952PASS 'use strict';({__proto__: {get '0'(){ return false; }}, [a]: true}[0]) is true
    5053PASS (function(){'use strict';return ({__proto__: {get '0'(){ return false; }}, [a]: true}[0])})() is true
     54PASS ({[1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     55PASS 'use strict';({[1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     56PASS (function(){'use strict';return ({[1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     57PASS ({propertyName: false, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     58PASS 'use strict';({propertyName: false, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     59PASS (function(){'use strict';return ({propertyName: false, [1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     60PASS ({[1,a]: false, propertyName: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     61PASS 'use strict';({[1,a]: false, propertyName: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     62PASS (function(){'use strict';return ({[1,a]: false, propertyName: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     63PASS ({get propertyName(){ return false; }, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     64PASS 'use strict';({get propertyName(){ return false; }, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     65PASS (function(){'use strict';return ({get propertyName(){ return false; }, [1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
    5166PASS successfullyParsed is true
    5267
  • trunk/LayoutTests/js/object-literal-computed-methods-expected.txt

    r181810 r181829  
    5151PASS ({ [](,,,){} }) threw exception SyntaxError: Unexpected token ']'.
    5252PASS ({ [1+](){} }) threw exception SyntaxError: Unexpected token ']'.
    53 PASS ({ [1,](){} }) threw exception SyntaxError: Unexpected token ']'.
     53PASS ({ [1,](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
     54PASS ({ [1,'name'](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
    5455PASS ({ [[1](){} }) threw exception SyntaxError: Unexpected token '{'. Expected ']' to end a computed property name..
    5556PASS ({ [foo](,,,){} }) threw exception SyntaxError: Unexpected token ','. Expected a parameter pattern or a ')' in parameter list..
  • trunk/LayoutTests/js/script-tests/basic-computed-property-name.js

    r181807 r181829  
    1010    shouldBeTrue("(function(){'use strict';return "+test+"})()");
    1111}
     12
    1213runTest("{[a]: true}.propertyName")
     14runTest("{[(1,a)]: true}.propertyName")
    1315runTest("{[a+1]: true}.propertyName1")
    1416runTest("{propertyName: false, [a]: true}.propertyName")
     
    2628runTest("{[a]: true, get '0'(){ return false; }}[0]")
    2729runTest("{__proto__: {get '0'(){ return false; }}, [a]: true}[0]")
     30
     31function runTestThrow(test)
     32{
     33    test = "(" + test + ")"
     34    shouldThrow(test);
     35    shouldThrow("'use strict';"+test);
     36    shouldThrow("(function(){'use strict';return "+test+"})()");
     37}
     38
     39a = "propertyName"
     40runTestThrow("{[1,a]: true}.propertyName")
     41runTestThrow("{propertyName: false, [1,a]: true}.propertyName")
     42runTestThrow("{[1,a]: false, propertyName: true}.propertyName")
     43runTestThrow("{get propertyName(){ return false; }, [1,a]: true}.propertyName")
  • trunk/LayoutTests/js/script-tests/object-literal-computed-methods.js

    r181183 r181829  
    6363shouldThrow("({ [1+](){} })");
    6464shouldThrow("({ [1,](){} })");
     65shouldThrow("({ [1,'name'](){} })");
    6566shouldThrow("({ [[1](){} })");
    6667shouldThrow("({ [foo](,,,){} })");
  • trunk/Source/JavaScriptCore/ChangeLog

    r181828 r181829  
     12015-03-21  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Computed Property names should allow only AssignmentExpressions not any Expression
     4        https://bugs.webkit.org/show_bug.cgi?id=142902
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * parser/Parser.cpp:
     9        (JSC::Parser<LexerType>::parseProperty):
     10        Limit computed expressions to just assignment expressions instead of
     11        any expression (which allowed comma expressions).
     12
    1132015-03-21  Andreas Kling  <akling@apple.com>
    214
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r181818 r181829  
    20052005    case OPENBRACKET: {
    20062006        next();
    2007         auto propertyName = parseExpression(context);
     2007        auto propertyName = parseAssignmentExpression(context);
    20082008        failIfFalse(propertyName, "Cannot parse computed property name");
    20092009        handleProductionOrFail(CLOSEBRACKET, "]", "end", "computed property name");
Note: See TracChangeset for help on using the changeset viewer.