8061959: ArrayBuffer lacked static isViewMethod
authorlagergren
Mon, 03 Nov 2014 13:58:52 +0100
changeset 27363 9722f0db287b
parent 27362 142fc25a0baf
child 27364 2c2e0dfec388
8061959: ArrayBuffer lacked static isViewMethod Reviewed-by: attila, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java
nashorn/test/script/basic/JDK-8061959.js
nashorn/test/script/basic/JDK-8061959.js.EXPECTED
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Mon Nov 03 12:34:39 2014 +0100
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Mon Nov 03 13:58:52 2014 +0100
@@ -26,7 +26,6 @@
 package jdk.nashorn.internal.objects;
 
 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
-
 import java.nio.ByteBuffer;
 import jdk.nashorn.internal.objects.annotations.Attribute;
 import jdk.nashorn.internal.objects.annotations.Constructor;
@@ -34,6 +33,7 @@
 import jdk.nashorn.internal.objects.annotations.Getter;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;
 import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
+import jdk.nashorn.internal.objects.annotations.Where;
 import jdk.nashorn.internal.runtime.JSType;
 import jdk.nashorn.internal.runtime.PropertyMap;
 import jdk.nashorn.internal.runtime.ScriptObject;
@@ -138,6 +138,19 @@
     }
 
     /**
+     * Returns true if an object is an ArrayBufferView
+     *
+     * @param self self
+     * @param obj  object to check
+     *
+     * @return true if obj is an ArrayBufferView
+     */
+    @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
+    public static boolean isView(final Object self, final Object obj) {
+        return obj instanceof ArrayBufferView;
+    }
+
+    /**
      * Slice function
      * @param self   native array buffer
      * @param begin0 start byte index
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8061959.js	Mon Nov 03 13:58:52 2014 +0100
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010, 2014, 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.
+ */
+
+/**
+ * Checks for the existence of ArrayBufferView
+ *
+ * @test
+ * @run
+ */
+
+print(ArrayBuffer.isView(new Int8Array(4)));
+print(ArrayBuffer.isView("gorilla"));
+print(ArrayBuffer.isView());
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8061959.js.EXPECTED	Mon Nov 03 13:58:52 2014 +0100
@@ -0,0 +1,3 @@
+true
+false
+false