Bug 1073809 - Allow "get" and "set" as generator names in object literals. (r=Waldo)
authorEric Faust <efaustbmo@gmail.com>
Mon, 26 Jan 2015 12:04:54 -0800
changeset 239194 0b4f930f8ae942c80ad9cd0863121a42b8150eae
parent 239193 6f06c4beef24a4a67892fd46ed169e3ec878216f
child 239195 86e9422940ed3d77d81fbc4f0a02c36ce66caf1e
push id489
push usermcmanus@ducksong.com
push dateTue, 27 Jan 2015 01:44:53 +0000
reviewersWaldo
bugs1073809
milestone38.0a1
Bug 1073809 - Allow "get" and "set" as generator names in object literals. (r=Waldo)
js/src/frontend/Parser.cpp
js/src/jit-test/tests/basic/syntax-error-illegal-character.js
js/src/tests/js1_8_5/extensions/reflect-parse.js
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -7943,28 +7943,23 @@ Parser<ParseHandler>::objectLiteral()
               propname = computedPropertyName(literal);
               if (!propname)
                   return null();
               break;
           }
 
           case TOK_NAME: {
             atom = tokenStream.currentName();
-            if (atom == context->names().get) {
-                if (isGenerator) {
-                    report(ParseError, false, null(), JSMSG_BAD_PROP_ID);
-                    return null();
-                }
-                op = JSOP_INITPROP_GETTER;
-            } else if (atom == context->names().set) {
-                if (isGenerator) {
-                    report(ParseError, false, null(), JSMSG_BAD_PROP_ID);
-                    return null();
-                }
-                op = JSOP_INITPROP_SETTER;
+            // Do not look for accessor syntax on generators
+            if (!isGenerator &&
+                (atom == context->names().get ||
+                 atom == context->names().set))
+            {
+                op = atom == context->names().get ? JSOP_INITPROP_GETTER
+                                                  : JSOP_INITPROP_SETTER;
             } else {
                 propname = handler.newIdentifier(atom, pos());
                 if (!propname)
                     return null();
                 break;
             }
 
             // We have parsed |get| or |set|. Look for an accessor property
--- a/js/src/jit-test/tests/basic/syntax-error-illegal-character.js
+++ b/js/src/jit-test/tests/basic/syntax-error-illegal-character.js
@@ -655,16 +655,30 @@ test("({ *[ @");
 test("({ *[m @");
 test("({ *[m] @");
 test("({ *[m]( @");
 test("({ *[m]() @");
 test("({ *[m]() { @");
 test("({ *[m]() {} @");
 test("({ *[m]() {}, @");
 
+test("({ * get @");
+test("({ * get ( @");
+test("({ * get () @");
+test("({ * get () { @");
+test("({ * get () {} @");
+test("({ * get () {}, @");
+
+test("({ * set @");
+test("({ * set ( @");
+test("({ * set () @");
+test("({ * set () { @");
+test("({ * set () {} @");
+test("({ * set () {}, @");
+
 // Regular expression literal
 
 test("/a/ @");
 test("/a/g @");
 
 // Array comprehensions
 
 test("[for @");
--- a/js/src/tests/js1_8_5/extensions/reflect-parse.js
+++ b/js/src/tests/js1_8_5/extensions/reflect-parse.js
@@ -384,17 +384,16 @@ assertExpr("({'x':1, 'y':2, 3:3})", objE
 assertExpr("({__proto__:x})", objExpr([{ type: "PrototypeMutation", value: ident("x") }]));
 assertExpr("({'__proto__':x})", objExpr([{ type: "PrototypeMutation", value: ident("x") }]));
 assertExpr("({['__proto__']:x})", objExpr([{ type: "Property", key: comp(lit("__proto__")), value: ident("x") }]));
 assertExpr("({['__proto__']:q, __proto__() {}, __proto__: null })",
            objExpr([{ type: "Property", key: comp(lit("__proto__")), value: ident("q") },
                     { type: "Property", key: ident("__proto__"), method: true },
                     { type: "PrototypeMutation", value: lit(null) }]));
 
-
 // Bug 571617: eliminate constant-folding
 assertExpr("2 + 3", binExpr("+", lit(2), lit(3)));
 
 // Bug 632026: constant-folding
 assertExpr("typeof(0?0:a)", unExpr("typeof", condExpr(lit(0), lit(0), ident("a"))));
 
 // Bug 632029: constant-folding
 assertExpr("[x for each (x in y) if (false)]", compExpr(ident("x"), [compEachBlock(ident("x"), ident("y"))], lit(false), "legacy"));
@@ -430,16 +429,35 @@ Pattern({ body: [ { expression: { right:
 // Bug 1048384 - Getter/setter syntax with computed names
 assertExpr("b = { get [meth]() { } }", aExpr("=", ident("b"),
               objExpr([{ key: computedName(ident("meth")), value: funExpr(null, [], blockStmt([])),
                 method: false, kind: "get"}])));
 assertExpr("b = { set [meth](a) { } }", aExpr("=", ident("b"),
               objExpr([{ key: computedName(ident("meth")), value: funExpr(null, [ident("a")],
                 blockStmt([])), method: false, kind: "set"}])));
 
+// Bug 1073809 - Getter/setter syntax with generators
+assertExpr("({*get() { }})", objExpr([{ type: "Property", key: ident("get"), method: true,
+                                        value: genFunExpr(ident("get"), [], blockStmt([]))}]));
+assertExpr("({*set() { }})", objExpr([{ type: "Property", key: ident("set"), method: true,
+                                        value: genFunExpr(ident("set"), [], blockStmt([]))}]));
+assertError("({*get foo() { }})", SyntaxError);
+assertError("({*set foo() { }})", SyntaxError);
+
+assertError("({ *get 1() {} })", SyntaxError);
+assertError("({ *get \"\"() {} })", SyntaxError);
+assertError("({ *get foo() {} })", SyntaxError);
+assertError("({ *get []() {} })", SyntaxError);
+assertError("({ *get [1]() {} })", SyntaxError);
+
+assertError("({ *set 1() {} })", SyntaxError);
+assertError("({ *set \"\"() {} })", SyntaxError);
+assertError("({ *set foo() {} })", SyntaxError);
+assertError("({ *set []() {} })", SyntaxError);
+assertError("({ *set [1]() {} })", SyntaxError);
 // statements
 
 assertStmt("throw 42", throwStmt(lit(42)));
 assertStmt("for (;;) break", forStmt(null, null, null, breakStmt(null)));
 assertStmt("for (x; y; z) break", forStmt(ident("x"), ident("y"), ident("z"), breakStmt(null)));
 assertStmt("for (var x; y; z) break", forStmt(varDecl([{ id: ident("x"), init: null }]), ident("y"), ident("z")));
 assertStmt("for (var x = 42; y; z) break", forStmt(varDecl([{ id: ident("x"), init: lit(42) }]), ident("y"), ident("z")));
 assertStmt("for (x; ; z) break", forStmt(ident("x"), null, ident("z"), breakStmt(null)));