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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2486 CHECK(obj->Has(sym1)); 2486 CHECK(obj->Has(sym1));
2487 CHECK(obj->Has(sym2)); 2487 CHECK(obj->Has(sym2));
2488 CHECK(obj->Delete(sym2)); 2488 CHECK(obj->Delete(sym2));
2489 CHECK(obj->Has(sym1)); 2489 CHECK(obj->Has(sym1));
2490 CHECK(!obj->Has(sym2)); 2490 CHECK(!obj->Has(sym2));
2491 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2491 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2492 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2492 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2493 } 2493 }
2494 2494
2495 2495
2496 THREADED_TEST(ArrayBuffer) { 2496 THREADED_TEST(ArrayBuffer) {
Sven Panne 2013/05/23 07:57:01 Can we please split this test into several tests?
Dmitry Lomov (no reviews) 2013/05/23 08:42:15 Done.
2497 i::FLAG_harmony_array_buffer = true; 2497 i::FLAG_harmony_array_buffer = true;
2498 i::FLAG_harmony_typed_arrays = true; 2498 i::FLAG_harmony_typed_arrays = true;
2499 2499
2500 LocalContext env; 2500 LocalContext env;
2501 v8::Isolate* isolate = env->GetIsolate(); 2501 v8::Isolate* isolate = env->GetIsolate();
2502 v8::HandleScope handle_scope(isolate); 2502 v8::HandleScope handle_scope(isolate);
2503 2503
2504 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); 2504 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024);
2505 CHECK_EQ(1024, ab->ByteLength());
2506 CHECK(!ab->IsExternal());
2505 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2507 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2506 2508
2507 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2509 v8::ArrayBufferContents ab_contents;
2508 uint8_t* data = static_cast<uint8_t*>(ab->Data()); 2510 ab->Externalize(&ab_contents);
2511 CHECK(ab->IsExternal());
2512
2513 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2514 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2509 ASSERT(data != NULL); 2515 ASSERT(data != NULL);
2510 env->Global()->Set(v8_str("ab"), ab); 2516 env->Global()->Set(v8_str("ab"), ab);
2511 2517
2512 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); 2518 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
2513 CHECK_EQ(1024, result->Int32Value()); 2519 CHECK_EQ(1024, result->Int32Value());
2514 2520
2515 result = CompileRun("var u8 = new Uint8Array(ab);" 2521 result = CompileRun("var u8 = new Uint8Array(ab);"
2516 "u8[0] = 0xFF;" 2522 "u8[0] = 0xFF;"
2517 "u8[1] = 0xAA;" 2523 "u8[1] = 0xAA;"
2518 "u8.length"); 2524 "u8.length");
2519 CHECK_EQ(1024, result->Int32Value()); 2525 CHECK_EQ(1024, result->Int32Value());
2520 CHECK_EQ(0xFF, data[0]); 2526 CHECK_EQ(0xFF, data[0]);
2521 CHECK_EQ(0xAA, data[1]); 2527 CHECK_EQ(0xAA, data[1]);
2522 data[0] = 0xCC; 2528 data[0] = 0xCC;
2523 data[1] = 0x11; 2529 data[1] = 0x11;
2524 result = CompileRun("u8[0] + u8[1]"); 2530 result = CompileRun("u8[0] + u8[1]");
2525 CHECK_EQ(0xDD, result->Int32Value()); 2531 CHECK_EQ(0xDD, result->Int32Value());
2526 2532
2527 result = CompileRun("var ab1 = new ArrayBuffer(2);" 2533 result = CompileRun("var ab1 = new ArrayBuffer(2);"
2528 "var u8_a = new Uint8Array(ab1);" 2534 "var u8_a = new Uint8Array(ab1);"
2529 "u8_a[0] = 0xAA;" 2535 "u8_a[0] = 0xAA;"
2530 "u8_a[1] = 0xFF; u8_a.buffer"); 2536 "u8_a[1] = 0xFF; u8_a.buffer");
2531 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); 2537 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result);
2532 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); 2538 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2533 uint8_t* ab1_data = static_cast<uint8_t*>(ab1->Data()); 2539 CHECK(!ab1->IsExternal());
2540 v8::ArrayBufferContents ab1_contents;
2541 ab1->Externalize(&ab1_contents);
2542 CHECK(ab1->IsExternal());
2543
2544 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2545 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2534 CHECK_EQ(0xAA, ab1_data[0]); 2546 CHECK_EQ(0xAA, ab1_data[0]);
2535 CHECK_EQ(0xFF, ab1_data[1]); 2547 CHECK_EQ(0xFF, ab1_data[1]);
2536 ab1_data[0] = 0xCC; 2548 ab1_data[0] = 0xCC;
2537 ab1_data[1] = 0x11; 2549 ab1_data[1] = 0x11;
2538 result = CompileRun("u8_a[0] + u8_a[1]"); 2550 result = CompileRun("u8_a[0] + u8_a[1]");
2539 CHECK_EQ(0xDD, result->Int32Value()); 2551 CHECK_EQ(0xDD, result->Int32Value());
2540 2552
2541 uint8_t* my_data = new uint8_t[100]; 2553 uint8_t* my_data = new uint8_t[100];
2542 memset(my_data, 0, 100); 2554 memset(my_data, 0, 100);
2543 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data, 100); 2555 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data, 100);
2544 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); 2556 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2545 CHECK_EQ(my_data, ab3->Data()); 2557 CHECK(ab3->IsExternal());
2558
2546 env->Global()->Set(v8_str("ab3"), ab3); 2559 env->Global()->Set(v8_str("ab3"), ab3);
2560
2561 result = CompileRun("ab3.byteLength");
2562 CHECK_EQ(100, result->Int32Value());
2563
2547 result = CompileRun("var u8_b = new Uint8Array(ab3);" 2564 result = CompileRun("var u8_b = new Uint8Array(ab3);"
2548 "u8_b[0] = 0xBB;" 2565 "u8_b[0] = 0xBB;"
2549 "u8_b[1] = 0xCC;" 2566 "u8_b[1] = 0xCC;"
2550 "u8_b.length"); 2567 "u8_b.length");
2551 CHECK_EQ(100, result->Int32Value()); 2568 CHECK_EQ(100, result->Int32Value());
2552 CHECK_EQ(0xBB, my_data[0]); 2569 CHECK_EQ(0xBB, my_data[0]);
2553 CHECK_EQ(0xCC, my_data[1]); 2570 CHECK_EQ(0xCC, my_data[1]);
2554 my_data[0] = 0xCC; 2571 my_data[0] = 0xCC;
2555 my_data[1] = 0x11; 2572 my_data[1] = 0x11;
2556 result = CompileRun("u8_b[0] + u8_b[1]"); 2573 result = CompileRun("u8_b[0] + u8_b[1]");
2557 CHECK_EQ(0xDD, result->Int32Value()); 2574 CHECK_EQ(0xDD, result->Int32Value());
2558 2575
2559 delete[] my_data; 2576 delete[] my_data;
2560 } 2577 }
2561 2578
2562 2579
2563
2564
2565
2566 THREADED_TEST(HiddenProperties) { 2580 THREADED_TEST(HiddenProperties) {
2567 LocalContext env; 2581 LocalContext env;
2568 v8::HandleScope scope(env->GetIsolate()); 2582 v8::HandleScope scope(env->GetIsolate());
2569 2583
2570 v8::Local<v8::Object> obj = v8::Object::New(); 2584 v8::Local<v8::Object> obj = v8::Object::New();
2571 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2585 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2572 v8::Local<v8::String> empty = v8_str(""); 2586 v8::Local<v8::String> empty = v8_str("");
2573 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2587 v8::Local<v8::String> prop_name = v8_str("prop_name");
2574 2588
2575 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2589 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 12877 matching lines...) Expand 10 before | Expand all | Expand 10 after
15453 15467
15454 15468
15455 template <typename ElementType, typename TypedArray, 15469 template <typename ElementType, typename TypedArray,
15456 class ExternalArrayClass> 15470 class ExternalArrayClass>
15457 void TypedArrayTestHelper(v8::ExternalArrayType array_type, 15471 void TypedArrayTestHelper(v8::ExternalArrayType array_type,
15458 int64_t low, int64_t high) { 15472 int64_t low, int64_t high) {
15459 const int kElementCount = 50; 15473 const int kElementCount = 50;
15460 i::FLAG_harmony_array_buffer = true; 15474 i::FLAG_harmony_array_buffer = true;
15461 i::FLAG_harmony_typed_arrays = true; 15475 i::FLAG_harmony_typed_arrays = true;
15462 15476
15463 LocalContext env; 15477 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.
15464 v8::Isolate* isolate = env->GetIsolate(); 15478 {
15465 v8::HandleScope handle_scope(isolate); 15479 LocalContext env;
15480 v8::Isolate* isolate = env->GetIsolate();
15481 v8::HandleScope handle_scope(isolate);
15466 15482
15467 Local<v8::ArrayBuffer> ab = 15483 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
15468 v8::ArrayBuffer::New((kElementCount+2)*sizeof(ElementType)); 15484 backing_store, (kElementCount+2)*sizeof(ElementType));
15469 Local<TypedArray> ta = 15485 Local<TypedArray> ta =
15470 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); 15486 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
15471 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); 15487 CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
15472 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset())); 15488 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
15473 CHECK_EQ(kElementCount*sizeof(ElementType), 15489 CHECK_EQ(kElementCount*sizeof(ElementType),
15474 static_cast<int>(ta->ByteLength())); 15490 static_cast<int>(ta->ByteLength()));
15475 CHECK_EQ(ab, ta->Buffer()); 15491 CHECK_EQ(ab, ta->Buffer());
15476 15492
15477 ElementType* data = static_cast<ElementType*>(ab->Data()) + 2; 15493 ElementType* data = backing_store + 2;
15478 for (int i = 0; i < kElementCount; i++) { 15494 for (int i = 0; i < kElementCount; i++) {
15479 data[i] = static_cast<ElementType>(i); 15495 data[i] = static_cast<ElementType>(i);
15496 }
15497
15498 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
15499 env.local(), ta, kElementCount, array_type, low, high);
15480 } 15500 }
15481 15501 delete[] backing_store;
15482 ObjectWithExternalArrayTestHelper<ExternalArrayClass, ElementType>(
15483 env.local(), ta, kElementCount, array_type, low, high);
15484 } 15502 }
15485 15503
15486 15504
15487 THREADED_TEST(Uint8Array) { 15505 THREADED_TEST(Uint8Array) {
15488 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUnsignedByteArray>( 15506 TypedArrayTestHelper<uint8_t, v8::Uint8Array, i::ExternalUnsignedByteArray>(
15489 v8::kExternalUnsignedByteArray, 0, 0xFF); 15507 v8::kExternalUnsignedByteArray, 0, 0xFF);
15490 } 15508 }
15491 15509
15492 15510
15493 THREADED_TEST(Int8Array) { 15511 THREADED_TEST(Int8Array) {
(...skipping 3758 matching lines...) Expand 10 before | Expand all | Expand 10 after
19252 i::Semaphore* sem_; 19270 i::Semaphore* sem_;
19253 volatile int sem_value_; 19271 volatile int sem_value_;
19254 }; 19272 };
19255 19273
19256 19274
19257 THREADED_TEST(SemaphoreInterruption) { 19275 THREADED_TEST(SemaphoreInterruption) {
19258 ThreadInterruptTest().RunTest(); 19276 ThreadInterruptTest().RunTest();
19259 } 19277 }
19260 19278
19261 #endif // WIN32 19279 #endif // WIN32
OLDNEW
« 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