| OLD | NEW |
| 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 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2659 CHECK_EQ(100, result->Int32Value()); | 2659 CHECK_EQ(100, result->Int32Value()); |
| 2660 CHECK_EQ(0xBB, my_data[0]); | 2660 CHECK_EQ(0xBB, my_data[0]); |
| 2661 CHECK_EQ(0xCC, my_data[1]); | 2661 CHECK_EQ(0xCC, my_data[1]); |
| 2662 my_data[0] = 0xCC; | 2662 my_data[0] = 0xCC; |
| 2663 my_data[1] = 0x11; | 2663 my_data[1] = 0x11; |
| 2664 result = CompileRun("u8_b[0] + u8_b[1]"); | 2664 result = CompileRun("u8_b[0] + u8_b[1]"); |
| 2665 CHECK_EQ(0xDD, result->Int32Value()); | 2665 CHECK_EQ(0xDD, result->Int32Value()); |
| 2666 } | 2666 } |
| 2667 | 2667 |
| 2668 | 2668 |
| 2669 static void CheckDataViewIsNeutered(v8::Handle<v8::DataView> dv) { |
| 2670 CHECK_EQ(0, static_cast<int>(dv->ByteLength())); |
| 2671 CHECK_EQ(0, static_cast<int>(dv->ByteOffset())); |
| 2672 } |
| 2673 |
| 2674 |
| 2669 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) { | 2675 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) { |
| 2670 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); | 2676 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); |
| 2671 CHECK_EQ(0, static_cast<int>(ta->Length())); | 2677 CHECK_EQ(0, static_cast<int>(ta->Length())); |
| 2672 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); | 2678 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); |
| 2673 } | 2679 } |
| 2674 | 2680 |
| 2681 |
| 2682 static void CheckIsTypedArrayVarNeutered(const char* name) { |
| 2683 i::ScopedVector<char> source(1024); |
| 2684 i::OS::SNPrintF(source, |
| 2685 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0", |
| 2686 name, name, name); |
| 2687 CHECK(CompileRun(source.start())->IsTrue()); |
| 2688 v8::Handle<v8::TypedArray> ta = |
| 2689 v8::Handle<v8::TypedArray>::Cast(CompileRun(name)); |
| 2690 CheckIsNeutered(ta); |
| 2691 } |
| 2692 |
| 2693 |
| 2675 template <typename TypedArray, int kElementSize> | 2694 template <typename TypedArray, int kElementSize> |
| 2676 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, | 2695 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, |
| 2677 int byteOffset, | 2696 int byteOffset, |
| 2678 int length) { | 2697 int length) { |
| 2679 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); | 2698 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); |
| 2680 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); | 2699 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); |
| 2681 CHECK_EQ(length, static_cast<int>(ta->Length())); | 2700 CHECK_EQ(length, static_cast<int>(ta->Length())); |
| 2682 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); | 2701 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); |
| 2683 return ta; | 2702 return ta; |
| 2684 } | 2703 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2706 v8::Handle<v8::Uint32Array> u32a = | 2725 v8::Handle<v8::Uint32Array> u32a = |
| 2707 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); | 2726 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); |
| 2708 v8::Handle<v8::Int32Array> i32a = | 2727 v8::Handle<v8::Int32Array> i32a = |
| 2709 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); | 2728 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); |
| 2710 | 2729 |
| 2711 v8::Handle<v8::Float32Array> f32a = | 2730 v8::Handle<v8::Float32Array> f32a = |
| 2712 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); | 2731 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); |
| 2713 v8::Handle<v8::Float64Array> f64a = | 2732 v8::Handle<v8::Float64Array> f64a = |
| 2714 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); | 2733 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); |
| 2715 | 2734 |
| 2735 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023); |
| 2736 CHECK_EQ(1, static_cast<int>(dv->ByteOffset())); |
| 2737 CHECK_EQ(1023, static_cast<int>(dv->ByteLength())); |
| 2738 |
| 2716 ScopedArrayBufferContents contents(buffer->Externalize()); | 2739 ScopedArrayBufferContents contents(buffer->Externalize()); |
| 2717 buffer->Neuter(); | 2740 buffer->Neuter(); |
| 2718 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); | 2741 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); |
| 2719 CheckIsNeutered(u8a); | 2742 CheckIsNeutered(u8a); |
| 2720 CheckIsNeutered(u8c); | 2743 CheckIsNeutered(u8c); |
| 2721 CheckIsNeutered(i8a); | 2744 CheckIsNeutered(i8a); |
| 2722 CheckIsNeutered(u16a); | 2745 CheckIsNeutered(u16a); |
| 2723 CheckIsNeutered(i16a); | 2746 CheckIsNeutered(i16a); |
| 2724 CheckIsNeutered(u32a); | 2747 CheckIsNeutered(u32a); |
| 2725 CheckIsNeutered(i32a); | 2748 CheckIsNeutered(i32a); |
| 2726 CheckIsNeutered(f32a); | 2749 CheckIsNeutered(f32a); |
| 2727 CheckIsNeutered(f64a); | 2750 CheckIsNeutered(f64a); |
| 2751 CheckDataViewIsNeutered(dv); |
| 2728 } | 2752 } |
| 2729 | 2753 |
| 2730 THREADED_TEST(ArrayBuffer_NeuteringScript) { | 2754 THREADED_TEST(ArrayBuffer_NeuteringScript) { |
| 2731 LocalContext env; | 2755 LocalContext env; |
| 2732 v8::Isolate* isolate = env->GetIsolate(); | 2756 v8::Isolate* isolate = env->GetIsolate(); |
| 2733 v8::HandleScope handle_scope(isolate); | 2757 v8::HandleScope handle_scope(isolate); |
| 2734 | 2758 |
| 2735 CompileRun( | 2759 CompileRun( |
| 2736 "var ab = new ArrayBuffer(1024);" | 2760 "var ab = new ArrayBuffer(1024);" |
| 2737 "var u8a = new Uint8Array(ab, 1, 1023);" | 2761 "var u8a = new Uint8Array(ab, 1, 1023);" |
| 2738 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" | 2762 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" |
| 2739 "var i8a = new Int8Array(ab, 1, 1023);" | 2763 "var i8a = new Int8Array(ab, 1, 1023);" |
| 2740 "var u16a = new Uint16Array(ab, 2, 511);" | 2764 "var u16a = new Uint16Array(ab, 2, 511);" |
| 2741 "var i16a = new Int16Array(ab, 2, 511);" | 2765 "var i16a = new Int16Array(ab, 2, 511);" |
| 2742 "var u32a = new Uint32Array(ab, 4, 255);" | 2766 "var u32a = new Uint32Array(ab, 4, 255);" |
| 2743 "var i32a = new Int32Array(ab, 4, 255);" | 2767 "var i32a = new Int32Array(ab, 4, 255);" |
| 2744 "var f32a = new Float32Array(ab, 4, 255);" | 2768 "var f32a = new Float32Array(ab, 4, 255);" |
| 2745 "var f64a = new Float64Array(ab, 8, 127);" | 2769 "var f64a = new Float64Array(ab, 8, 127);" |
| 2746 "var dv = new DataView(ab, 1, 1023);"); | 2770 "var dv = new DataView(ab, 1, 1023);"); |
| 2747 | 2771 |
| 2748 v8::Handle<v8::ArrayBuffer> ab = | 2772 v8::Handle<v8::ArrayBuffer> ab = |
| 2749 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 2773 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
| 2750 | 2774 |
| 2751 v8::Handle<v8::Uint8Array> u8a = | 2775 v8::Handle<v8::DataView> dv = |
| 2752 v8::Handle<v8::Uint8Array>::Cast(CompileRun("u8a")); | 2776 v8::Handle<v8::DataView>::Cast(CompileRun("dv")); |
| 2753 v8::Handle<v8::Uint8ClampedArray> u8c = | |
| 2754 v8::Handle<v8::Uint8ClampedArray>::Cast(CompileRun("u8c")); | |
| 2755 v8::Handle<v8::Int8Array> i8a = | |
| 2756 v8::Handle<v8::Int8Array>::Cast(CompileRun("i8a")); | |
| 2757 | |
| 2758 v8::Handle<v8::Uint16Array> u16a = | |
| 2759 v8::Handle<v8::Uint16Array>::Cast(CompileRun("u16a")); | |
| 2760 v8::Handle<v8::Int16Array> i16a = | |
| 2761 v8::Handle<v8::Int16Array>::Cast(CompileRun("i16a")); | |
| 2762 v8::Handle<v8::Uint32Array> u32a = | |
| 2763 v8::Handle<v8::Uint32Array>::Cast(CompileRun("u32a")); | |
| 2764 v8::Handle<v8::Int32Array> i32a = | |
| 2765 v8::Handle<v8::Int32Array>::Cast(CompileRun("i32a")); | |
| 2766 v8::Handle<v8::Float32Array> f32a = | |
| 2767 v8::Handle<v8::Float32Array>::Cast(CompileRun("f32a")); | |
| 2768 v8::Handle<v8::Float64Array> f64a = | |
| 2769 v8::Handle<v8::Float64Array>::Cast(CompileRun("f64a")); | |
| 2770 | 2777 |
| 2771 ScopedArrayBufferContents contents(ab->Externalize()); | 2778 ScopedArrayBufferContents contents(ab->Externalize()); |
| 2772 ab->Neuter(); | 2779 ab->Neuter(); |
| 2773 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); | 2780 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); |
| 2774 CheckIsNeutered(u8a); | 2781 CHECK_EQ(0, CompileRun("ab.byteLength")->Int32Value()); |
| 2775 CheckIsNeutered(u8c); | 2782 |
| 2776 CheckIsNeutered(i8a); | 2783 CheckIsTypedArrayVarNeutered("u8a"); |
| 2777 CheckIsNeutered(u16a); | 2784 CheckIsTypedArrayVarNeutered("u8c"); |
| 2778 CheckIsNeutered(i16a); | 2785 CheckIsTypedArrayVarNeutered("i8a"); |
| 2779 CheckIsNeutered(u32a); | 2786 CheckIsTypedArrayVarNeutered("u16a"); |
| 2780 CheckIsNeutered(i32a); | 2787 CheckIsTypedArrayVarNeutered("i16a"); |
| 2781 CheckIsNeutered(f32a); | 2788 CheckIsTypedArrayVarNeutered("u32a"); |
| 2782 CheckIsNeutered(f64a); | 2789 CheckIsTypedArrayVarNeutered("i32a"); |
| 2790 CheckIsTypedArrayVarNeutered("f32a"); |
| 2791 CheckIsTypedArrayVarNeutered("f64a"); |
| 2792 |
| 2783 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); | 2793 CHECK(CompileRun("dv.byteLength == 0 && dv.byteOffset == 0")->IsTrue()); |
| 2794 CheckDataViewIsNeutered(dv); |
| 2784 } | 2795 } |
| 2785 | 2796 |
| 2786 | 2797 |
| 2787 | 2798 |
| 2788 THREADED_TEST(HiddenProperties) { | 2799 THREADED_TEST(HiddenProperties) { |
| 2789 LocalContext env; | 2800 LocalContext env; |
| 2790 v8::HandleScope scope(env->GetIsolate()); | 2801 v8::HandleScope scope(env->GetIsolate()); |
| 2791 | 2802 |
| 2792 v8::Local<v8::Object> obj = v8::Object::New(); | 2803 v8::Local<v8::Object> obj = v8::Object::New(); |
| 2793 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 2804 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| (...skipping 12657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15451 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); | 15462 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); |
| 15452 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); | 15463 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); |
| 15453 } | 15464 } |
| 15454 | 15465 |
| 15455 | 15466 |
| 15456 template <typename ElementType, typename TypedArray, | 15467 template <typename ElementType, typename TypedArray, |
| 15457 class ExternalArrayClass> | 15468 class ExternalArrayClass> |
| 15458 void TypedArrayTestHelper(v8::ExternalArrayType array_type, | 15469 void TypedArrayTestHelper(v8::ExternalArrayType array_type, |
| 15459 int64_t low, int64_t high) { | 15470 int64_t low, int64_t high) { |
| 15460 const int kElementCount = 50; | 15471 const int kElementCount = 50; |
| 15461 i::FLAG_harmony_array_buffer = true; | |
| 15462 i::FLAG_harmony_typed_arrays = true; | |
| 15463 | 15472 |
| 15464 i::ScopedVector<ElementType> backing_store(kElementCount+2); | 15473 i::ScopedVector<ElementType> backing_store(kElementCount+2); |
| 15465 | 15474 |
| 15466 LocalContext env; | 15475 LocalContext env; |
| 15467 v8::Isolate* isolate = env->GetIsolate(); | 15476 v8::Isolate* isolate = env->GetIsolate(); |
| 15468 v8::HandleScope handle_scope(isolate); | 15477 v8::HandleScope handle_scope(isolate); |
| 15469 | 15478 |
| 15470 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( | 15479 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( |
| 15471 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); | 15480 backing_store.start(), (kElementCount+2)*sizeof(ElementType)); |
| 15472 Local<TypedArray> ta = | 15481 Local<TypedArray> ta = |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15536 v8::kExternalDoubleArray, -500, 500); | 15545 v8::kExternalDoubleArray, -500, 500); |
| 15537 } | 15546 } |
| 15538 | 15547 |
| 15539 | 15548 |
| 15540 THREADED_TEST(Uint8ClampedArray) { | 15549 THREADED_TEST(Uint8ClampedArray) { |
| 15541 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, i::ExternalPixelArray>( | 15550 TypedArrayTestHelper<uint8_t, v8::Uint8ClampedArray, i::ExternalPixelArray>( |
| 15542 v8::kExternalPixelArray, 0, 0xFF); | 15551 v8::kExternalPixelArray, 0, 0xFF); |
| 15543 } | 15552 } |
| 15544 | 15553 |
| 15545 | 15554 |
| 15546 #define IS_TYPED_ARRAY_TEST(TypedArray) \ | 15555 THREADED_TEST(DataView) { |
| 15547 THREADED_TEST(Is##TypedArray) { \ | 15556 const int kSize = 50; |
| 15557 |
| 15558 i::ScopedVector<uint8_t> backing_store(kSize+2); |
| 15559 |
| 15560 LocalContext env; |
| 15561 v8::Isolate* isolate = env->GetIsolate(); |
| 15562 v8::HandleScope handle_scope(isolate); |
| 15563 |
| 15564 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New( |
| 15565 backing_store.start(), 2 + kSize); |
| 15566 Local<v8::DataView> dv = |
| 15567 v8::DataView::New(ab, 2, kSize); |
| 15568 CHECK_EQ(2, static_cast<int>(dv->ByteOffset())); |
| 15569 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); |
| 15570 CHECK_EQ(ab, dv->Buffer()); |
| 15571 } |
| 15572 |
| 15573 |
| 15574 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ |
| 15575 THREADED_TEST(Is##View) { \ |
| 15548 i::FLAG_harmony_array_buffer = true; \ | 15576 i::FLAG_harmony_array_buffer = true; \ |
| 15549 i::FLAG_harmony_typed_arrays = true; \ | 15577 i::FLAG_harmony_typed_arrays = true; \ |
| 15550 LocalContext env; \ | 15578 LocalContext env; \ |
| 15551 v8::Isolate* isolate = env->GetIsolate(); \ | 15579 v8::Isolate* isolate = env->GetIsolate(); \ |
| 15552 v8::HandleScope handle_scope(isolate); \ | 15580 v8::HandleScope handle_scope(isolate); \ |
| 15553 \ | 15581 \ |
| 15554 Handle<Value> result = CompileRun( \ | 15582 Handle<Value> result = CompileRun( \ |
| 15555 "var ab = new ArrayBuffer(128);" \ | 15583 "var ab = new ArrayBuffer(128);" \ |
| 15556 "new " #TypedArray "(ab)"); \ | 15584 "new " #View "(ab)"); \ |
| 15557 CHECK(result->Is##TypedArray()); \ | 15585 CHECK(result->IsArrayBufferView()); \ |
| 15586 CHECK(result->Is##View()); \ |
| 15558 } | 15587 } |
| 15559 | 15588 |
| 15560 IS_TYPED_ARRAY_TEST(Uint8Array) | 15589 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array) |
| 15561 IS_TYPED_ARRAY_TEST(Int8Array) | 15590 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array) |
| 15562 IS_TYPED_ARRAY_TEST(Uint16Array) | 15591 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array) |
| 15563 IS_TYPED_ARRAY_TEST(Int16Array) | 15592 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array) |
| 15564 IS_TYPED_ARRAY_TEST(Uint32Array) | 15593 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array) |
| 15565 IS_TYPED_ARRAY_TEST(Int32Array) | 15594 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array) |
| 15566 IS_TYPED_ARRAY_TEST(Float32Array) | 15595 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array) |
| 15567 IS_TYPED_ARRAY_TEST(Float64Array) | 15596 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array) |
| 15568 IS_TYPED_ARRAY_TEST(Uint8ClampedArray) | 15597 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray) |
| 15598 IS_ARRAY_BUFFER_VIEW_TEST(DataView) |
| 15569 | 15599 |
| 15570 #undef IS_TYPED_ARRAY_TEST | 15600 #undef IS_ARRAY_BUFFER_VIEW_TEST |
| 15571 | 15601 |
| 15572 | 15602 |
| 15573 | 15603 |
| 15574 THREADED_TEST(ScriptContextDependence) { | 15604 THREADED_TEST(ScriptContextDependence) { |
| 15575 LocalContext c1; | 15605 LocalContext c1; |
| 15576 v8::HandleScope scope(c1->GetIsolate()); | 15606 v8::HandleScope scope(c1->GetIsolate()); |
| 15577 const char *source = "foo"; | 15607 const char *source = "foo"; |
| 15578 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); | 15608 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); |
| 15579 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); | 15609 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); |
| 15580 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); | 15610 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); |
| (...skipping 3770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19351 i::Semaphore* sem_; | 19381 i::Semaphore* sem_; |
| 19352 volatile int sem_value_; | 19382 volatile int sem_value_; |
| 19353 }; | 19383 }; |
| 19354 | 19384 |
| 19355 | 19385 |
| 19356 THREADED_TEST(SemaphoreInterruption) { | 19386 THREADED_TEST(SemaphoreInterruption) { |
| 19357 ThreadInterruptTest().RunTest(); | 19387 ThreadInterruptTest().RunTest(); |
| 19358 } | 19388 } |
| 19359 | 19389 |
| 19360 #endif // WIN32 | 19390 #endif // WIN32 |
| OLD | NEW |