8026264: Getter, setter function name mangling issues

Thu, 10 Oct 2013 21:43:35 +0200

author
sundar
date
Thu, 10 Oct 2013 21:43:35 +0200
changeset 611
a781ea074521
parent 610
ed3da7a574a0
child 612
375c2f2d41c8

8026264: Getter, setter function name mangling issues
Reviewed-by: lagergren, jlaskey

src/jdk/nashorn/internal/parser/Parser.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8026264.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/parser/Parser.java	Thu Oct 10 16:16:20 2013 +0200
     1.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java	Thu Oct 10 21:43:35 2013 +0200
     1.3 @@ -2113,7 +2113,7 @@
     1.4                  case "get":
     1.5                      final PropertyKey getIdent = propertyName();
     1.6                      final String getterName = getIdent.getPropertyName();
     1.7 -                    final IdentNode getNameNode = new IdentNode(((Node)getIdent).getToken(), finish, "get " + NameCodec.encode(getterName));
     1.8 +                    final IdentNode getNameNode = new IdentNode(((Node)getIdent).getToken(), finish, NameCodec.encode("get " + getterName));
     1.9                      expect(LPAREN);
    1.10                      expect(RPAREN);
    1.11                      functionNode = functionBody(getSetToken, getNameNode, new ArrayList<IdentNode>(), FunctionNode.Kind.GETTER);
    1.12 @@ -2122,7 +2122,7 @@
    1.13                  case "set":
    1.14                      final PropertyKey setIdent = propertyName();
    1.15                      final String setterName = setIdent.getPropertyName();
    1.16 -                    final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, "set " + NameCodec.encode(setterName));
    1.17 +                    final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName));
    1.18                      expect(LPAREN);
    1.19                      final IdentNode argIdent = getIdent();
    1.20                      verifyStrictIdent(argIdent, "setter argument");
     2.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Thu Oct 10 16:16:20 2013 +0200
     2.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java	Thu Oct 10 21:43:35 2013 +0200
     2.3 @@ -33,6 +33,7 @@
     2.4  import java.util.ArrayList;
     2.5  import java.util.Arrays;
     2.6  import java.util.LinkedList;
     2.7 +import jdk.internal.dynalink.support.NameCodec;
     2.8  
     2.9  import jdk.nashorn.internal.codegen.Compiler;
    2.10  import jdk.nashorn.internal.codegen.CompilerConstants;
    2.11 @@ -100,9 +101,7 @@
    2.12       * @param allocatorMap       allocator map to seed instances with, when constructing
    2.13       */
    2.14      public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) {
    2.15 -        super(functionNode.isAnonymous() ?
    2.16 -                "" :
    2.17 -                functionNode.getIdent().getName(),
    2.18 +        super(functionName(functionNode),
    2.19                functionNode.getParameters().size(),
    2.20                functionNode.isStrict(),
    2.21                false,
    2.22 @@ -139,6 +138,20 @@
    2.23          return sb.toString() + super.toString();
    2.24      }
    2.25  
    2.26 +    private static String functionName(final FunctionNode fn) {
    2.27 +        if (fn.isAnonymous()) {
    2.28 +            return "";
    2.29 +        } else {
    2.30 +            final FunctionNode.Kind kind = fn.getKind();
    2.31 +            if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) {
    2.32 +                final String name = NameCodec.decode(fn.getIdent().getName());
    2.33 +                return name.substring(4); // 4 is "get " or "set "
    2.34 +            } else {
    2.35 +                return fn.getIdent().getName();
    2.36 +            }
    2.37 +        }
    2.38 +    }
    2.39 +
    2.40      private static long tokenFor(final FunctionNode fn) {
    2.41          final int  position   = Token.descPosition(fn.getFirstToken());
    2.42          final int  length     = Token.descPosition(fn.getLastToken()) - position + Token.descLength(fn.getLastToken());
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8026264.js	Thu Oct 10 21:43:35 2013 +0200
     3.3 @@ -0,0 +1,54 @@
     3.4 +/*
     3.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + * 
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + * 
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + * 
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + * 
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * JDK-8026264: Getter, setter function name mangling issues
    3.29 + *
    3.30 + * @test
    3.31 + * @run
    3.32 + */
    3.33 +
    3.34 +var obj = {
    3.35 +   get ":"(){},
    3.36 +   set ":"(x){},
    3.37 +   get ""(){},
    3.38 +   set ""(x){}
    3.39 +};
    3.40 +
    3.41 +var desc = Object.getOwnPropertyDescriptor(obj, ":");
    3.42 +if (desc.get.name != ':') {
    3.43 +    fail("getter name is expected to be ':' got " + desc.get.name);
    3.44 +}
    3.45 +
    3.46 +if (desc.set.name != ':') {
    3.47 +    fail("setter name is expected to be ':' got " + desc.set.name);
    3.48 +}
    3.49 +
    3.50 +desc = Object.getOwnPropertyDescriptor(obj, "");
    3.51 +if (desc.get.name != '') {
    3.52 +    fail("getter name is expected to be '' got " + desc.get.name);
    3.53 +}
    3.54 +
    3.55 +if (desc.set.name != '') {
    3.56 +    fail("setter name is expected to be '' got " + desc.set.name);
    3.57 +}

mercurial