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

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

Issue 18695004: Add internal fields to JSArrayBufferViews (JSTypedArray and JSDataView) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 5 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 | « 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 2535 matching lines...) Expand 10 before | Expand all | Expand 10 after
2546 explicit ScopedArrayBufferContents( 2546 explicit ScopedArrayBufferContents(
2547 const v8::ArrayBuffer::Contents& contents) 2547 const v8::ArrayBuffer::Contents& contents)
2548 : contents_(contents) {} 2548 : contents_(contents) {}
2549 ~ScopedArrayBufferContents() { free(contents_.Data()); } 2549 ~ScopedArrayBufferContents() { free(contents_.Data()); }
2550 void* Data() const { return contents_.Data(); } 2550 void* Data() const { return contents_.Data(); }
2551 size_t ByteLength() const { return contents_.ByteLength(); } 2551 size_t ByteLength() const { return contents_.ByteLength(); }
2552 private: 2552 private:
2553 const v8::ArrayBuffer::Contents contents_; 2553 const v8::ArrayBuffer::Contents contents_;
2554 }; 2554 };
2555 2555
2556 template <typename T>
2557 static void CheckInternalFieldsAreZero(v8::Handle<T> value) {
2558 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount());
2559 for (int i = 0; i < value->InternalFieldCount(); i++) {
2560 CHECK_EQ(0, value->GetInternalField(i)->Int32Value());
2561 }
2562 }
2563
2556 2564
2557 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { 2565 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
2558 i::FLAG_harmony_array_buffer = true; 2566 i::FLAG_harmony_array_buffer = true;
2559 i::FLAG_harmony_typed_arrays = true; 2567 i::FLAG_harmony_typed_arrays = true;
2560 2568
2561 LocalContext env; 2569 LocalContext env;
2562 v8::Isolate* isolate = env->GetIsolate(); 2570 v8::Isolate* isolate = env->GetIsolate();
2563 v8::HandleScope handle_scope(isolate); 2571 v8::HandleScope handle_scope(isolate);
2564 2572
2565 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024); 2573 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(1024);
2574 CheckInternalFieldsAreZero(ab);
2566 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2575 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2567 CHECK(!ab->IsExternal()); 2576 CHECK(!ab->IsExternal());
2568 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2577 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2569 2578
2570 ScopedArrayBufferContents ab_contents(ab->Externalize()); 2579 ScopedArrayBufferContents ab_contents(ab->Externalize());
2571 CHECK(ab->IsExternal()); 2580 CHECK(ab->IsExternal());
2572 2581
2573 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 2582 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2574 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 2583 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2575 ASSERT(data != NULL); 2584 ASSERT(data != NULL);
(...skipping 24 matching lines...) Expand all
2600 v8::Isolate* isolate = env->GetIsolate(); 2609 v8::Isolate* isolate = env->GetIsolate();
2601 v8::HandleScope handle_scope(isolate); 2610 v8::HandleScope handle_scope(isolate);
2602 2611
2603 2612
2604 v8::Local<v8::Value> result = 2613 v8::Local<v8::Value> result =
2605 CompileRun("var ab1 = new ArrayBuffer(2);" 2614 CompileRun("var ab1 = new ArrayBuffer(2);"
2606 "var u8_a = new Uint8Array(ab1);" 2615 "var u8_a = new Uint8Array(ab1);"
2607 "u8_a[0] = 0xAA;" 2616 "u8_a[0] = 0xAA;"
2608 "u8_a[1] = 0xFF; u8_a.buffer"); 2617 "u8_a[1] = 0xFF; u8_a.buffer");
2609 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); 2618 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result);
2619 CheckInternalFieldsAreZero(ab1);
2610 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); 2620 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2611 CHECK(!ab1->IsExternal()); 2621 CHECK(!ab1->IsExternal());
2612 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); 2622 ScopedArrayBufferContents ab1_contents(ab1->Externalize());
2613 CHECK(ab1->IsExternal()); 2623 CHECK(ab1->IsExternal());
2614 2624
2615 result = CompileRun("ab1.byteLength"); 2625 result = CompileRun("ab1.byteLength");
2616 CHECK_EQ(2, result->Int32Value()); 2626 CHECK_EQ(2, result->Int32Value());
2617 result = CompileRun("u8_a[0]"); 2627 result = CompileRun("u8_a[0]");
2618 CHECK_EQ(0xAA, result->Int32Value()); 2628 CHECK_EQ(0xAA, result->Int32Value());
2619 result = CompileRun("u8_a[1]"); 2629 result = CompileRun("u8_a[1]");
(...skipping 20 matching lines...) Expand all
2640 i::FLAG_harmony_array_buffer = true; 2650 i::FLAG_harmony_array_buffer = true;
2641 i::FLAG_harmony_typed_arrays = true; 2651 i::FLAG_harmony_typed_arrays = true;
2642 2652
2643 LocalContext env; 2653 LocalContext env;
2644 v8::Isolate* isolate = env->GetIsolate(); 2654 v8::Isolate* isolate = env->GetIsolate();
2645 v8::HandleScope handle_scope(isolate); 2655 v8::HandleScope handle_scope(isolate);
2646 2656
2647 i::ScopedVector<uint8_t> my_data(100); 2657 i::ScopedVector<uint8_t> my_data(100);
2648 memset(my_data.start(), 0, 100); 2658 memset(my_data.start(), 0, 100);
2649 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data.start(), 100); 2659 Local<v8::ArrayBuffer> ab3 = v8::ArrayBuffer::New(my_data.start(), 100);
2660 CheckInternalFieldsAreZero(ab3);
2650 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); 2661 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2651 CHECK(ab3->IsExternal()); 2662 CHECK(ab3->IsExternal());
2652 2663
2653 env->Global()->Set(v8_str("ab3"), ab3); 2664 env->Global()->Set(v8_str("ab3"), ab3);
2654 2665
2655 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); 2666 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength");
2656 CHECK_EQ(100, result->Int32Value()); 2667 CHECK_EQ(100, result->Int32Value());
2657 2668
2658 result = CompileRun("var u8_b = new Uint8Array(ab3);" 2669 result = CompileRun("var u8_b = new Uint8Array(ab3);"
2659 "u8_b[0] = 0xBB;" 2670 "u8_b[0] = 0xBB;"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 v8::Handle<v8::TypedArray>::Cast(CompileRun(name)); 2703 v8::Handle<v8::TypedArray>::Cast(CompileRun(name));
2693 CheckIsNeutered(ta); 2704 CheckIsNeutered(ta);
2694 } 2705 }
2695 2706
2696 2707
2697 template <typename TypedArray, int kElementSize> 2708 template <typename TypedArray, int kElementSize>
2698 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, 2709 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab,
2699 int byteOffset, 2710 int byteOffset,
2700 int length) { 2711 int length) {
2701 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); 2712 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length);
2713 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
2702 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); 2714 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
2703 CHECK_EQ(length, static_cast<int>(ta->Length())); 2715 CHECK_EQ(length, static_cast<int>(ta->Length()));
2704 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); 2716 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
2705 return ta; 2717 return ta;
2706 } 2718 }
2707 2719
2708 2720
2709 THREADED_TEST(ArrayBuffer_NeuteringApi) { 2721 THREADED_TEST(ArrayBuffer_NeuteringApi) {
2710 LocalContext env; 2722 LocalContext env;
2711 v8::Isolate* isolate = env->GetIsolate(); 2723 v8::Isolate* isolate = env->GetIsolate();
(...skipping 17 matching lines...) Expand all
2729 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); 2741 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
2730 v8::Handle<v8::Int32Array> i32a = 2742 v8::Handle<v8::Int32Array> i32a =
2731 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); 2743 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
2732 2744
2733 v8::Handle<v8::Float32Array> f32a = 2745 v8::Handle<v8::Float32Array> f32a =
2734 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); 2746 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
2735 v8::Handle<v8::Float64Array> f64a = 2747 v8::Handle<v8::Float64Array> f64a =
2736 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); 2748 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
2737 2749
2738 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023); 2750 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023);
2751 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
2739 CHECK_EQ(1, static_cast<int>(dv->ByteOffset())); 2752 CHECK_EQ(1, static_cast<int>(dv->ByteOffset()));
2740 CHECK_EQ(1023, static_cast<int>(dv->ByteLength())); 2753 CHECK_EQ(1023, static_cast<int>(dv->ByteLength()));
2741 2754
2742 ScopedArrayBufferContents contents(buffer->Externalize()); 2755 ScopedArrayBufferContents contents(buffer->Externalize());
2743 buffer->Neuter(); 2756 buffer->Neuter();
2744 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); 2757 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
2745 CheckIsNeutered(u8a); 2758 CheckIsNeutered(u8a);
2746 CheckIsNeutered(u8c); 2759 CheckIsNeutered(u8c);
2747 CheckIsNeutered(i8a); 2760 CheckIsNeutered(i8a);
2748 CheckIsNeutered(u16a); 2761 CheckIsNeutered(u16a);
(...skipping 12978 matching lines...) Expand 10 before | Expand all | Expand 10 after
15727 i::ScopedVector<ElementType> backing_store(kElementCount+2); 15740 i::ScopedVector<ElementType> backing_store(kElementCount+2);
15728 15741
15729 LocalContext env; 15742 LocalContext env;
15730 v8::Isolate* isolate = env->GetIsolate(); 15743 v8::Isolate* isolate = env->GetIsolate();
15731 v8::HandleScope handle_scope(isolate); 15744 v8::HandleScope handle_scope(isolate);
15732 15745
15733 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( 15746 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
15734 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); 15747 backing_store.start(), (kElementCount+2)*sizeof(ElementType));
15735 Local<TypedArray> ta = 15748 Local<TypedArray> ta =
15736 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount); 15749 TypedArray::New(ab, 2*sizeof(ElementType), kElementCount);
15750 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
15737 CHECK_EQ(kElementCount, static_cast<int>(ta->Length())); 15751 CHECK_EQ(kElementCount, static_cast<int>(ta->Length()));
15738 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset())); 15752 CHECK_EQ(2*sizeof(ElementType), static_cast<int>(ta->ByteOffset()));
15739 CHECK_EQ(kElementCount*sizeof(ElementType), 15753 CHECK_EQ(kElementCount*sizeof(ElementType),
15740 static_cast<int>(ta->ByteLength())); 15754 static_cast<int>(ta->ByteLength()));
15741 CHECK_EQ(ab, ta->Buffer()); 15755 CHECK_EQ(ab, ta->Buffer());
15742 15756
15743 ElementType* data = backing_store.start() + 2; 15757 ElementType* data = backing_store.start() + 2;
15744 for (int i = 0; i < kElementCount; i++) { 15758 for (int i = 0; i < kElementCount; i++) {
15745 data[i] = static_cast<ElementType>(i); 15759 data[i] = static_cast<ElementType>(i);
15746 } 15760 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
15812 i::ScopedVector<uint8_t> backing_store(kSize+2); 15826 i::ScopedVector<uint8_t> backing_store(kSize+2);
15813 15827
15814 LocalContext env; 15828 LocalContext env;
15815 v8::Isolate* isolate = env->GetIsolate(); 15829 v8::Isolate* isolate = env->GetIsolate();
15816 v8::HandleScope handle_scope(isolate); 15830 v8::HandleScope handle_scope(isolate);
15817 15831
15818 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( 15832 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(
15819 backing_store.start(), 2 + kSize); 15833 backing_store.start(), 2 + kSize);
15820 Local<v8::DataView> dv = 15834 Local<v8::DataView> dv =
15821 v8::DataView::New(ab, 2, kSize); 15835 v8::DataView::New(ab, 2, kSize);
15836 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
15822 CHECK_EQ(2, static_cast<int>(dv->ByteOffset())); 15837 CHECK_EQ(2, static_cast<int>(dv->ByteOffset()));
15823 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); 15838 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
15824 CHECK_EQ(ab, dv->Buffer()); 15839 CHECK_EQ(ab, dv->Buffer());
15825 } 15840 }
15826 15841
15827 15842
15828 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ 15843 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
15829 THREADED_TEST(Is##View) { \ 15844 THREADED_TEST(Is##View) { \
15830 i::FLAG_harmony_array_buffer = true; \ 15845 i::FLAG_harmony_array_buffer = true; \
15831 i::FLAG_harmony_typed_arrays = true; \ 15846 i::FLAG_harmony_typed_arrays = true; \
15832 LocalContext env; \ 15847 LocalContext env; \
15833 v8::Isolate* isolate = env->GetIsolate(); \ 15848 v8::Isolate* isolate = env->GetIsolate(); \
15834 v8::HandleScope handle_scope(isolate); \ 15849 v8::HandleScope handle_scope(isolate); \
15835 \ 15850 \
15836 Handle<Value> result = CompileRun( \ 15851 Handle<Value> result = CompileRun( \
15837 "var ab = new ArrayBuffer(128);" \ 15852 "var ab = new ArrayBuffer(128);" \
15838 "new " #View "(ab)"); \ 15853 "new " #View "(ab)"); \
15839 CHECK(result->IsArrayBufferView()); \ 15854 CHECK(result->IsArrayBufferView()); \
15840 CHECK(result->Is##View()); \ 15855 CHECK(result->Is##View()); \
15856 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \
15841 } 15857 }
15842 15858
15843 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array) 15859 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array)
15844 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array) 15860 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array)
15845 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array) 15861 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array)
15846 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array) 15862 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array)
15847 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array) 15863 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array)
15848 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array) 15864 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array)
15849 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array) 15865 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array)
15850 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array) 15866 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array)
(...skipping 3751 matching lines...) Expand 10 before | Expand all | Expand 10 after
19602 i::Semaphore* sem_; 19618 i::Semaphore* sem_;
19603 volatile int sem_value_; 19619 volatile int sem_value_;
19604 }; 19620 };
19605 19621
19606 19622
19607 THREADED_TEST(SemaphoreInterruption) { 19623 THREADED_TEST(SemaphoreInterruption) {
19608 ThreadInterruptTest().RunTest(); 19624 ThreadInterruptTest().RunTest();
19609 } 19625 }
19610 19626
19611 #endif // WIN32 19627 #endif // WIN32
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698