8061959: ArrayBuffer lacked static isViewMethod

Reviewed-by: attila, sundar
This commit is contained in:
Marcus Lagergren 2014-11-03 13:58:52 +01:00
parent f27f5dd651
commit 75d37c8e9c
3 changed files with 52 additions and 1 deletions

View File

@ -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.Function;
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;
@ -137,6 +137,19 @@ public final class NativeArrayBuffer extends ScriptObject {
return ((NativeArrayBuffer)self).getByteLength();
}
/**
* 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

View File

@ -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());

View File

@ -0,0 +1,3 @@
true
false
false