changeset 1800:ac561634520e

8168146: Infinite recursion in Uint8ClampedArray.set Reviewed-by: sundar
author hannesw
date Fri, 21 Oct 2016 09:43:11 +0200
parents ca08ca9bef23
children 1272bfe44562
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java test/script/basic/JDK-8168146.js
diffstat 2 files changed, 38 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Thu Oct 20 20:01:31 2016 +0000
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeUint8ClampedArray.java	Fri Oct 21 09:43:11 2016 +0200
@@ -82,7 +82,6 @@
         private static final MethodHandle SET_ELEM = specialCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "setElem", void.class, int.class, int.class).methodHandle();
         private static final MethodHandle RINT_D   = staticCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "rint", double.class, double.class).methodHandle();
         private static final MethodHandle RINT_O   = staticCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "rint", Object.class, Object.class).methodHandle();
-        private static final MethodHandle CLAMP_LONG = staticCall(MethodHandles.lookup(), Uint8ClampedArrayData.class, "clampLong", long.class, long.class).methodHandle();
 
         private Uint8ClampedArrayData(final ByteBuffer nb, final int start, final int end) {
             super((nb.position(start).limit(end)).slice(), end - start);
@@ -124,8 +123,6 @@
                     return MH.filterArguments(setter, 2, RINT_O);
                 } else if (elementType == double.class) {
                     return MH.filterArguments(setter, 2, RINT_D);
-                } else if (elementType == long.class) {
-                    return MH.filterArguments(setter, 2, CLAMP_LONG);
                 }
             }
             return setter;
@@ -195,7 +192,7 @@
 
         @Override
         public ArrayData set(final int index, final double value, final boolean strict) {
-            return set(index, rint(value), strict);
+            return set(index, (int) rint(value), strict);
         }
 
         private static double rint(final double rint) {
@@ -207,15 +204,6 @@
             return rint(JSType.toNumber(rint));
         }
 
-        @SuppressWarnings("unused")
-        private static long clampLong(final long l) {
-            if(l < 0L) {
-                return 0L;
-            } else if(l > 0xffL) {
-                return 0xffL;
-            }
-            return l;
-        }
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/script/basic/JDK-8168146.js	Fri Oct 21 09:43:11 2016 +0200
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016, 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-8168146: Infinite recursion in Uint8ClampedArray.set
+ *
+ * @test
+ * @run
+ */
+
+
+var a = new Uint8ClampedArray(10);
+
+for (var i = 0; i < 10; i++) {
+    a[i] = i;
+    Assert.assertTrue(a[i] === i);
+}