8019488: switch on literals result in NoSuchMethodError or VerifyError

Mon, 01 Jul 2013 19:52:07 +0530

author
sundar
date
Mon, 01 Jul 2013 19:52:07 +0530
changeset 390
ab3ea5b3e507
parent 389
47099609a48b
child 391
9165138b427c

8019488: switch on literals result in NoSuchMethodError or VerifyError
Reviewed-by: hannesw

src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/runtime/ScriptRuntime.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8019488.js file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Jul 01 17:21:09 2013 +0530
     1.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Mon Jul 01 19:52:07 2013 +0530
     1.3 @@ -1845,7 +1845,8 @@
     1.4              // If expression not int see if we can convert, if not use deflt to trigger default.
     1.5              if (!type.isInteger()) {
     1.6                  method.load(deflt);
     1.7 -                method.invoke(staticCallNoLookup(ScriptRuntime.class, "switchTagAsInt", int.class, type.getTypeClass(), int.class));
     1.8 +                final Class exprClass = type.getTypeClass();
     1.9 +                method.invoke(staticCallNoLookup(ScriptRuntime.class, "switchTagAsInt", int.class, exprClass.isPrimitive()? exprClass : Object.class, int.class));
    1.10              }
    1.11  
    1.12              // If reasonable size and not too sparse (80%), use table otherwise use lookup.
     2.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Mon Jul 01 17:21:09 2013 +0530
     2.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java	Mon Jul 01 19:52:07 2013 +0530
     2.3 @@ -127,6 +127,17 @@
     2.4       * @param deflt default to use if not convertible.
     2.5       * @return int tag value (or deflt.)
     2.6       */
     2.7 +    public static int switchTagAsInt(final boolean tag, final int deflt) {
     2.8 +        return deflt;
     2.9 +    }
    2.10 +
    2.11 +    /**
    2.12 +     * Converts a switch tag value to a simple integer. deflt value if it can't.
    2.13 +     *
    2.14 +     * @param tag   Switch statement tag value.
    2.15 +     * @param deflt default to use if not convertible.
    2.16 +     * @return int tag value (or deflt.)
    2.17 +     */
    2.18      public static int switchTagAsInt(final long tag, final int deflt) {
    2.19          return isRepresentableAsInt(tag) ? (int)tag : deflt;
    2.20      }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8019488.js	Mon Jul 01 19:52:07 2013 +0530
     3.3 @@ -0,0 +1,68 @@
     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-8019488: switch on literals result in NoSuchMethodError or VerifyError
    3.29 + *
    3.30 + * @test
    3.31 + * @run
    3.32 + */
    3.33 +
    3.34 +switch("") {
    3.35 +    case 0:
    3.36 +        break
    3.37 +}
    3.38 +
    3.39 +switch(true) {
    3.40 +    case 0:
    3.41 +        print("0"); break;
    3.42 +    case 1:
    3.43 +        print("1"); break;
    3.44 +}
    3.45 +
    3.46 +switch(false) {
    3.47 +    case 0:
    3.48 +        print("0"); break;
    3.49 +    case 1:
    3.50 +        print("1"); break;
    3.51 +}
    3.52 +
    3.53 +switch([]) {
    3.54 +    case 1:
    3.55 +        print("1");
    3.56 +}
    3.57 +
    3.58 +switch (undefined) {
    3.59 +    case 0:
    3.60 +        print("0");
    3.61 +}
    3.62 +
    3.63 +switch (null) {
    3.64 +    case 0:
    3.65 +        print("0");
    3.66 +}
    3.67 +
    3.68 +switch({}) {
    3.69 +    case 1:
    3.70 +        print("1");
    3.71 +}

mercurial