8062381: Wrong index was used for linking charCodeAt specializations

Mon, 03 Nov 2014 12:34:39 +0100

author
lagergren
date
Mon, 03 Nov 2014 12:34:39 +0100
changeset 1083
dba2a3939f4c
parent 1082
e1e27c4262be
child 1084
4ac6934c6cc2

8062381: Wrong index was used for linking charCodeAt specializations
Reviewed-by: attila, hannesw

src/jdk/nashorn/internal/objects/NativeString.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8062381.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8062381.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/NativeString.java	Mon Nov 03 11:47:41 2014 +0100
     1.2 +++ b/src/jdk/nashorn/internal/objects/NativeString.java	Mon Nov 03 12:34:39 2014 +0100
     1.3 @@ -572,7 +572,7 @@
     1.4          try {
     1.5              return ((CharSequence)self).charAt(pos);
     1.6          } catch (final IndexOutOfBoundsException e) {
     1.7 -            throw new ClassCastException();
     1.8 +            throw new ClassCastException(); //invalid char, out of bounds, force relink
     1.9          }
    1.10      }
    1.11  
    1.12 @@ -1389,7 +1389,7 @@
    1.13                  //check that it's a char sequence or throw cce
    1.14                  final CharSequence cs = (CharSequence)self;
    1.15                  //check that the index, representable as an int, is inside the array
    1.16 -                final int intIndex = JSType.toInteger(request.getArguments()[1]);
    1.17 +                final int intIndex = JSType.toInteger(request.getArguments()[2]);
    1.18                  return intIndex >= 0 && intIndex < cs.length(); //can link
    1.19              } catch (final ClassCastException | IndexOutOfBoundsException e) {
    1.20                  //fallthru
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/script/basic/JDK-8062381.js	Mon Nov 03 12:34:39 2014 +0100
     2.3 @@ -0,0 +1,53 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * JDK-8062381 wrong argument chosen for charCodeAt in linker logic
    2.29 + *
    2.30 + * @test
    2.31 + * @run
    2.32 + */
    2.33 +
    2.34 +var s = "abcdef";
    2.35 +var len = s.length + 1;
    2.36 +
    2.37 +function f1() {
    2.38 +    for (var i = 0; i < len; i++) {
    2.39 +	print(s.charCodeAt(i));
    2.40 +    }
    2.41 +    print(s.charCodeAt());
    2.42 +}
    2.43 +
    2.44 +function f2() {    
    2.45 +    for (var i = 0; i < len; i++) {
    2.46 +	print(s.charCodeAt("" + i));
    2.47 +    }
    2.48 +    print(s.charCodeAt());
    2.49 +}
    2.50 +
    2.51 +f1();
    2.52 +f2();
    2.53 +f1();
    2.54 +f2();
    2.55 +
    2.56 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8062381.js.EXPECTED	Mon Nov 03 12:34:39 2014 +0100
     3.3 @@ -0,0 +1,32 @@
     3.4 +97
     3.5 +98
     3.6 +99
     3.7 +100
     3.8 +101
     3.9 +102
    3.10 +NaN
    3.11 +97
    3.12 +97
    3.13 +98
    3.14 +99
    3.15 +100
    3.16 +101
    3.17 +102
    3.18 +NaN
    3.19 +97
    3.20 +97
    3.21 +98
    3.22 +99
    3.23 +100
    3.24 +101
    3.25 +102
    3.26 +NaN
    3.27 +97
    3.28 +97
    3.29 +98
    3.30 +99
    3.31 +100
    3.32 +101
    3.33 +102
    3.34 +NaN
    3.35 +97

mercurial