Commit 380d0ca5 authored by dslomov@chromium.org's avatar dslomov@chromium.org

Implement ArrayBuffer.isView.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/25700010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17121 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent eace5101
......@@ -81,6 +81,10 @@ function ArrayBufferSlice(start, end) {
return result;
}
function ArrayBufferIsView(obj) {
return %ArrayBufferIsView(obj);
}
function SetUpArrayBuffer() {
%CheckIsBootstrapping();
......@@ -93,6 +97,10 @@ function SetUpArrayBuffer() {
InstallGetter($ArrayBuffer.prototype, "byteLength", ArrayBufferGetByteLength);
InstallFunctions($ArrayBuffer, DONT_ENUM, $Array(
"isView", ArrayBufferIsView
));
InstallFunctions($ArrayBuffer.prototype, DONT_ENUM, $Array(
"slice", ArrayBufferSlice
));
......
......@@ -801,6 +801,16 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferSliceImpl) {
}
RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) {
HandleScope scope(isolate);
ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(Object, object, 0);
return object->IsJSArrayBufferView()
? isolate->heap()->true_value()
: isolate->heap()->false_value();
}
enum TypedArrayId {
// arrayIds below should be synchromized with typedarray.js natives.
ARRAY_ID_UINT8 = 1,
......
......@@ -362,6 +362,7 @@ namespace internal {
F(ArrayBufferInitialize, 2, 1)\
F(ArrayBufferGetByteLength, 1, 1)\
F(ArrayBufferSliceImpl, 3, 1) \
F(ArrayBufferIsView, 1, 1) \
\
F(TypedArrayInitialize, 5, 1) \
F(TypedArrayInitializeFromArrayLike, 4, 1) \
......
......@@ -123,6 +123,7 @@ function TestTypedArray(constr, elementSize, typicalElement) {
var ab = new ArrayBuffer(256*elementSize);
var a0 = new constr(30);
assertTrue(ArrayBuffer.isView(a0));
assertSame(elementSize, a0.BYTES_PER_ELEMENT);
assertSame(30, a0.length);
assertSame(30*elementSize, a0.byteLength);
......@@ -476,6 +477,7 @@ function TestDataViewConstructor() {
var ab = new ArrayBuffer(256);
var d1 = new DataView(ab, 1, 255);
assertTrue(ArrayBuffer.isView(d1));
assertSame(ab, d1.buffer);
assertSame(1, d1.byteOffset);
assertSame(255, d1.byteLength);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment