Reviewers: rossberg,

Message:
PTAL.

Description:
Implement ArrayBuffer.isView.

[email protected]

Please review this at https://codereview.chromium.org/25700010/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+21, -0 lines):
  M src/arraybuffer.js
  M src/runtime.h
  M src/runtime.cc
  M test/mjsunit/harmony/typedarrays.js


Index: src/arraybuffer.js
diff --git a/src/arraybuffer.js b/src/arraybuffer.js
index 4a4f570146568464dfe8938502e9a827be60c6cd..c5c98dbe4bbeaa04fd2797af69442d4d28096910 100644
--- a/src/arraybuffer.js
+++ b/src/arraybuffer.js
@@ -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
   ));
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index af3c39e45ed07f5650a0af2859d6dfa67e4f8997..c93dbf79cf71c37ac28f6ec3b2df6d73dcc03af3 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -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,
Index: src/runtime.h
diff --git a/src/runtime.h b/src/runtime.h
index 1b68863bf687345bc60cdd543c4d188e2fc599e9..5566226198b8f6d29d4e641e36912bd8eb9bf0aa 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -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) \
Index: test/mjsunit/harmony/typedarrays.js
diff --git a/test/mjsunit/harmony/typedarrays.js b/test/mjsunit/harmony/typedarrays.js index c6d130fc0c6dd30268e0a6ca3c2088bf16d2fbaa..e20fbade9b07d99ecfabd558ca702dbfacd33d69 100644
--- a/test/mjsunit/harmony/typedarrays.js
+++ b/test/mjsunit/harmony/typedarrays.js
@@ -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);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to