Reviewers: Mads Ager,

Message:
Please review.

Description:
Make "length" and "BYTES_PER_ELEMENT" properties of typed arrays accessible.


Please review this at http://codereview.chromium.org/6805010/

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

Affected files:
  M samples/shell.cc
  M test/mjsunit/external-array.js


Index: samples/shell.cc
diff --git a/samples/shell.cc b/samples/shell.cc
index 72aca0ff563ca865c37fc4d21c9486fecfab487d..222eeda1149406eea9206e54746fbd498a41829f 100644
--- a/samples/shell.cc
+++ b/samples/shell.cc
@@ -466,6 +466,10 @@ v8::Handle<v8::Value> CreateExternalArray(const v8::Arguments& args,
       v8::Persistent<v8::Object>::New(array);
   persistent_array.MakeWeak(data, ExternalArrayWeakCallback);
   array->SetIndexedPropertiesToExternalArrayData(data, type, length);
+  array->Set(v8::String::New("length"), v8::Int32::New(length),
+             v8::ReadOnly);
+  array->Set(v8::String::New("BYTES_PER_ELEMENT"),
+             v8::Int32::New(element_size));
   return array;
 }

Index: test/mjsunit/external-array.js
diff --git a/test/mjsunit/external-array.js b/test/mjsunit/external-array.js
index 5c04b5571e5ada76a4356fb4cbe6e688ea6c494d..228e8f06f6d19fe6d805f870521793ef9531bd54 100644
--- a/test/mjsunit/external-array.js
+++ b/test/mjsunit/external-array.js
@@ -38,3 +38,24 @@ for (var i = 0; i < 1000000; i++) {

 assertEquals(0, a[0]);
 assertEquals(0, a[1]);
+
+// Test the correct behavior of the |length| property (which is read-only).
+a = new Int32Array(42);
+assertEquals(42, a.length);
+a.length = 2;
+assertEquals(42, a.length);
+assertTrue(delete a.length);
+a.length = 2
+assertEquals(2, a.length);
+
+// Test the correct behavior of the |BYTES_PER_ELEMENT| property (which is
+// "constant", but not read-only).
+a = new Int32Array(2);
+assertEquals(4, a.BYTES_PER_ELEMENT);
+a.BYTES_PER_ELEMENT = 42;
+assertEquals(42, a.BYTES_PER_ELEMENT);
+a = new Uint8Array(2);
+assertEquals(1, a.BYTES_PER_ELEMENT);
+a = new Int16Array(2);
+assertEquals(2, a.BYTES_PER_ELEMENT);
+


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to