8061959: ArrayBuffer lacked static isViewMethod

Mon, 03 Nov 2014 13:58:52 +0100

author
lagergren
date
Mon, 03 Nov 2014 13:58:52 +0100
changeset 1084
4ac6934c6cc2
parent 1083
dba2a3939f4c
child 1085
b00442519275

8061959: ArrayBuffer lacked static isViewMethod
Reviewed-by: attila, sundar

src/jdk/nashorn/internal/objects/NativeArrayBuffer.java file | annotate | diff | comparison | revisions
test/script/basic/JDK-8061959.js file | annotate | diff | comparison | revisions
test/script/basic/JDK-8061959.js.EXPECTED file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Mon Nov 03 12:34:39 2014 +0100
     1.2 +++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Mon Nov 03 13:58:52 2014 +0100
     1.3 @@ -26,7 +26,6 @@
     1.4  package jdk.nashorn.internal.objects;
     1.5  
     1.6  import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
     1.7 -
     1.8  import java.nio.ByteBuffer;
     1.9  import jdk.nashorn.internal.objects.annotations.Attribute;
    1.10  import jdk.nashorn.internal.objects.annotations.Constructor;
    1.11 @@ -34,6 +33,7 @@
    1.12  import jdk.nashorn.internal.objects.annotations.Getter;
    1.13  import jdk.nashorn.internal.objects.annotations.ScriptClass;
    1.14  import jdk.nashorn.internal.objects.annotations.SpecializedFunction;
    1.15 +import jdk.nashorn.internal.objects.annotations.Where;
    1.16  import jdk.nashorn.internal.runtime.JSType;
    1.17  import jdk.nashorn.internal.runtime.PropertyMap;
    1.18  import jdk.nashorn.internal.runtime.ScriptObject;
    1.19 @@ -138,6 +138,19 @@
    1.20      }
    1.21  
    1.22      /**
    1.23 +     * Returns true if an object is an ArrayBufferView
    1.24 +     *
    1.25 +     * @param self self
    1.26 +     * @param obj  object to check
    1.27 +     *
    1.28 +     * @return true if obj is an ArrayBufferView
    1.29 +     */
    1.30 +    @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
    1.31 +    public static boolean isView(final Object self, final Object obj) {
    1.32 +        return obj instanceof ArrayBufferView;
    1.33 +    }
    1.34 +
    1.35 +    /**
    1.36       * Slice function
    1.37       * @param self   native array buffer
    1.38       * @param begin0 start byte index
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/script/basic/JDK-8061959.js	Mon Nov 03 13:58:52 2014 +0100
     2.3 @@ -0,0 +1,35 @@
     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-8061959 - Checks for the existence of ArrayBufferView
    2.29 + *
    2.30 + * @test
    2.31 + * @run
    2.32 + */
    2.33 +
    2.34 +print(ArrayBuffer.isView(new Int8Array(4)));
    2.35 +print(ArrayBuffer.isView("gorilla"));
    2.36 +print(ArrayBuffer.isView());
    2.37 +
    2.38 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/script/basic/JDK-8061959.js.EXPECTED	Mon Nov 03 13:58:52 2014 +0100
     3.3 @@ -0,0 +1,3 @@
     3.4 +true
     3.5 +false
     3.6 +false

mercurial