Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Unified Diff: test/cctest/test-api.cc

Issue 15001041: Externalization API for ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index c8f67de0abfc857747de6893320715eab7601cd1..746244d6d8e14fbeec80c42da5587594d81920d3 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -2502,10 +2502,16 @@ THREADED_TEST(ArrayBuffer) {
v8::HandleScope handle_scope(isolate);
Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024);
+ CHECK_EQ(1024, ab->ByteLength());
+ CHECK(!ab->IsExternal());
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
- CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
- uint8_t* data = static_cast<uint8_t*>(ab->Data());
+ v8::ArrayBufferContents ab_contents;
+ ab->Externalize(&ab_contents);
+ CHECK(ab->IsExternal());
+
+ CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
+ uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
ASSERT(data != NULL);
env->Global()->Set(v8_str("ab"), ab);
@@ -2530,7 +2536,13 @@ THREADED_TEST(ArrayBuffer) {
"u8_a[1] = 0xFF; u8_a.buffer");
Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result);
CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
- uint8_t* ab1_data = static_cast<uint8_t*>(ab1->Data());
+ CHECK(!ab1->IsExternal());
+ v8::ArrayBufferContents ab1_contents;
+ ab1->Externalize(&ab1_contents);
+ CHECK(ab1->IsExternal());
+
+ CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
+ uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
CHECK_EQ(0xAA, ab1_data[0]);
CHECK_EQ(0xFF, ab1_data[1]);
ab1_data[0] = 0xCC;
@@ -2542,8 +2554,13 @@ THREADED_TEST(ArrayBuffer) {
memset(my_data, 0, 100);
Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data, 100);
CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
- CHECK_EQ(my_data, ab3->Data());
+ CHECK(ab3->IsExternal());
+
env->Global()->Set(v8_str("ab3"), ab3);
+
+ result = CompileRun("ab3.byteLength");
+ CHECK_EQ(100, result->Int32Value());
+
result = CompileRun("var u8_b = new Uint8Array(ab3);"
"u8_b[0] = 0xBB;"
"u8_b[1] = 0xCC;"
@@ -2560,9 +2577,6 @@ THREADED_TEST(ArrayBuffer) {
}
-
-
-
THREADED_TEST(HiddenProperties) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
@@ -15460,27 +15474,31 @@ void TypedArrayTestHelper(v8::ExternalArrayType array_type,
i::FLAG_harmony_array_buffer = true;
i::FLAG_harmony_typed_arrays = true;
- LocalContext env;
- v8::Isolate* isolate = env->GetIsolate();
- v8::HandleScope handle_scope(isolate);
+ ElementType* backing_store = new ElementType[kElementCount+2];
Sven Panne 2013/05/23 07:57:01 Using 'ScopedVector<ElementType> backing_store(kEl
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
+ {
+ LocalContext env;
+ v8::Isolate* isolate = env->GetIsolate();
+ v8::HandleScope handle_scope(isolate);
- Local<v8::ArrayBuffer> ab =
- v8::ArrayBuffer::New((kElementCount+2)*sizeof(ElementType));
- Local<TypedArray> ta =
- TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
- CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
- CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
- CHECK_EQ(kElementCount*sizeof(ElementType),
- static_cast<int>(ta->ByteLength()));
- CHECK_EQ(ab, ta->Buffer());
-
- ElementType* data = static_cast<ElementType*>(ab->Data()) + 2;
- for (int i = 0; i < kElementCount; i++) {
- data[i] = static_cast<ElementType>(i);
- }
+ Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
+ backing_store, (kElementCount+2)*sizeof(ElementType));
+ Local<TypedArray> ta =
+ TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
+ CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
+ CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
+ CHECK_EQ(kElementCount*sizeof(ElementType),
+ static_cast<int>(ta->ByteLength()));
+ CHECK_EQ(ab, ta->Buffer());
+
+ ElementType* data = backing_store + 2;
+ for (int i = 0; i < kElementCount; i++) {
+ data[i] = static_cast<ElementType>(i);
+ }
- ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
- env.local(), ta, kElementCount, array_type, low, high);
+ ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
+ env.local(), ta, kElementCount, array_type, low, high);
+ }
+ delete[] backing_store;
}
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698