Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 9d05c0f795a55dc23fb0fe2ad780d90db863adc3..197f673f8be2f51eea18169a03ff34581170e55f 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -2251,6 +2251,59 @@ THREADED_TEST(SymbolProperties) { |
CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); |
} |
rossberg
2013/04/25 11:00:55
Style: add extra line
Dmitry Lomov (no reviews)
2013/04/25 11:48:01
Done.
|
+THREADED_TEST(ArrayBuffer) { |
+ i::FLAG_harmony_typed_arrays = true; |
+ |
+ LocalContext env; |
+ v8::Isolate* isolate = env->GetIsolate(); |
+ v8::HandleScope handle_scope(isolate); |
+ |
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); |
+ HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
+ |
+ CHECK_EQ(1024, ab->ByteLength()); |
+ uint8_t* data = static_cast<uint8_t*>(ab->Data()); |
rossberg
2013/04/25 11:00:55
Maybe add an assertion that Data is non-null.
Dmitry Lomov (no reviews)
2013/04/25 11:48:01
Done.
|
+ env->Global()->Set(v8_str("ab"), ab); |
+ |
+ v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); |
+ CHECK_EQ(1024, result->Int32Value()); |
+ |
+ result = CompileRun("var u8 = new __Uint8Array(ab);" |
+ "u8[0] = 0xFF;" |
+ "u8[1] = 0xAA;" |
+ "u8.length"); |
+ CHECK_EQ(1024, result->Int32Value()); |
+ CHECK_EQ(0xFF, data[0]); |
+ CHECK_EQ(0xAA, data[1]); |
rossberg
2013/04/25 11:00:55
Also test the inverse, i.e., writing to data, read
Dmitry Lomov (no reviews)
2013/04/25 11:48:01
Done.
|
+ |
+ result = CompileRun("var ab1 = new __ArrayBuffer(2);" |
+ "var u8_a = new __Uint8Array(ab1);" |
+ "u8_a[0] = 0xAA;" |
+ "u8_a[1] = 0xFF; u8_a.buffer"); |
+ Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); |
+ CHECK_EQ(2, ab1->ByteLength()); |
+ CHECK_EQ(0xAA, static_cast<uint8_t*>(ab1->Data())[0]); |
+ CHECK_EQ(0xFF, static_cast<uint8_t*>(ab1->Data())[1]); |
+ |
+ uint8_t* my_data = new uint8_t[100]; |
+ memset(my_data, 0, 100); |
+ Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data, 100); |
+ CHECK_EQ(100, ab3->ByteLength()); |
+ CHECK_EQ(my_data, ab3->Data()); |
+ |
+ env->Global()->Set(v8_str("ab3"), ab3); |
+ |
+ result = CompileRun("var u8_b = new __Uint8Array(ab3);" |
+ "u8_b[0] = 0xBB;" |
+ "u8_b[1] = 0xCC;" |
+ "u8_b.length"); |
+ CHECK_EQ(100, result->Int32Value()); |
+ CHECK_EQ(0xBB, my_data[0]); |
+ CHECK_EQ(0xCC, my_data[1]); |
+ |
+ delete[] my_data; |
+} |
+ |
THREADED_TEST(HiddenProperties) { |
LocalContext env; |