Title: [183382] trunk
Revision
183382
Author
[email protected]
Date
2015-04-26 21:18:18 -0700 (Sun, 26 Apr 2015)

Log Message

Getter or setter method named "prototype" or "constrcutor" should throw SyntaxError
https://bugs.webkit.org/show_bug.cgi?id=144243

Reviewed by Darin Adler.

Source/_javascript_Core:

Fixed the bug by adding explicit checks in parseGetterSetter when we're parsing class methods.

* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseGetterSetter):

LayoutTests:

Added tests cases to both tests. Also added test cases missing from _expression_ tests.

* js/class-syntax-declaration-expected.txt:
* js/class-syntax-_expression_-expected.txt:
* js/script-tests/class-syntax-declaration.js:
* js/script-tests/class-syntax-_expression_.js:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (183381 => 183382)


--- trunk/LayoutTests/ChangeLog	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/LayoutTests/ChangeLog	2015-04-27 04:18:18 UTC (rev 183382)
@@ -1,3 +1,17 @@
+2015-04-26  Ryosuke Niwa  <[email protected]>
+
+        Getter or setter method named "prototype" or "constrcutor" should throw SyntaxError
+        https://bugs.webkit.org/show_bug.cgi?id=144243
+
+        Reviewed by Darin Adler.
+
+        Added tests cases to both tests. Also added test cases missing from _expression_ tests.
+
+        * js/class-syntax-declaration-expected.txt:
+        * js/class-syntax-_expression_-expected.txt:
+        * js/script-tests/class-syntax-declaration.js:
+        * js/script-tests/class-syntax-_expression_.js:
+
 2015-04-26  Said Abou-Hallawa  <[email protected]>
 
         SVGFilterBuilder should drive the builtin sourceAlpha from the passed sourceGraphic

Modified: trunk/LayoutTests/js/class-syntax-declaration-expected.txt (183381 => 183382)


