changeset 753:8c19fdb184f8

8031317: SyntaxError when property setter has no parameter Reviewed-by: lagergren, hannesw
author sundar
date Wed, 08 Jan 2014 17:51:47 +0530
parents 2f55fa4b2e88
children c6ed9226b007
files src/jdk/nashorn/internal/parser/Parser.java test/script/basic/JDK-8031317.js test/script/basic/JDK-8031317.js.EXPECTED
diffstat 3 files changed, 55 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/parser/Parser.java	Tue Jan 07 14:16:23 2014 +0100
+++ b/src/jdk/nashorn/internal/parser/Parser.java	Wed Jan 08 17:51:47 2014 +0530
@@ -2134,11 +2134,20 @@
                     final String setterName = setIdent.getPropertyName();
                     final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName));
                     expect(LPAREN);
-                    final IdentNode argIdent = getIdent();
-                    verifyStrictIdent(argIdent, "setter argument");
+                    // be sloppy and allow missing setter parameter even though
+                    // spec does not permit it!
+                    final IdentNode argIdent;
+                    if (type == IDENT || isNonStrictModeIdent()) {
+                        argIdent = getIdent();
+                        verifyStrictIdent(argIdent, "setter argument");
+                    } else {
+                        argIdent = null;
+                    }
                     expect(RPAREN);
                     List<IdentNode> parameters = new ArrayList<>();
-                    parameters.add(argIdent);
+                    if (argIdent != null) {
+                        parameters.add(argIdent);
+                    }
                     functionNode = functionBody(getSetToken, setNameNode, parameters, FunctionNode.Kind.SETTER);
                     return new PropertyNode(propertyToken, finish, setIdent, null, null, functionNode);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8031317.js	Wed Jan 08 17:51:47 2014 +0530
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8031317: SyntaxError when property setter has no parameter
+ *
+ * @test
+ * @run
+ */
+
+var obj = {
+  get toto() {
+      print("in getter for 'toto'");
+  },
+  set toto() {
+      print("in setter for 'toto'");
+  }
+}
+
+obj.toto;
+obj.toto = 344;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8031317.js.EXPECTED	Wed Jan 08 17:51:47 2014 +0530
@@ -0,0 +1,2 @@
+in getter for 'toto'
+in setter for 'toto'