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

Side by Side Diff: test/cctest/test-api.cc

Issue 15855012: Change ArrayBuffer API and implementation to use embedder-provided allocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 6 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
« no previous file with comments | « test/cctest/cctest.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 2529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 CHECK(obj->Has(sym1)); 2540 CHECK(obj->Has(sym1));
2541 CHECK(obj->Has(sym2)); 2541 CHECK(obj->Has(sym2));
2542 CHECK(obj->Delete(sym2)); 2542 CHECK(obj->Delete(sym2));
2543 CHECK(obj->Has(sym1)); 2543 CHECK(obj->Has(sym1));
2544 CHECK(!obj->Has(sym2)); 2544 CHECK(!obj->Has(sym2));
2545 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2545 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2546 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length()); 2546 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2547 } 2547 }
2548 2548
2549 2549
2550 class ScopedArrayBufferContents {
2551 public:
2552 explicit ScopedArrayBufferContents(
2553 const v8::ArrayBuffer::Contents& contents)
2554 : contents_(contents) {}
2555 ~ScopedArrayBufferContents() { free(contents_.Data()); }
2556 void* Data() const { return contents_.Data(); }
2557 size_t ByteLength() const { return contents_.ByteLength(); }
2558 private:
2559 const v8::ArrayBuffer::Contents contents_;
2560 };
2561
2562
2550 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { 2563 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
2551 i::FLAG_harmony_array_buffer = true; 2564 i::FLAG_harmony_array_buffer = true;
2552 i::FLAG_harmony_typed_arrays = true; 2565 i::FLAG_harmony_typed_arrays = true;
2553 2566
2554 LocalContext env; 2567 LocalContext env;
2555 v8::Isolate* isolate = env->GetIsolate(); 2568 v8::Isolate* isolate = env->GetIsolate();
2556 v8::HandleScope handle_scope(isolate); 2569 v8::HandleScope handle_scope(isolate);
2557 2570
2558 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); 2571 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024);
2559 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2572 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2560 CHECK(!ab->IsExternal()); 2573 CHECK(!ab->IsExternal());
2561 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2574 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2562 2575
2563 v8::ArrayBufferContents ab_contents; 2576 ScopedArrayBufferContents ab_contents(ab->Externalize());
2564 ab->Externalize(&ab_contents);
2565 CHECK(ab->IsExternal()); 2577 CHECK(ab->IsExternal());
2566 2578
2567 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 2579 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2568 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 2580 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2569 ASSERT(data != NULL); 2581 ASSERT(data != NULL);
2570 env->Global()->Set(v8_str("ab"), ab); 2582 env->Global()->Set(v8_str("ab"), ab);
2571 2583
2572 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); 2584 v8::Handle<v8::Value> result = CompileRun("ab.byteLength");
2573 CHECK_EQ(1024, result->Int32Value()); 2585 CHECK_EQ(1024, result->Int32Value());
2574 2586
(...skipping 21 matching lines...) Expand all
2596 2608
2597 2609
2598 v8::Handle<v8::Value> result = 2610 v8::Handle<v8::Value> result =
2599 CompileRun("var ab1 = new ArrayBuffer(2);" 2611 CompileRun("var ab1 = new ArrayBuffer(2);"
2600 "var u8_a = new Uint8Array(ab1);" 2612 "var u8_a = new Uint8Array(ab1);"
2601 "u8_a[0] = 0xAA;" 2613 "u8_a[0] = 0xAA;"
2602 "u8_a[1] = 0xFF; u8_a.buffer"); 2614 "u8_a[1] = 0xFF; u8_a.buffer");
2603 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); 2615 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result);
2604 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); 2616 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2605 CHECK(!ab1->IsExternal()); 2617 CHECK(!ab1->IsExternal());
2606 v8::ArrayBufferContents ab1_contents; 2618 ScopedArrayBufferContents ab1_contents(ab1->Externalize());
2607 ab1->Externalize(&ab1_contents);
2608 CHECK(ab1->IsExternal()); 2619 CHECK(ab1->IsExternal());
2609 2620
2610 result = CompileRun("ab1.byteLength"); 2621 result = CompileRun("ab1.byteLength");
2611 CHECK_EQ(2, result->Int32Value()); 2622 CHECK_EQ(2, result->Int32Value());
2612 result = CompileRun("u8_a[0]"); 2623 result = CompileRun("u8_a[0]");
2613 CHECK_EQ(0xAA, result->Int32Value()); 2624 CHECK_EQ(0xAA, result->Int32Value());
2614 result = CompileRun("u8_a[1]"); 2625 result = CompileRun("u8_a[1]");
2615 CHECK_EQ(0xFF, result->Int32Value()); 2626 CHECK_EQ(0xFF, result->Int32Value());
2616 result = CompileRun("var u8_b = new Uint8Array(ab1);" 2627 result = CompileRun("var u8_b = new Uint8Array(ab1);"
2617 "u8_b[0] = 0xBB;" 2628 "u8_b[0] = 0xBB;"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 v8::Handle<v8::Uint32Array> u32a = 2715 v8::Handle<v8::Uint32Array> u32a =
2705 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); 2716 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
2706 v8::Handle<v8::Int32Array> i32a = 2717 v8::Handle<v8::Int32Array> i32a =
2707 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); 2718 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
2708 2719
2709 v8::Handle<v8::Float32Array> f32a = 2720 v8::Handle<v8::Float32Array> f32a =
2710 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); 2721 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
2711 v8::Handle<v8::Float64Array> f64a = 2722 v8::Handle<v8::Float64Array> f64a =
2712 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); 2723 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
2713 2724
2714 v8::ArrayBufferContents contents; 2725 ScopedArrayBufferContents contents(buffer->Externalize());
2715 buffer->Externalize(&contents);
2716 buffer->Neuter(); 2726 buffer->Neuter();
2717 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); 2727 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
2718 CheckIsNeutered(u8a); 2728 CheckIsNeutered(u8a);
2719 CheckIsNeutered(u8c); 2729 CheckIsNeutered(u8c);
2720 CheckIsNeutered(i8a); 2730 CheckIsNeutered(i8a);
2721 CheckIsNeutered(u16a); 2731 CheckIsNeutered(u16a);
2722 CheckIsNeutered(i16a); 2732 CheckIsNeutered(i16a);
2723 CheckIsNeutered(u32a); 2733 CheckIsNeutered(u32a);
2724 CheckIsNeutered(i32a); 2734 CheckIsNeutered(i32a);
2725 CheckIsNeutered(f32a); 2735 CheckIsNeutered(f32a);
(...skipping 30 matching lines...) Expand all
2756 v8::Int16Array::Cast(*CompileRun("i16a"))); 2766 v8::Int16Array::Cast(*CompileRun("i16a")));
2757 v8::Handle<v8::Uint32Array> u32a( 2767 v8::Handle<v8::Uint32Array> u32a(
2758 v8::Uint32Array::Cast(*CompileRun("u32a"))); 2768 v8::Uint32Array::Cast(*CompileRun("u32a")));
2759 v8::Handle<v8::Int32Array> i32a( 2769 v8::Handle<v8::Int32Array> i32a(
2760 v8::Int32Array::Cast(*CompileRun("i32a"))); 2770 v8::Int32Array::Cast(*CompileRun("i32a")));
2761 v8::Handle<v8::Float32Array> f32a( 2771 v8::Handle<v8::Float32Array> f32a(
2762 v8::Float32Array::Cast(*CompileRun("f32a"))); 2772 v8::Float32Array::Cast(*CompileRun("f32a")));
2763 v8::Handle<v8::Float64Array> f64a( 2773 v8::Handle<v8::Float64Array> f64a(
2764 v8::Float64Array::Cast(*CompileRun("f64a"))); 2774 v8::Float64Array::Cast(*CompileRun("f64a")));
2765 2775
2766 v8::ArrayBufferContents contents; 2776 ScopedArrayBufferContents contents(ab->Externalize());
2767 ab->Externalize(&contents);
2768 ab->Neuter(); 2777 ab->Neuter();
2769 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); 2778 CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
2770 CheckIsNeutered(u8a); 2779 CheckIsNeutered(u8a);
2771 CheckIsNeutered(u8c); 2780 CheckIsNeutered(u8c);
2772 CheckIsNeutered(i8a); 2781 CheckIsNeutered(i8a);
2773 CheckIsNeutered(u16a); 2782 CheckIsNeutered(u16a);
2774 CheckIsNeutered(i16a); 2783 CheckIsNeutered(i16a);
2775 CheckIsNeutered(u32a); 2784 CheckIsNeutered(u32a);
2776 CheckIsNeutered(i32a); 2785 CheckIsNeutered(i32a);
2777 CheckIsNeutered(f32a); 2786 CheckIsNeutered(f32a);
(...skipping 16551 matching lines...) Expand 10 before | Expand all | Expand 10 after
19329 i::Semaphore* sem_; 19338 i::Semaphore* sem_;
19330 volatile int sem_value_; 19339 volatile int sem_value_;
19331 }; 19340 };
19332 19341
19333 19342
19334 THREADED_TEST(SemaphoreInterruption) { 19343 THREADED_TEST(SemaphoreInterruption) {
19335 ThreadInterruptTest().RunTest(); 19344 ThreadInterruptTest().RunTest();
19336 } 19345 }
19337 19346
19338 #endif // WIN32 19347 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/cctest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698