--- trunk/LayoutTests/js/class-syntax-declaration-expected.txt	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/LayoutTests/js/class-syntax-declaration-expected.txt	2015-04-27 04:18:18 UTC (rev 183382)
@@ -22,9 +22,13 @@
 PASS class X { ( } threw exception SyntaxError: Unexpected token '('. Expected an identifier..
 PASS class X {} did not throw exception.
 PASS class X { constructor() {} constructor() {} } threw exception SyntaxError: Cannot declare multiple constructors in a single class..
+PASS class X { get constructor() {} } threw exception SyntaxError: Cannot declare a getter or setter named 'constructor'..
+PASS class X { set constructor() {} } threw exception SyntaxError: Cannot declare a getter or setter named 'constructor'..
 PASS class X { constructor() {} static constructor() { return staticMethodValue; } } did not throw exception.
 PASS class X { constructor() {} static constructor() { return staticMethodValue; } }; X.constructor() is staticMethodValue
 PASS class X { constructor() {} static prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS class X { constructor() {} static get prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS class X { constructor() {} static set prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
 PASS class X { constructor() {} prototype() { return instanceMethodValue; } } did not throw exception.
 PASS class X { constructor() {} prototype() { return instanceMethodValue; } }; (new X).prototype() is instanceMethodValue
 PASS class X { constructor() {} set foo(a) {} } did not throw exception.

Modified: trunk/LayoutTests/js/class-syntax-_expression_-expected.txt (183381 => 183382)


--- trunk/LayoutTests/js/class-syntax-_expression_-expected.txt	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/LayoutTests/js/class-syntax-_expression_-expected.txt	2015-04-27 04:18:18 UTC (rev 183382)
@@ -20,11 +20,22 @@
 PASS x = class { ( } threw exception SyntaxError: Unexpected token '('. Expected an identifier..
 PASS x = class {} did not throw exception.
 PASS x = class { constructor() {} constructor() {} } threw exception SyntaxError: Cannot declare multiple constructors in a single class..
+PASS x = class { get constructor() {} } threw exception SyntaxError: Cannot declare a getter or setter named 'constructor'..
+PASS x = class { set constructor() {} } threw exception SyntaxError: Cannot declare a getter or setter named 'constructor'..
 PASS x = class { constructor() {} static constructor() { return staticMethodValue; } } did not throw exception.
-PASS x.constructor() is staticMethodValue
+PASS x = class { constructor() {} static constructor() { return staticMethodValue; } }; x.constructor() is staticMethodValue
 PASS x = class { constructor() {} static prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
-PASS x = class { constructor() {} prototype() { return instanceMethodValue; } } did not throw exception.
-PASS (new x).prototype() is instanceMethodValue
+PASS x = class { constructor() {} static get prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS x = class { constructor() {} static set prototype() {} } threw exception SyntaxError: Cannot declare a static method named 'prototype'..
+PASS x = class  { constructor() {} prototype() { return instanceMethodValue; } } did not throw exception.
+PASS x = class { constructor() {} prototype() { return instanceMethodValue; } }; (new x).prototype() is instanceMethodValue
+PASS x = class { constructor() {} set foo(a) {} } did not throw exception.
+PASS x = class { constructor() {} set foo({x, y}) {} } did not throw exception.
+PASS x = class { constructor() {} set foo() {} } threw exception SyntaxError: Unexpected token ')'. setter functions must have one parameter..
+PASS x = class { constructor() {} set foo(a, b) {} } threw exception SyntaxError: Unexpected token ','. setter functions must have one parameter..
+PASS x = class { constructor() {} get foo() {} } did not throw exception.
+PASS x = class { constructor() {} get foo(x) {} } threw exception SyntaxError: Unexpected identifier 'x'. getter functions must have no parameters..
+PASS x = class { constructor() {} get foo({x, y}) {} } threw exception SyntaxError: Unexpected token '{'. getter functions must have no parameters..
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/class-syntax-declaration.js (183381 => 183382)


--- trunk/LayoutTests/js/script-tests/class-syntax-declaration.js	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/LayoutTests/js/script-tests/class-syntax-declaration.js	2015-04-27 04:18:18 UTC (rev 183382)
@@ -35,10 +35,16 @@
 shouldThrow("class X {", "'SyntaxError: Unexpected end of script'");
 shouldThrow("class X { ( }", "'SyntaxError: Unexpected token \\'(\\'. Expected an identifier.'");
 shouldNotThrow("class X {}");
+
 shouldThrow("class X { constructor() {} constructor() {} }", "'SyntaxError: Cannot declare multiple constructors in a single class.'");
+shouldThrow("class X { get constructor() {} }", "'SyntaxError: Cannot declare a getter or setter named \\'constructor\\'.'");
+shouldThrow("class X { set constructor() {} }", "'SyntaxError: Cannot declare a getter or setter named \\'constructor\\'.'");
 shouldNotThrow("class X { constructor() {} static constructor() { return staticMethodValue; } }");
 shouldBe("class X { constructor() {} static constructor() { return staticMethodValue; } }; X.constructor()", "staticMethodValue");
+
 shouldThrow("class X { constructor() {} static prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldThrow("class X { constructor() {} static get prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldThrow("class X { constructor() {} static set prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
 shouldNotThrow("class X { constructor() {} prototype() { return instanceMethodValue; } }");
 shouldBe("class X { constructor() {} prototype() { return instanceMethodValue; } }; (new X).prototype()", "instanceMethodValue");
 

Modified: trunk/LayoutTests/js/script-tests/class-syntax-_expression_.js (183381 => 183382)


--- trunk/LayoutTests/js/script-tests/class-syntax-_expression_.js	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/LayoutTests/js/script-tests/class-syntax-_expression_.js	2015-04-27 04:18:18 UTC (rev 183382)
@@ -33,11 +33,25 @@
 shouldThrow("x = class {", "'SyntaxError: Unexpected end of script'");
 shouldThrow("x = class { ( }", "'SyntaxError: Unexpected token \\'(\\'. Expected an identifier.'");
 shouldNotThrow("x = class {}");
+
 shouldThrow("x = class { constructor() {} constructor() {} }", "'SyntaxError: Cannot declare multiple constructors in a single class.'");
+shouldThrow("x = class { get constructor() {} }", "'SyntaxError: Cannot declare a getter or setter named \\'constructor\\'.'");
+shouldThrow("x = class { set constructor() {} }", "'SyntaxError: Cannot declare a getter or setter named \\'constructor\\'.'");
 shouldNotThrow("x = class { constructor() {} static constructor() { return staticMethodValue; } }");
-shouldBe("x.constructor()", "staticMethodValue");
+shouldBe("x = class { constructor() {} static constructor() { return staticMethodValue; } }; x.constructor()", "staticMethodValue");
+
 shouldThrow("x = class { constructor() {} static prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
-shouldNotThrow("x = class { constructor() {} prototype() { return instanceMethodValue; } }");
-shouldBe("(new x).prototype()", "instanceMethodValue");
+shouldThrow("x = class { constructor() {} static get prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldThrow("x = class { constructor() {} static set prototype() {} }", "'SyntaxError: Cannot declare a static method named \\'prototype\\'.'");
+shouldNotThrow("x = class  { constructor() {} prototype() { return instanceMethodValue; } }");
+shouldBe("x = class { constructor() {} prototype() { return instanceMethodValue; } }; (new x).prototype()", "instanceMethodValue");
 
+shouldNotThrow("x = class { constructor() {} set foo(a) {} }");
+shouldNotThrow("x = class { constructor() {} set foo({x, y}) {} }");
+shouldThrow("x = class { constructor() {} set foo() {} }");
+shouldThrow("x = class { constructor() {} set foo(a, b) {} }");
+shouldNotThrow("x = class { constructor() {} get foo() {} }");
+shouldThrow("x = class { constructor() {} get foo(x) {} }");
+shouldThrow("x = class { constructor() {} get foo({x, y}) {} }");
+
 var successfullyParsed = true;

Modified: trunk/Source/_javascript_Core/ChangeLog (183381 => 183382)


--- trunk/Source/_javascript_Core/ChangeLog	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-04-27 04:18:18 UTC (rev 183382)
@@ -1,3 +1,15 @@
+2015-04-26  Ryosuke Niwa  <[email protected]>
+
+        Getter or setter method named "prototype" or "constrcutor" should throw SyntaxError
+        https://bugs.webkit.org/show_bug.cgi?id=144243
+
+        Reviewed by Darin Adler.
+
+        Fixed the bug by adding explicit checks in parseGetterSetter when we're parsing class methods.
+
+        * parser/Parser.cpp:
+        (JSC::Parser<LexerType>::parseGetterSetter):
+
 2015-04-26  Jordan Harband  <[email protected]>
 
         Map#forEach does not pass "map" argument to callback.

Modified: trunk/Source/_javascript_Core/parser/Parser.cpp (183381 => 183382)


--- trunk/Source/_javascript_Core/parser/Parser.cpp	2015-04-27 03:51:23 UTC (rev 183381)
+++ trunk/Source/_javascript_Core/parser/Parser.cpp	2015-04-27 04:18:18 UTC (rev 183382)
@@ -2077,9 +2077,13 @@
 {
     const Identifier* stringPropertyName = 0;
     double numericPropertyName = 0;
-    if (m_token.m_type == IDENT || m_token.m_type == STRING)
+    if (m_token.m_type == IDENT || m_token.m_type == STRING) {
         stringPropertyName = m_token.m_data.ident;
-    else if (m_token.m_type == DOUBLE || m_token.m_type == INTEGER)
+        semanticFailIfTrue(superBinding == SuperBinding::Needed && *stringPropertyName == m_vm->propertyNames->prototype,
+            "Cannot declare a static method named 'prototype'");
+        semanticFailIfTrue(superBinding == SuperBinding::Needed && *stringPropertyName == m_vm->propertyNames->constructor,
+            "Cannot declare a getter or setter named 'constructor'");
+    } else if (m_token.m_type == DOUBLE || m_token.m_type == INTEGER)
         numericPropertyName = m_token.m_data.doubleValue;
     else
         failDueToUnexpectedToken();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to