Skip to content
Permalink
Browse files
Computed Property names should allow only AssignmentExpressions not a…
…ny 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.

Canonical link: https://commits.webkit.org/160960@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181829 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JosephPecoraro committed Mar 22, 2015
1 parent e9f120b commit ca86dae8bfd3258e7d18846adfc6659f55e15d9e
Showing 7 changed files with 61 additions and 2 deletions.
@@ -1,3 +1,17 @@
2015-03-21 Joseph Pecoraro <pecoraro@apple.com>

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

Reviewed by Ryosuke Niwa.

* 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.

2015-03-21 Benjamin Poulain <bpoulain@apple.com>

Import the blink test fast/css/currentcolor-strict-mode.html
@@ -6,6 +6,9 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS ({[a]: true}.propertyName) is true
PASS 'use strict';({[a]: true}.propertyName) is true
PASS (function(){'use strict';return ({[a]: true}.propertyName)})() is true
PASS ({[(1,a)]: true}.propertyName) is true
PASS 'use strict';({[(1,a)]: true}.propertyName) is true
PASS (function(){'use strict';return ({[(1,a)]: true}.propertyName)})() is true
PASS ({[a+1]: true}.propertyName1) is true
PASS 'use strict';({[a+1]: true}.propertyName1) is true
PASS (function(){'use strict';return ({[a+1]: true}.propertyName1)})() is true
@@ -48,6 +51,18 @@ PASS (function(){'use strict';return ({[a]: true, get '0'(){ return false; }}[0]
PASS ({__proto__: {get '0'(){ return false; }}, [a]: true}[0]) is true
PASS 'use strict';({__proto__: {get '0'(){ return false; }}, [a]: true}[0]) is true
PASS (function(){'use strict';return ({__proto__: {get '0'(){ return false; }}, [a]: true}[0])})() is true
PASS ({[1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS 'use strict';({[1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS (function(){'use strict';return ({[1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({propertyName: false, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS 'use strict';({propertyName: false, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS (function(){'use strict';return ({propertyName: false, [1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({[1,a]: false, propertyName: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS 'use strict';({[1,a]: false, propertyName: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS (function(){'use strict';return ({[1,a]: false, propertyName: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({get propertyName(){ return false; }, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS 'use strict';({get propertyName(){ return false; }, [1,a]: true}.propertyName) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS (function(){'use strict';return ({get propertyName(){ return false; }, [1,a]: true}.propertyName)})() threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS successfullyParsed is true

TEST COMPLETE
@@ -50,7 +50,8 @@ PASS o = { ['set'](x, y) { return x + y; } }; did not throw exception.
PASS o.set('hello', 'world') is 'helloworld'
PASS ({ [](,,,){} }) threw exception SyntaxError: Unexpected token ']'.
PASS ({ [1+](){} }) threw exception SyntaxError: Unexpected token ']'.
PASS ({ [1,](){} }) threw exception SyntaxError: Unexpected token ']'.
PASS ({ [1,](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({ [1,'name'](){} }) threw exception SyntaxError: Unexpected token ','. Expected ']' to end a computed property name..
PASS ({ [[1](){} }) threw exception SyntaxError: Unexpected token '{'. Expected ']' to end a computed property name..
PASS ({ [foo](,,,){} }) threw exception SyntaxError: Unexpected token ','. Expected a parameter pattern or a ')' in parameter list..
PASS ({ [foo](a{}, bar(){} }) threw exception SyntaxError: Unexpected token '{'. Expected a ')' or a ',' after a parameter declaration..
@@ -9,7 +9,9 @@ function runTest(test)
shouldBeTrue("'use strict';"+test);
shouldBeTrue("(function(){'use strict';return "+test+"})()");
}

runTest("{[a]: true}.propertyName")
runTest("{[(1,a)]: true}.propertyName")
runTest("{[a+1]: true}.propertyName1")
runTest("{propertyName: false, [a]: true}.propertyName")
runTest("{[a]: false, propertyName: true}.propertyName")
@@ -25,3 +27,17 @@ runTest("{[a]: false, 0: true}[0]")
runTest("{get '0'(){ return false; }, [a]: true}[0]")
runTest("{[a]: true, get '0'(){ return false; }}[0]")
runTest("{__proto__: {get '0'(){ return false; }}, [a]: true}[0]")

function runTestThrow(test)
{
test = "(" + test + ")"
shouldThrow(test);
shouldThrow("'use strict';"+test);
shouldThrow("(function(){'use strict';return "+test+"})()");
}

a = "propertyName"
runTestThrow("{[1,a]: true}.propertyName")
runTestThrow("{propertyName: false, [1,a]: true}.propertyName")
runTestThrow("{[1,a]: false, propertyName: true}.propertyName")
runTestThrow("{get propertyName(){ return false; }, [1,a]: true}.propertyName")
@@ -62,6 +62,7 @@ shouldBe("o.set('hello', 'world')", "'helloworld'");
shouldThrow("({ [](,,,){} })");
shouldThrow("({ [1+](){} })");
shouldThrow("({ [1,](){} })");
shouldThrow("({ [1,'name'](){} })");
shouldThrow("({ [[1](){} })");
shouldThrow("({ [foo](,,,){} })");
shouldThrow("({ [foo](a{}, bar(){} })");
@@ -1,3 +1,15 @@
2015-03-21 Joseph Pecoraro <pecoraro@apple.com>

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

Reviewed by Ryosuke Niwa.

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

2015-03-21 Andreas Kling <akling@apple.com>

Make UnlinkedFunctionExecutable fit in a 128-byte cell.
@@ -2004,7 +2004,7 @@ template <class TreeBuilder> TreeProperty Parser<LexerType>::parseProperty(TreeB
}
case OPENBRACKET: {
next();
auto propertyName = parseExpression(context);
auto propertyName = parseAssignmentExpression(context);
failIfFalse(propertyName, "Cannot parse computed property name");
handleProductionOrFail(CLOSEBRACKET, "]", "end", "computed property name");

0 comments on commit ca86dae

Please sign in to comment.