Bug 1150855 - Disallow method syntax without curly brackets. r=efaust
authorTom Schuster <evilpies@gmail.com>
Fri, 22 May 2015 21:23:57 +0200
changeset 245226 6cf58656d6fb28c8ea79ae0b139a905aa8900bdf
parent 245225 bd2239b9df33324430c609bd0cec7467b7d202d1
child 245227 0135ea20609a4ab62db17a537b1885ad2170cb7a
push id28799
push userphilringnalda@gmail.com
push dateSat, 23 May 2015 20:31:44 +0000
treeherdermozilla-central@c3c0928c3cde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1150855
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1150855 - Disallow method syntax without curly brackets. r=efaust
js/src/frontend/Parser.cpp
js/src/tests/ecma_6/Class/methDefn.js
js/src/tests/js1_8_5/reflect-parse/classes.js
js/src/tests/js1_8_5/reflect-parse/methodDefn.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -2561,17 +2561,17 @@ Parser<ParseHandler>::functionArgsAndBod
     }
 
     // Parse the function body.
     FunctionBodyType bodyType = StatementListBody;
     TokenKind tt;
     if (!tokenStream.getToken(&tt, TokenStream::Operand))
         return false;
     if (tt != TOK_LC) {
-        if (funbox->isStarGenerator()) {
+        if (funbox->isStarGenerator() || kind == Method || kind == ClassConstructor) {
             report(ParseError, false, null(), JSMSG_CURLY_BEFORE_BODY);
             return false;
         }
 
         if (kind != Arrow) {
 #if JS_HAS_EXPR_CLOSURES
             addTelemetry(JSCompartment::DeprecatedExpressionClosure);
 #else
--- a/js/src/tests/ecma_6/Class/methDefn.js
+++ b/js/src/tests/ecma_6/Class/methDefn.js
@@ -27,16 +27,19 @@ syntaxError("b = {a()");
 syntaxError("b = {a()}");
 syntaxError("b = {a(){}");
 syntaxError("b = {a){}");
 syntaxError("b = {a}}");
 syntaxError("b = {a{}}");
 syntaxError("b = {a({}}");
 syntaxError("b = {a@(){}}");
 syntaxError("b = {a() => 0}");
+syntaxError("b = {a() void 0}");
+syntaxError("b = {a() 1}");
+syntaxError("b = {a() false}");
 
 b = {a(){return 5;}};
 assertEq(b.a(), 5);
 
 b = {a(){return "hey";}};
 assertEq(b.a(), "hey");
 
 b = {a(){return arguments;}};
--- a/js/src/tests/js1_8_5/reflect-parse/classes.js
+++ b/js/src/tests/js1_8_5/reflect-parse/classes.js
@@ -403,20 +403,20 @@ function testClasses() {
     assertError("(()=>super.prop)", SyntaxError);
     assertError("function *foo() { super.prop; }", SyntaxError);
     assertError("super.prop", SyntaxError);
     assertError("function foo () { super['prop']; }", SyntaxError);
     assertError("(function () { super['prop']; }", SyntaxError);
     assertError("(()=>super['prop'])", SyntaxError);
     assertError("function *foo() { super['prop']; }", SyntaxError);
     assertError("super['prop']", SyntaxError);
-    
+
     // Or inside functions inside method definitions...
     assertClassError("class NAME { constructor() { function nested() { super.prop; }}}", SyntaxError);
-    
+
     // Bare super is forbidden
     assertError("super", SyntaxError);
 
     // Even where super is otherwise allowed
     assertError("{ foo() { super } }", SyntaxError);
     assertClassError("class NAME { constructor() { super; } }", SyntaxError);
 
     /* EOF */
@@ -437,14 +437,25 @@ function testClasses() {
     assertClassError("class NAME { static get y", SyntaxError);
     assertClassError("class NAME extends", SyntaxError);
     assertClassError("class NAME { constructor() { super", SyntaxError);
     assertClassError("class NAME { constructor() { super.", SyntaxError);
     assertClassError("class NAME { constructor() { super.x", SyntaxError);
     assertClassError("class NAME { constructor() { super.m(", SyntaxError);
     assertClassError("class NAME { constructor() { super[", SyntaxError);
     assertClassError("class NAME { constructor() { super(", SyntaxError);
+
+    // Can not omit curly brackets
+    assertClassError("class NAME { constructor() ({}) }", SyntaxError);
+    assertClassError("class NAME { constructor() void 0 }", SyntaxError);
+    assertClassError("class NAME { constructor() 1 }", SyntaxError);
+    assertClassError("class NAME { constructor() false }", SyntaxError);
+    assertClassError("class NAME { constructor() {} a() ({}) }", SyntaxError);
+    assertClassError("class NAME { constructor() {} a() void 0 }", SyntaxError);
+    assertClassError("class NAME { constructor() {} a() 1 }", SyntaxError);
+    assertClassError("class NAME { constructor() {} a() false }", SyntaxError);
+
 }
 
 if (classesEnabled())
     runtest(testClasses);
 else if (typeof reportCompare === 'function')
     reportCompare(true, true);
--- a/js/src/tests/js1_8_5/reflect-parse/methodDefn.js
+++ b/js/src/tests/js1_8_5/reflect-parse/methodDefn.js
@@ -5,16 +5,21 @@ function test() {
 assertExpr("b = { a() { } }", aExpr("=", ident("b"),
               objExpr([{ key: ident("a"), value: funExpr(ident("a"), [], blockStmt([])), method:
               true}])));
 
 assertExpr("b = { *a() { } }", aExpr("=", ident("b"),
               objExpr([{ key: ident("a"), value: genFunExpr(ident("a"), [], blockStmt([])), method:
               true}])));
 
+// Method definitions without braces
+assertError("({ a() void 0 })", SyntaxError);
+assertError("({ a() 1 })", SyntaxError);
+assertError("({ a() false })", SyntaxError);
+
 // getters and setters
 
 assertExpr("({ get x() { return 42 } })",
            objExpr([ { key: ident("x"),
                        value: funExpr(null, [], blockStmt([returnStmt(lit(42))])),
                        kind: "get" } ]));
 assertExpr("({ set x(v) { return 42 } })",
            objExpr([ { key: ident("x"),