Title: [181829] trunk
Revision
181829
Author
[email protected]
Date
2015-03-21 20:14:47 -0700 (Sat, 21 Mar 2015)

Log 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/_javascript_Core:

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

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (181828 => 181829)


--- trunk/LayoutTests/ChangeLog	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/LayoutTests/ChangeLog	2015-03-22 03:14:47 UTC (rev 181829)
@@ -1,3 +1,17 @@
+2015-03-21  Joseph Pecoraro  <[email protected]>
+
+        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  <[email protected]>
 
         Import the blink test fast/css/currentcolor-strict-mode.html

Modified: trunk/LayoutTests/js/basic-computed-property-name-expected.txt (181828 => 181829)


--- trunk/LayoutTests/js/basic-computed-property-name-expected.txt	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/LayoutTests/js/basic-computed-property-name-expected.txt	2015-03-22 03:14:47 UTC (rev 181829)
@@ -6,6 +6,9 @@
 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 ({__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

Modified: trunk/LayoutTests/js/object-literal-computed-methods-expected.txt (181828 => 181829)


--- trunk/LayoutTests/js/object-literal-computed-methods-expected.txt	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/LayoutTests/js/object-literal-computed-methods-expected.txt	2015-03-22 03:14:47 UTC (rev 181829)
@@ -50,7 +50,8 @@
 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..

Modified: trunk/LayoutTests/js/script-tests/basic-computed-property-name.js (181828 => 181829)


--- trunk/LayoutTests/js/script-tests/basic-computed-property-name.js	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/LayoutTests/js/script-tests/basic-computed-property-name.js	2015-03-22 03:14:47 UTC (rev 181829)
@@ -9,7 +9,9 @@
     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("{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")

Modified: trunk/LayoutTests/js/script-tests/object-literal-computed-methods.js (181828 => 181829)


--- trunk/LayoutTests/js/script-tests/object-literal-computed-methods.js	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/LayoutTests/js/script-tests/object-literal-computed-methods.js	2015-03-22 03:14:47 UTC (rev 181829)
@@ -62,6 +62,7 @@
 shouldThrow("({ [](,,,){} })");
 shouldThrow("({ [1+](){} })");
 shouldThrow("({ [1,](){} })");
+shouldThrow("({ [1,'name'](){} })");
 shouldThrow("({ [[1](){} })");
 shouldThrow("({ [foo](,,,){} })");
 shouldThrow("({ [foo](a{}, bar(){} })");

Modified: trunk/Source/_javascript_Core/ChangeLog (181828 => 181829)


--- trunk/Source/_javascript_Core/ChangeLog	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-03-22 03:14:47 UTC (rev 181829)
@@ -1,3 +1,15 @@
+2015-03-21  Joseph Pecoraro  <[email protected]>
+
+        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  <[email protected]>
 
         Make UnlinkedFunctionExecutable fit in a 128-byte cell.

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (181828 => 181829)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2015-03-22 00:07:46 UTC (rev 181828)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2015-03-22 03:14:47 UTC (rev 181829)
@@ -2004,7 +2004,7 @@
     }
     case OPENBRACKET: {
         next();
-        auto propertyName = parseExpression(context);
+        auto propertyName = parseAssignmentExpression(context);
         failIfFalse(propertyName, "Cannot parse computed property name");
         handleProductionOrFail(CLOSEBRACKET, "]", "end", "computed property name");
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to