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

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

Issue 16562005: Neutering API for v8::ArrayBuffer (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Style 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 | « src/objects.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 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 CHECK_EQ(100, result->Int32Value()); 2650 CHECK_EQ(100, result->Int32Value());
2651 CHECK_EQ(0xBB, my_data[0]); 2651 CHECK_EQ(0xBB, my_data[0]);
2652 CHECK_EQ(0xCC, my_data[1]); 2652 CHECK_EQ(0xCC, my_data[1]);
2653 my_data[0] = 0xCC; 2653 my_data[0] = 0xCC;
2654 my_data[1] = 0x11; 2654 my_data[1] = 0x11;
2655 result = CompileRun("u8_b[0] + u8_b[1]"); 2655 result = CompileRun("u8_b[0] + u8_b[1]");
2656 CHECK_EQ(0xDD, result->Int32Value()); 2656 CHECK_EQ(0xDD, result->Int32Value());
2657 } 2657 }
2658 2658
2659 2659
2660 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) {
2661 CHECK_EQ(0, static_cast<int>(ta->ByteLength()));
2662 CHECK_EQ(0, static_cast<int>(ta->Length()));
2663 CHECK_EQ(0, static_cast<int>(ta->ByteOffset()));
2664 }
2665
2666 template <typename TypedArray, int kElementSize>
2667 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab,
2668 int byteOffset,
Sven Panne 2013/06/07 12:21:08 Using size_t instead of int for offset/length is c
Dmitry Lomov (no reviews) 2013/06/07 14:57:09 No it does not get rid of casts - compiler gets co
2669 int length) {
2670 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length);
2671 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
2672 CHECK_EQ(length, static_cast<int>(ta->Length()));
2673 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
2674 return ta;
2675 }
2676
2677
2678 THREADED_TEST(ArrayBuffer_NeuteringApi) {
2679 LocalContext env;
2680 v8::Isolate* isolate = env->GetIsolate();
2681 v8::HandleScope handle_scope(isolate);
2682
2683 v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(1024);
2684
2685 v8::Handle<v8::Uint8Array> u8a =
2686 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023);
2687 v8::Handle<v8::Uint8ClampedArray> u8c =
2688 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023);
2689 v8::Handle<v8::Int8Array> i8a =
2690 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023);
2691
2692 v8::Handle<v8::Uint16Array> u16a =
2693 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511);
2694 v8::Handle<v8::Int16Array> i16a =
2695 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511);
2696
2697 v8::Handle<v8::Uint32Array> u32a =
2698 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
2699 v8::Handle<v8::Int32Array> i32a =
2700 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
2701
2702 v8::Handle<v8::Float32Array> f32a =
2703 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
2704 v8::Handle<v8::Float64Array> f64a =
2705 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
2706
2707 v8::ArrayBufferContents contents;
2708 buffer->Externalize(&contents);
2709 buffer->Neuter();
2710 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
2711 CheckIsNeutered(u8a);
2712 CheckIsNeutered(u8c);
2713 CheckIsNeutered(i8a);
2714 CheckIsNeutered(u16a);
2715 CheckIsNeutered(i16a);
2716 CheckIsNeutered(u32a);
2717 CheckIsNeutered(i32a);
2718 CheckIsNeutered(f32a);
2719 CheckIsNeutered(f64a);
2720 }
2721
2722 THREADED_TEST(ArrayBuffer_NeuteringScript) {
2723 LocalContext env;
2724 v8::Isolate* isolate = env->GetIsolate();
2725 v8::HandleScope handle_scope(isolate);
2726
2727 CompileRun(
2728 "var ab = new ArrayBuffer(1024);"
2729 "var u8a = new Uint8Array(ab, 1, 1023);"
2730 "var u8c = new Uint8ClampedArray(ab, 1, 1023);"
2731 "var i8a = new Int8Array(ab, 1, 1023);"
2732 "var u16a = new Uint16Array(ab, 2, 511);"
2733 "var i16a = new Int16Array(ab, 2, 511);"
2734 "var u32a = new Uint32Array(ab, 4, 255);"
2735 "var i32a = new Int32Array(ab, 4, 255);"
2736 "var f32a = new Float32Array(ab, 4, 255);"
2737 "var f64a = new Float64Array(ab, 8, 127);");
2738
2739 v8::Handle<v8::ArrayBuffer> ab(v8::ArrayBuffer::Cast(*CompileRun("ab")));
2740
2741 v8::Handle<v8::Uint8Array> u8a(v8::Uint8Array::Cast(*CompileRun("u8a")));
2742 v8::Handle<v8::Uint8ClampedArray> u8c(
2743 v8::Uint8ClampedArray::Cast(*CompileRun("u8c")));
2744 v8::Handle<v8::Int8Array> i8a(v8::Int8Array::Cast(*CompileRun("i8a")));
2745
2746 v8::Handle<v8::Uint16Array> u16a(
2747 v8::Uint16Array::Cast(*CompileRun("u16a")));
2748 v8::Handle<v8::Int16Array> i16a(
2749 v8::Int16Array::Cast(*CompileRun("i16a")));
2750 v8::Handle<v8::Uint32Array> u32a(
2751 v8::Uint32Array::Cast(*CompileRun("u32a")));
2752 v8::Handle<v8::Int32Array> i32a(
2753 v8::Int32Array::Cast(*CompileRun("i32a")));
2754 v8::Handle<v8::Float32Array> f32a(
2755 v8::Float32Array::Cast(*CompileRun("f32a")));
2756 v8::Handle<v8::Float64Array> f64a(
2757 v8::Float64Array::Cast(*CompileRun("f64a")));
2758
2759 v8::ArrayBufferContents contents;
2760 ab->Externalize(&contents);
2761 ab->Neuter();
2762 CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
2763 CheckIsNeutered(u8a);
2764 CheckIsNeutered(u8c);
2765 CheckIsNeutered(i8a);
2766 CheckIsNeutered(u16a);
2767 CheckIsNeutered(i16a);
2768 CheckIsNeutered(u32a);
2769 CheckIsNeutered(i32a);
2770 CheckIsNeutered(f32a);
2771 CheckIsNeutered(f64a);
2772 }
2773
2774
2775
2660 THREADED_TEST(HiddenProperties) { 2776 THREADED_TEST(HiddenProperties) {
2661 LocalContext env; 2777 LocalContext env;
2662 v8::HandleScope scope(env->GetIsolate()); 2778 v8::HandleScope scope(env->GetIsolate());
2663 2779
2664 v8::Local<v8::Object> obj = v8::Object::New(); 2780 v8::Local<v8::Object> obj = v8::Object::New();
2665 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2781 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2666 v8::Local<v8::String> empty = v8_str(""); 2782 v8::Local<v8::String> empty = v8_str("");
2667 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2783 v8::Local<v8::String> prop_name = v8_str("prop_name");
2668 2784
2669 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2785 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 16514 matching lines...) Expand 10 before | Expand all | Expand 10 after
19184 i::Semaphore* sem_; 19300 i::Semaphore* sem_;
19185 volatile int sem_value_; 19301 volatile int sem_value_;
19186 }; 19302 };
19187 19303
19188 19304
19189 THREADED_TEST(SemaphoreInterruption) { 19305 THREADED_TEST(SemaphoreInterruption) {
19190 ThreadInterruptTest().RunTest(); 19306 ThreadInterruptTest().RunTest();
19191 } 19307 }
19192 19308
19193 #endif // WIN32 19309 #endif // WIN32
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698