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

Review URL: http://codereview.chromium.org/6805010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7527 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f9832441
......@@ -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;
}
......
......@@ -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);
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