# HG changeset patch # User sundar # Date 1381434215 -7200 # Node ID 9cbbf2065cd158a578ef6b65259be76cdd100a2e # Parent 89748612fd1d38a6096ee20b28912ae4632f616a 8026264: Getter, setter function name mangling issues Reviewed-by: lagergren, jlaskey diff -r 89748612fd1d -r 9cbbf2065cd1 nashorn/src/jdk/nashorn/internal/parser/Parser.java --- a/nashorn/src/jdk/nashorn/internal/parser/Parser.java Thu Oct 10 16:16:20 2013 +0200 +++ b/nashorn/src/jdk/nashorn/internal/parser/Parser.java Thu Oct 10 21:43:35 2013 +0200 @@ -2113,7 +2113,7 @@ case "get": final PropertyKey getIdent = propertyName(); final String getterName = getIdent.getPropertyName(); - final IdentNode getNameNode = new IdentNode(((Node)getIdent).getToken(), finish, "get " + NameCodec.encode(getterName)); + final IdentNode getNameNode = new IdentNode(((Node)getIdent).getToken(), finish, NameCodec.encode("get " + getterName)); expect(LPAREN); expect(RPAREN); functionNode = functionBody(getSetToken, getNameNode, new ArrayList(), FunctionNode.Kind.GETTER); @@ -2122,7 +2122,7 @@ case "set": final PropertyKey setIdent = propertyName(); final String setterName = setIdent.getPropertyName(); - final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, "set " + NameCodec.encode(setterName)); + final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName)); expect(LPAREN); final IdentNode argIdent = getIdent(); verifyStrictIdent(argIdent, "setter argument"); diff -r 89748612fd1d -r 9cbbf2065cd1 nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java --- a/nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Oct 10 16:16:20 2013 +0200 +++ b/nashorn/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Oct 10 21:43:35 2013 +0200 @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; +import jdk.internal.dynalink.support.NameCodec; import jdk.nashorn.internal.codegen.Compiler; import jdk.nashorn.internal.codegen.CompilerConstants; @@ -100,9 +101,7 @@ * @param allocatorMap allocator map to seed instances with, when constructing */ public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller installer, final String allocatorClassName, final PropertyMap allocatorMap) { - super(functionNode.isAnonymous() ? - "" : - functionNode.getIdent().getName(), + super(functionName(functionNode), functionNode.getParameters().size(), functionNode.isStrict(), false, @@ -139,6 +138,20 @@ return sb.toString() + super.toString(); } + private static String functionName(final FunctionNode fn) { + if (fn.isAnonymous()) { + return ""; + } else { + final FunctionNode.Kind kind = fn.getKind(); + if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { + final String name = NameCodec.decode(fn.getIdent().getName()); + return name.substring(4); // 4 is "get " or "set " + } else { + return fn.getIdent().getName(); + } + } + } + private static long tokenFor(final FunctionNode fn) { final int position = Token.descPosition(fn.getFirstToken()); final int length = Token.descPosition(fn.getLastToken()) - position + Token.descLength(fn.getLastToken()); diff -r 89748612fd1d -r 9cbbf2065cd1 nashorn/test/script/basic/JDK-8026264.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nashorn/test/script/basic/JDK-8026264.js Thu Oct 10 21:43:35 2013 +0200 @@ -0,0 +1,54 @@ +/* + * 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-8026264: Getter, setter function name mangling issues + * + * @test + * @run + */ + +var obj = { + get ":"(){}, + set ":"(x){}, + get ""(){}, + set ""(x){} +}; + +var desc = Object.getOwnPropertyDescriptor(obj, ":"); +if (desc.get.name != ':') { + fail("getter name is expected to be ':' got " + desc.get.name); +} + +if (desc.set.name != ':') { + fail("setter name is expected to be ':' got " + desc.set.name); +} + +desc = Object.getOwnPropertyDescriptor(obj, ""); +if (desc.get.name != '') { + fail("getter name is expected to be '' got " + desc.get.name); +} + +if (desc.set.name != '') { + fail("setter name is expected to be '' got " + desc.set.name); +}