changeset 628:fb091f9052a6

8026302: source representation of getter and setter methods is wrong Reviewed-by: lagergren, hannesw, jlaskey
author sundar
date Fri, 11 Oct 2013 11:15:59 +0200
parents 1c154cee43d9
children 062579f50371
files src/jdk/nashorn/internal/parser/Parser.java test/script/basic/JDK-8026302.js test/script/basic/JDK-8026302.js.EXPECTED test/script/basic/objects.js.EXPECTED
diffstat 4 files changed, 63 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/parser/Parser.java	Fri Oct 11 10:56:08 2013 +0200
+++ b/src/jdk/nashorn/internal/parser/Parser.java	Fri Oct 11 11:15:59 2013 +0200
@@ -2107,7 +2107,7 @@
             final String ident = (String)expectValue(IDENT);
 
             if (type != COLON) {
-                final long getSetToken = token;
+                final long getSetToken = propertyToken;
 
                 switch (ident) {
                 case "get":
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8026302.js	Fri Oct 11 11:15:59 2013 +0200
@@ -0,0 +1,48 @@
+/*
+ * 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-8026302: source representation of getter and setter methods is wrong
+ *
+ * @test
+ * @run
+ */
+
+var obj = {
+    get "foo"() {},
+    set "foo"(x) {},
+    get bar() {},
+    set bar(x) {},
+    get ":"() {},
+    set ":"(x) {},
+    get 12() {},
+    set 12(x) {},
+    get 1.8e-8() {},
+    set 1.8e-8(x) {}
+}
+
+for (var prop in obj) {
+    var desc = Object.getOwnPropertyDescriptor(obj, prop);
+    print(desc.get);
+    print(desc.set);
+} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8026302.js.EXPECTED	Fri Oct 11 11:15:59 2013 +0200
@@ -0,0 +1,10 @@
+get "foo"() {}
+set "foo"(x) {}
+get bar() {}
+set bar(x) {}
+get ":"() {}
+set ":"(x) {}
+get 12() {}
+set 12(x) {}
+get 1.8e-8() {}
+set 1.8e-8(x) {}
--- a/test/script/basic/objects.js.EXPECTED	Fri Oct 11 10:56:08 2013 +0200
+++ b/test/script/basic/objects.js.EXPECTED	Fri Oct 11 11:15:59 2013 +0200
@@ -29,18 +29,18 @@
 abc is configurable? true
 abc is enumerable? true
 abc's value = undefined
-abc's get = abc() { return "abc"; }
+abc's get = get abc() { return "abc"; }
 abc's set = undefined
 xyz is writable? undefined
 xyz is configurable? true
 xyz is enumerable? true
 xyz's value = undefined
 xyz's get = undefined
-xyz's set = xyz(val) { print(val); }
+xyz's set = set xyz(val) { print(val); }
 hey is writable? undefined
 hey is configurable? true
 hey is enumerable? true
 hey's value = undefined
-hey's get = hey() { return "hey"; }
-hey's set = hey(val) { print(val); }
+hey's get = get hey() { return "hey"; }
+hey's set = set hey(val) { print(val); }
 undefined