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 2612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2623 | 2623 |
2624 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { | 2624 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { |
2625 i::FLAG_harmony_array_buffer = true; | 2625 i::FLAG_harmony_array_buffer = true; |
2626 i::FLAG_harmony_typed_arrays = true; | 2626 i::FLAG_harmony_typed_arrays = true; |
2627 | 2627 |
2628 LocalContext env; | 2628 LocalContext env; |
2629 v8::Isolate* isolate = env->GetIsolate(); | 2629 v8::Isolate* isolate = env->GetIsolate(); |
2630 v8::HandleScope handle_scope(isolate); | 2630 v8::HandleScope handle_scope(isolate); |
2631 | 2631 |
2632 | 2632 |
2633 v8::Handle<v8::Value> result = | 2633 v8::Local<v8::Value> result = |
2634 CompileRun("var ab1 = new ArrayBuffer(2);" | 2634 CompileRun("var ab1 = new ArrayBuffer(2);" |
2635 "var u8_a = new Uint8Array(ab1);" | 2635 "var u8_a = new Uint8Array(ab1);" |
2636 "u8_a[0] = 0xAA;" | 2636 "u8_a[0] = 0xAA;" |
2637 "u8_a[1] = 0xFF; u8_a.buffer"); | 2637 "u8_a[1] = 0xFF; u8_a.buffer"); |
2638 Local<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::Cast(*result); | 2638 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); |
2639 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); | 2639 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
2640 CHECK(!ab1->IsExternal()); | 2640 CHECK(!ab1->IsExternal()); |
2641 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); | 2641 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); |
2642 CHECK(ab1->IsExternal()); | 2642 CHECK(ab1->IsExternal()); |
2643 | 2643 |
2644 result = CompileRun("ab1.byteLength"); | 2644 result = CompileRun("ab1.byteLength"); |
2645 CHECK_EQ(2, result->Int32Value()); | 2645 CHECK_EQ(2, result->Int32Value()); |
2646 result = CompileRun("u8_a[0]"); | 2646 result = CompileRun("u8_a[0]"); |
2647 CHECK_EQ(0xAA, result->Int32Value()); | 2647 CHECK_EQ(0xAA, result->Int32Value()); |
2648 result = CompileRun("u8_a[1]"); | 2648 result = CompileRun("u8_a[1]"); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2769 "var u8a = new Uint8Array(ab, 1, 1023);" | 2769 "var u8a = new Uint8Array(ab, 1, 1023);" |
2770 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" | 2770 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" |
2771 "var i8a = new Int8Array(ab, 1, 1023);" | 2771 "var i8a = new Int8Array(ab, 1, 1023);" |
2772 "var u16a = new Uint16Array(ab, 2, 511);" | 2772 "var u16a = new Uint16Array(ab, 2, 511);" |
2773 "var i16a = new Int16Array(ab, 2, 511);" | 2773 "var i16a = new Int16Array(ab, 2, 511);" |
2774 "var u32a = new Uint32Array(ab, 4, 255);" | 2774 "var u32a = new Uint32Array(ab, 4, 255);" |
2775 "var i32a = new Int32Array(ab, 4, 255);" | 2775 "var i32a = new Int32Array(ab, 4, 255);" |
2776 "var f32a = new Float32Array(ab, 4, 255);" | 2776 "var f32a = new Float32Array(ab, 4, 255);" |
2777 "var f64a = new Float64Array(ab, 8, 127);"); | 2777 "var f64a = new Float64Array(ab, 8, 127);"); |
2778 | 2778 |
2779 v8::Handle<v8::ArrayBuffer> ab(v8::ArrayBuffer::Cast(*CompileRun("ab"))); | 2779 v8::Handle<v8::ArrayBuffer> ab = |
| 2780 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
2780 | 2781 |
2781 v8::Handle<v8::Uint8Array> u8a(v8::Uint8Array::Cast(*CompileRun("u8a"))); | 2782 v8::Handle<v8::Uint8Array> u8a = |
2782 v8::Handle<v8::Uint8ClampedArray> u8c( | 2783 v8::Handle<v8::Uint8Array>::Cast(CompileRun("u8a")); |
2783 v8::Uint8ClampedArray::Cast(*CompileRun("u8c"))); | 2784 v8::Handle<v8::Uint8ClampedArray> u8c = |
2784 v8::Handle<v8::Int8Array> i8a(v8::Int8Array::Cast(*CompileRun("i8a"))); | 2785 v8::Handle<v8::Uint8ClampedArray>::Cast(CompileRun("u8c")); |
| 2786 v8::Handle<v8::Int8Array> i8a = |
| 2787 v8::Handle<v8::Int8Array>::Cast(CompileRun("i8a")); |
2785 | 2788 |
2786 v8::Handle<v8::Uint16Array> u16a( | 2789 v8::Handle<v8::Uint16Array> u16a = |
2787 v8::Uint16Array::Cast(*CompileRun("u16a"))); | 2790 v8::Handle<v8::Uint16Array>::Cast(CompileRun("u16a")); |
2788 v8::Handle<v8::Int16Array> i16a( | 2791 v8::Handle<v8::Int16Array> i16a = |
2789 v8::Int16Array::Cast(*CompileRun("i16a"))); | 2792 v8::Handle<v8::Int16Array>::Cast(CompileRun("i16a")); |
2790 v8::Handle<v8::Uint32Array> u32a( | 2793 v8::Handle<v8::Uint32Array> u32a = |
2791 v8::Uint32Array::Cast(*CompileRun("u32a"))); | 2794 v8::Handle<v8::Uint32Array>::Cast(CompileRun("u32a")); |
2792 v8::Handle<v8::Int32Array> i32a( | 2795 v8::Handle<v8::Int32Array> i32a = |
2793 v8::Int32Array::Cast(*CompileRun("i32a"))); | 2796 v8::Handle<v8::Int32Array>::Cast(CompileRun("i32a")); |
2794 v8::Handle<v8::Float32Array> f32a( | 2797 v8::Handle<v8::Float32Array> f32a = |
2795 v8::Float32Array::Cast(*CompileRun("f32a"))); | 2798 v8::Handle<v8::Float32Array>::Cast(CompileRun("f32a")); |
2796 v8::Handle<v8::Float64Array> f64a( | 2799 v8::Handle<v8::Float64Array> f64a = |
2797 v8::Float64Array::Cast(*CompileRun("f64a"))); | 2800 v8::Handle<v8::Float64Array>::Cast(CompileRun("f64a")); |
2798 | 2801 |
2799 ScopedArrayBufferContents contents(ab->Externalize()); | 2802 ScopedArrayBufferContents contents(ab->Externalize()); |
2800 ab->Neuter(); | 2803 ab->Neuter(); |
2801 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); | 2804 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); |
2802 CheckIsNeutered(u8a); | 2805 CheckIsNeutered(u8a); |
2803 CheckIsNeutered(u8c); | 2806 CheckIsNeutered(u8c); |
2804 CheckIsNeutered(i8a); | 2807 CheckIsNeutered(i8a); |
2805 CheckIsNeutered(u16a); | 2808 CheckIsNeutered(u16a); |
2806 CheckIsNeutered(i16a); | 2809 CheckIsNeutered(i16a); |
2807 CheckIsNeutered(u32a); | 2810 CheckIsNeutered(u32a); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3095 | 3098 |
3096 static void WeakPointerCallback(v8::Isolate* isolate, | 3099 static void WeakPointerCallback(v8::Isolate* isolate, |
3097 Persistent<Value>* handle, | 3100 Persistent<Value>* handle, |
3098 WeakCallCounter* counter) { | 3101 WeakCallCounter* counter) { |
3099 CHECK_EQ(1234, counter->id()); | 3102 CHECK_EQ(1234, counter->id()); |
3100 counter->increment(); | 3103 counter->increment(); |
3101 handle->Dispose(isolate); | 3104 handle->Dispose(isolate); |
3102 } | 3105 } |
3103 | 3106 |
3104 | 3107 |
| 3108 static UniqueId MakeUniqueId(const Persistent<Value>& p) { |
| 3109 return UniqueId(reinterpret_cast<uintptr_t>(*v8::Utils::OpenPersistent(p))); |
| 3110 } |
| 3111 |
| 3112 |
3105 THREADED_TEST(ApiObjectGroups) { | 3113 THREADED_TEST(ApiObjectGroups) { |
3106 LocalContext env; | 3114 LocalContext env; |
3107 v8::Isolate* iso = env->GetIsolate(); | 3115 v8::Isolate* iso = env->GetIsolate(); |
3108 HandleScope scope(iso); | 3116 HandleScope scope(iso); |
3109 | 3117 |
3110 Persistent<Value> g1s1; | 3118 Persistent<Value> g1s1; |
3111 Persistent<Value> g1s2; | 3119 Persistent<Value> g1s2; |
3112 Persistent<Value> g1c1; | 3120 Persistent<Value> g1c1; |
3113 Persistent<Value> g2s1; | 3121 Persistent<Value> g2s1; |
3114 Persistent<Value> g2s2; | 3122 Persistent<Value> g2s2; |
(...skipping 17 matching lines...) Expand all Loading... |
3132 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); | 3140 g2s2.MakeWeak(iso, &counter, &WeakPointerCallback); |
3133 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); | 3141 g2c1.MakeWeak(iso, &counter, &WeakPointerCallback); |
3134 } | 3142 } |
3135 | 3143 |
3136 Persistent<Value> root(iso, g1s1); // make a root. | 3144 Persistent<Value> root(iso, g1s1); // make a root. |
3137 | 3145 |
3138 // Connect group 1 and 2, make a cycle. | 3146 // Connect group 1 and 2, make a cycle. |
3139 { | 3147 { |
3140 HandleScope scope(iso); | 3148 HandleScope scope(iso); |
3141 CHECK(Local<Object>::New(iso, g1s2.As<Object>())-> | 3149 CHECK(Local<Object>::New(iso, g1s2.As<Object>())-> |
3142 Set(0, Local<Value>(*g2s2))); | 3150 Set(0, Local<Value>::New(iso, g2s2))); |
3143 CHECK(Local<Object>::New(iso, g2s1.As<Object>())-> | 3151 CHECK(Local<Object>::New(iso, g2s1.As<Object>())-> |
3144 Set(0, Local<Value>(*g1s1))); | 3152 Set(0, Local<Value>::New(iso, g1s1))); |
3145 } | 3153 } |
3146 | 3154 |
3147 { | 3155 { |
3148 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3156 UniqueId id1 = MakeUniqueId(g1s1); |
3149 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); | 3157 UniqueId id2 = MakeUniqueId(g2s2); |
3150 iso->SetObjectGroupId(g1s1, id1); | 3158 iso->SetObjectGroupId(g1s1, id1); |
3151 iso->SetObjectGroupId(g1s2, id1); | 3159 iso->SetObjectGroupId(g1s2, id1); |
3152 iso->SetReferenceFromGroup(id1, g1c1); | 3160 iso->SetReferenceFromGroup(id1, g1c1); |
3153 iso->SetObjectGroupId(g2s1, id2); | 3161 iso->SetObjectGroupId(g2s1, id2); |
3154 iso->SetObjectGroupId(g2s2, id2); | 3162 iso->SetObjectGroupId(g2s2, id2); |
3155 iso->SetReferenceFromGroup(id2, g2c1); | 3163 iso->SetReferenceFromGroup(id2, g2c1); |
3156 } | 3164 } |
3157 // Do a single full GC, ensure incremental marking is stopped. | 3165 // Do a single full GC, ensure incremental marking is stopped. |
3158 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3166 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
3159 iso)->heap(); | 3167 iso)->heap(); |
3160 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3168 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
3161 | 3169 |
3162 // All object should be alive. | 3170 // All object should be alive. |
3163 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3171 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
3164 | 3172 |
3165 // Weaken the root. | 3173 // Weaken the root. |
3166 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3174 root.MakeWeak(iso, &counter, &WeakPointerCallback); |
3167 // But make children strong roots---all the objects (except for children) | 3175 // But make children strong roots---all the objects (except for children) |
3168 // should be collectable now. | 3176 // should be collectable now. |
3169 g1c1.ClearWeak(iso); | 3177 g1c1.ClearWeak(iso); |
3170 g2c1.ClearWeak(iso); | 3178 g2c1.ClearWeak(iso); |
3171 | 3179 |
3172 // Groups are deleted, rebuild groups. | 3180 // Groups are deleted, rebuild groups. |
3173 { | 3181 { |
3174 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3182 UniqueId id1 = MakeUniqueId(g1s1); |
3175 UniqueId id2(reinterpret_cast<intptr_t>(*g2s2)); | 3183 UniqueId id2 = MakeUniqueId(g2s2); |
3176 iso->SetObjectGroupId(g1s1, id1); | 3184 iso->SetObjectGroupId(g1s1, id1); |
3177 iso->SetObjectGroupId(g1s2, id1); | 3185 iso->SetObjectGroupId(g1s2, id1); |
3178 iso->SetReferenceFromGroup(id1, g1c1); | 3186 iso->SetReferenceFromGroup(id1, g1c1); |
3179 iso->SetObjectGroupId(g2s1, id2); | 3187 iso->SetObjectGroupId(g2s1, id2); |
3180 iso->SetObjectGroupId(g2s2, id2); | 3188 iso->SetObjectGroupId(g2s2, id2); |
3181 iso->SetReferenceFromGroup(id2, g2c1); | 3189 iso->SetReferenceFromGroup(id2, g2c1); |
3182 } | 3190 } |
3183 | 3191 |
3184 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3192 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
3185 | 3193 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3241 CHECK(g4s1.IsWeak(iso)); | 3249 CHECK(g4s1.IsWeak(iso)); |
3242 CHECK(g4s2.IsWeak(iso)); | 3250 CHECK(g4s2.IsWeak(iso)); |
3243 } | 3251 } |
3244 | 3252 |
3245 Persistent<Value> root(iso, g1s1); // make a root. | 3253 Persistent<Value> root(iso, g1s1); // make a root. |
3246 | 3254 |
3247 // Connect groups. We're building the following cycle: | 3255 // Connect groups. We're building the following cycle: |
3248 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other | 3256 // G1: { g1s1, g2s1 }, g1s1 implicitly references g2s1, ditto for other |
3249 // groups. | 3257 // groups. |
3250 { | 3258 { |
3251 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3259 UniqueId id1 = MakeUniqueId(g1s1); |
3252 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); | 3260 UniqueId id2 = MakeUniqueId(g2s1); |
3253 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); | 3261 UniqueId id3 = MakeUniqueId(g3s1); |
3254 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); | 3262 UniqueId id4 = MakeUniqueId(g4s1); |
3255 iso->SetObjectGroupId(g1s1, id1); | 3263 iso->SetObjectGroupId(g1s1, id1); |
3256 iso->SetObjectGroupId(g1s2, id1); | 3264 iso->SetObjectGroupId(g1s2, id1); |
3257 iso->SetReferenceFromGroup(id1, g2s1); | 3265 iso->SetReferenceFromGroup(id1, g2s1); |
3258 iso->SetObjectGroupId(g2s1, id2); | 3266 iso->SetObjectGroupId(g2s1, id2); |
3259 iso->SetObjectGroupId(g2s2, id2); | 3267 iso->SetObjectGroupId(g2s2, id2); |
3260 iso->SetReferenceFromGroup(id2, g3s1); | 3268 iso->SetReferenceFromGroup(id2, g3s1); |
3261 iso->SetObjectGroupId(g3s1, id3); | 3269 iso->SetObjectGroupId(g3s1, id3); |
3262 iso->SetObjectGroupId(g3s2, id3); | 3270 iso->SetObjectGroupId(g3s2, id3); |
3263 iso->SetReferenceFromGroup(id3, g4s1); | 3271 iso->SetReferenceFromGroup(id3, g4s1); |
3264 iso->SetObjectGroupId(g4s1, id4); | 3272 iso->SetObjectGroupId(g4s1, id4); |
3265 iso->SetObjectGroupId(g4s2, id4); | 3273 iso->SetObjectGroupId(g4s2, id4); |
3266 iso->SetReferenceFromGroup(id4, g1s1); | 3274 iso->SetReferenceFromGroup(id4, g1s1); |
3267 } | 3275 } |
3268 // Do a single full GC | 3276 // Do a single full GC |
3269 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3277 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
3270 iso)->heap(); | 3278 iso)->heap(); |
3271 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); | 3279 heap->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); |
3272 | 3280 |
3273 // All object should be alive. | 3281 // All object should be alive. |
3274 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3282 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
3275 | 3283 |
3276 // Weaken the root. | 3284 // Weaken the root. |
3277 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3285 root.MakeWeak(iso, &counter, &WeakPointerCallback); |
3278 | 3286 |
3279 // Groups are deleted, rebuild groups. | 3287 // Groups are deleted, rebuild groups. |
3280 { | 3288 { |
3281 UniqueId id1(reinterpret_cast<intptr_t>(*g1s1)); | 3289 UniqueId id1 = MakeUniqueId(g1s1); |
3282 UniqueId id2(reinterpret_cast<intptr_t>(*g2s1)); | 3290 UniqueId id2 = MakeUniqueId(g2s1); |
3283 UniqueId id3(reinterpret_cast<intptr_t>(*g3s1)); | 3291 UniqueId id3 = MakeUniqueId(g3s1); |
3284 UniqueId id4(reinterpret_cast<intptr_t>(*g4s1)); | 3292 UniqueId id4 = MakeUniqueId(g4s1); |
3285 iso->SetObjectGroupId(g1s1, id1); | 3293 iso->SetObjectGroupId(g1s1, id1); |
3286 iso->SetObjectGroupId(g1s2, id1); | 3294 iso->SetObjectGroupId(g1s2, id1); |
3287 iso->SetReferenceFromGroup(id1, g2s1); | 3295 iso->SetReferenceFromGroup(id1, g2s1); |
3288 iso->SetObjectGroupId(g2s1, id2); | 3296 iso->SetObjectGroupId(g2s1, id2); |
3289 iso->SetObjectGroupId(g2s2, id2); | 3297 iso->SetObjectGroupId(g2s2, id2); |
3290 iso->SetReferenceFromGroup(id2, g3s1); | 3298 iso->SetReferenceFromGroup(id2, g3s1); |
3291 iso->SetObjectGroupId(g3s1, id3); | 3299 iso->SetObjectGroupId(g3s1, id3); |
3292 iso->SetObjectGroupId(g3s2, id3); | 3300 iso->SetObjectGroupId(g3s2, id3); |
3293 iso->SetReferenceFromGroup(id3, g4s1); | 3301 iso->SetReferenceFromGroup(id3, g4s1); |
3294 iso->SetObjectGroupId(g4s1, id4); | 3302 iso->SetObjectGroupId(g4s1, id4); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3349 { | 3357 { |
3350 HandleScope handle_scope(iso); | 3358 HandleScope handle_scope(iso); |
3351 g1s1.MarkPartiallyDependent(iso); | 3359 g1s1.MarkPartiallyDependent(iso); |
3352 g1s2.MarkPartiallyDependent(iso); | 3360 g1s2.MarkPartiallyDependent(iso); |
3353 g2s1.MarkPartiallyDependent(iso); | 3361 g2s1.MarkPartiallyDependent(iso); |
3354 g2s2.MarkPartiallyDependent(iso); | 3362 g2s2.MarkPartiallyDependent(iso); |
3355 g3s1.MarkPartiallyDependent(iso); | 3363 g3s1.MarkPartiallyDependent(iso); |
3356 g3s2.MarkPartiallyDependent(iso); | 3364 g3s2.MarkPartiallyDependent(iso); |
3357 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3365 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
3358 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3366 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
3359 Local<Object>::New(iso, g1s1.As<Object>())->Set(v8_str("x"), | 3367 Local<Object>::New(iso, g1s1.As<Object>())->Set( |
3360 Local<Value>(*g2s1)); | 3368 v8_str("x"), Local<Value>::New(iso, g2s1)); |
3361 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3369 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
3362 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3370 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
3363 Local<Object>::New(iso, g2s1.As<Object>())->Set(v8_str("x"), | 3371 Local<Object>::New(iso, g2s1.As<Object>())->Set( |
3364 Local<Value>(*g3s1)); | 3372 v8_str("x"), Local<Value>::New(iso, g3s1)); |
3365 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3373 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
3366 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3374 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
3367 Local<Object>::New(iso, g3s1.As<Object>())->Set(v8_str("x"), | 3375 Local<Object>::New(iso, g3s1.As<Object>())->Set( |
3368 Local<Value>(*g1s1)); | 3376 v8_str("x"), Local<Value>::New(iso, g1s1)); |
3369 } | 3377 } |
3370 | 3378 |
3371 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( | 3379 v8::internal::Heap* heap = reinterpret_cast<v8::internal::Isolate*>( |
3372 iso)->heap(); | 3380 iso)->heap(); |
3373 heap->CollectGarbage(i::NEW_SPACE); | 3381 heap->CollectGarbage(i::NEW_SPACE); |
3374 | 3382 |
3375 // All objects should be alive. | 3383 // All objects should be alive. |
3376 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 3384 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
3377 | 3385 |
3378 // Weaken the root. | 3386 // Weaken the root. |
3379 root.MakeWeak(iso, &counter, &WeakPointerCallback); | 3387 root.MakeWeak(iso, &counter, &WeakPointerCallback); |
3380 root.MarkPartiallyDependent(iso); | 3388 root.MarkPartiallyDependent(iso); |
3381 | 3389 |
3382 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3390 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
3383 // Groups are deleted, rebuild groups. | 3391 // Groups are deleted, rebuild groups. |
3384 { | 3392 { |
3385 HandleScope handle_scope(iso); | 3393 HandleScope handle_scope(iso); |
3386 g1s1.MarkPartiallyDependent(isolate); | 3394 g1s1.MarkPartiallyDependent(isolate); |
3387 g1s2.MarkPartiallyDependent(isolate); | 3395 g1s2.MarkPartiallyDependent(isolate); |
3388 g2s1.MarkPartiallyDependent(isolate); | 3396 g2s1.MarkPartiallyDependent(isolate); |
3389 g2s2.MarkPartiallyDependent(isolate); | 3397 g2s2.MarkPartiallyDependent(isolate); |
3390 g3s1.MarkPartiallyDependent(isolate); | 3398 g3s1.MarkPartiallyDependent(isolate); |
3391 g3s2.MarkPartiallyDependent(isolate); | 3399 g3s2.MarkPartiallyDependent(isolate); |
3392 iso->SetObjectGroupId(g1s1, UniqueId(1)); | 3400 iso->SetObjectGroupId(g1s1, UniqueId(1)); |
3393 iso->SetObjectGroupId(g1s2, UniqueId(1)); | 3401 iso->SetObjectGroupId(g1s2, UniqueId(1)); |
3394 Local<Object>::New(iso, g1s1.As<Object>())->Set(v8_str("x"), | 3402 Local<Object>::New(iso, g1s1.As<Object>())->Set( |
3395 Local<Value>(*g2s1)); | 3403 v8_str("x"), Local<Value>::New(iso, g2s1)); |
3396 iso->SetObjectGroupId(g2s1, UniqueId(2)); | 3404 iso->SetObjectGroupId(g2s1, UniqueId(2)); |
3397 iso->SetObjectGroupId(g2s2, UniqueId(2)); | 3405 iso->SetObjectGroupId(g2s2, UniqueId(2)); |
3398 Local<Object>::New(iso, g2s1.As<Object>())->Set(v8_str("x"), | 3406 Local<Object>::New(iso, g2s1.As<Object>())->Set( |
3399 Local<Value>(*g3s1)); | 3407 v8_str("x"), Local<Value>::New(iso, g3s1)); |
3400 iso->SetObjectGroupId(g3s1, UniqueId(3)); | 3408 iso->SetObjectGroupId(g3s1, UniqueId(3)); |
3401 iso->SetObjectGroupId(g3s2, UniqueId(3)); | 3409 iso->SetObjectGroupId(g3s2, UniqueId(3)); |
3402 Local<Object>::New(iso, g3s1.As<Object>())->Set(v8_str("x"), | 3410 Local<Object>::New(iso, g3s1.As<Object>())->Set( |
3403 Local<Value>(*g1s1)); | 3411 v8_str("x"), Local<Value>::New(iso, g1s1)); |
3404 } | 3412 } |
3405 | 3413 |
3406 heap->CollectGarbage(i::NEW_SPACE); | 3414 heap->CollectGarbage(i::NEW_SPACE); |
3407 | 3415 |
3408 // All objects should be gone. 7 global handles in total. | 3416 // All objects should be gone. 7 global handles in total. |
3409 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 3417 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
3410 } | 3418 } |
3411 | 3419 |
3412 | 3420 |
3413 THREADED_TEST(ScriptException) { | 3421 THREADED_TEST(ScriptException) { |
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4846 THREADED_TEST(SimplePropertyWrite) { | 4854 THREADED_TEST(SimplePropertyWrite) { |
4847 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4855 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4848 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4856 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4849 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 4857 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
4850 LocalContext context; | 4858 LocalContext context; |
4851 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4859 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
4852 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); | 4860 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); |
4853 for (int i = 0; i < 10; i++) { | 4861 for (int i = 0; i < 10; i++) { |
4854 CHECK(xValue.IsEmpty()); | 4862 CHECK(xValue.IsEmpty()); |
4855 script->Run(); | 4863 script->Run(); |
4856 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); | 4864 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); |
4857 xValue.Dispose(context->GetIsolate()); | 4865 xValue.Dispose(context->GetIsolate()); |
4858 xValue.Clear(); | 4866 xValue.Clear(); |
4859 } | 4867 } |
4860 } | 4868 } |
4861 | 4869 |
4862 | 4870 |
4863 THREADED_TEST(SetterOnly) { | 4871 THREADED_TEST(SetterOnly) { |
4864 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4872 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4865 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4873 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4866 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 4874 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
4867 LocalContext context; | 4875 LocalContext context; |
4868 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 4876 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
4869 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); | 4877 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); |
4870 for (int i = 0; i < 10; i++) { | 4878 for (int i = 0; i < 10; i++) { |
4871 CHECK(xValue.IsEmpty()); | 4879 CHECK(xValue.IsEmpty()); |
4872 script->Run(); | 4880 script->Run(); |
4873 CHECK_EQ(v8_num(4), Handle<Value>(*xValue)); | 4881 CHECK_EQ(v8_num(4), Local<Value>::New(v8::Isolate::GetCurrent(), xValue)); |
4874 xValue.Dispose(context->GetIsolate()); | 4882 xValue.Dispose(context->GetIsolate()); |
4875 xValue.Clear(); | 4883 xValue.Clear(); |
4876 } | 4884 } |
4877 } | 4885 } |
4878 | 4886 |
4879 | 4887 |
4880 THREADED_TEST(NoAccessors) { | 4888 THREADED_TEST(NoAccessors) { |
4881 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 4889 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
4882 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 4890 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
4883 templ->SetAccessor(v8_str("x"), | 4891 templ->SetAccessor(v8_str("x"), |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5088 | 5096 |
5089 | 5097 |
5090 Handle<v8::Array> UnboxedDoubleIndexedPropertyEnumerator( | 5098 Handle<v8::Array> UnboxedDoubleIndexedPropertyEnumerator( |
5091 const AccessorInfo& info) { | 5099 const AccessorInfo& info) { |
5092 // Force the list of returned keys to be stored in a FastDoubleArray. | 5100 // Force the list of returned keys to be stored in a FastDoubleArray. |
5093 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 5101 Local<Script> indexed_property_names_script = Script::Compile(v8_str( |
5094 "keys = new Array(); keys[125000] = 1;" | 5102 "keys = new Array(); keys[125000] = 1;" |
5095 "for(i = 0; i < 80000; i++) { keys[i] = i; };" | 5103 "for(i = 0; i < 80000; i++) { keys[i] = i; };" |
5096 "keys.length = 25; keys;")); | 5104 "keys.length = 25; keys;")); |
5097 Local<Value> result = indexed_property_names_script->Run(); | 5105 Local<Value> result = indexed_property_names_script->Run(); |
5098 return Local<v8::Array>(::v8::Array::Cast(*result)); | 5106 return Local<v8::Array>::Cast(result); |
5099 } | 5107 } |
5100 | 5108 |
5101 | 5109 |
5102 // Make sure that the the interceptor code in the runtime properly handles | 5110 // Make sure that the the interceptor code in the runtime properly handles |
5103 // merging property name lists for double-array-backed arrays. | 5111 // merging property name lists for double-array-backed arrays. |
5104 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { | 5112 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { |
5105 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 5113 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
5106 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5114 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
5107 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, | 5115 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, |
5108 UnboxedDoubleIndexedPropertySetter, | 5116 UnboxedDoubleIndexedPropertySetter, |
(...skipping 19 matching lines...) Expand all Loading... |
5128 | 5136 |
5129 Handle<v8::Array> NonStrictArgsIndexedPropertyEnumerator( | 5137 Handle<v8::Array> NonStrictArgsIndexedPropertyEnumerator( |
5130 const AccessorInfo& info) { | 5138 const AccessorInfo& info) { |
5131 // Force the list of returned keys to be stored in a Arguments object. | 5139 // Force the list of returned keys to be stored in a Arguments object. |
5132 Local<Script> indexed_property_names_script = Script::Compile(v8_str( | 5140 Local<Script> indexed_property_names_script = Script::Compile(v8_str( |
5133 "function f(w,x) {" | 5141 "function f(w,x) {" |
5134 " return arguments;" | 5142 " return arguments;" |
5135 "}" | 5143 "}" |
5136 "keys = f(0, 1, 2, 3);" | 5144 "keys = f(0, 1, 2, 3);" |
5137 "keys;")); | 5145 "keys;")); |
5138 Local<Value> result = indexed_property_names_script->Run(); | 5146 Local<Object> result = |
5139 return Local<v8::Array>(static_cast<v8::Array*>(::v8::Object::Cast(*result))); | 5147 Local<Object>::Cast(indexed_property_names_script->Run()); |
| 5148 return *reinterpret_cast<Local<v8::Array>*>(&result); |
5140 } | 5149 } |
5141 | 5150 |
5142 | 5151 |
5143 static v8::Handle<Value> NonStrictIndexedPropertyGetter( | 5152 static v8::Handle<Value> NonStrictIndexedPropertyGetter( |
5144 uint32_t index, | 5153 uint32_t index, |
5145 const AccessorInfo& info) { | 5154 const AccessorInfo& info) { |
5146 ApiTestFuzzer::Fuzz(); | 5155 ApiTestFuzzer::Fuzz(); |
5147 if (index < 4) { | 5156 if (index < 4) { |
5148 return v8::Handle<Value>(v8_num(index)); | 5157 return v8::Handle<Value>(v8_num(index)); |
5149 } | 5158 } |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6240 Snorkel() { index_ = global_index++; } | 6249 Snorkel() { index_ = global_index++; } |
6241 int index_; | 6250 int index_; |
6242 }; | 6251 }; |
6243 | 6252 |
6244 class Whammy { | 6253 class Whammy { |
6245 public: | 6254 public: |
6246 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } | 6255 explicit Whammy(v8::Isolate* isolate) : cursor_(0), isolate_(isolate) { } |
6247 ~Whammy() { script_.Dispose(isolate_); } | 6256 ~Whammy() { script_.Dispose(isolate_); } |
6248 v8::Handle<Script> getScript() { | 6257 v8::Handle<Script> getScript() { |
6249 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); | 6258 if (script_.IsEmpty()) script_.Reset(isolate_, v8_compile("({}).blammo")); |
6250 return Local<Script>(*script_); | 6259 return Local<Script>::New(isolate_, script_); |
6251 } | 6260 } |
6252 | 6261 |
6253 public: | 6262 public: |
6254 static const int kObjectCount = 256; | 6263 static const int kObjectCount = 256; |
6255 int cursor_; | 6264 int cursor_; |
6256 v8::Isolate* isolate_; | 6265 v8::Isolate* isolate_; |
6257 v8::Persistent<v8::Object> objects_[kObjectCount]; | 6266 v8::Persistent<v8::Object> objects_[kObjectCount]; |
6258 v8::Persistent<Script> script_; | 6267 v8::Persistent<Script> script_; |
6259 }; | 6268 }; |
6260 | 6269 |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7204 Handle<String> sym2 = v8::String::NewSymbol("\360\220\220\210"); | 7213 Handle<String> sym2 = v8::String::NewSymbol("\360\220\220\210"); |
7205 Handle<String> sym3 = v8::String::NewSymbol("x\355\240\201\355\260\207"); | 7214 Handle<String> sym3 = v8::String::NewSymbol("x\355\240\201\355\260\207"); |
7206 Handle<String> sym4 = v8::String::NewSymbol("x\360\220\220\210"); | 7215 Handle<String> sym4 = v8::String::NewSymbol("x\360\220\220\210"); |
7207 v8::Local<v8::Object> global = context->Global(); | 7216 v8::Local<v8::Object> global = context->Global(); |
7208 Local<Value> s0 = global->Get(v8_str("sym0")); | 7217 Local<Value> s0 = global->Get(v8_str("sym0")); |
7209 Local<Value> s0b = global->Get(v8_str("sym0b")); | 7218 Local<Value> s0b = global->Get(v8_str("sym0b")); |
7210 Local<Value> s1 = global->Get(v8_str("sym1")); | 7219 Local<Value> s1 = global->Get(v8_str("sym1")); |
7211 Local<Value> s2 = global->Get(v8_str("sym2")); | 7220 Local<Value> s2 = global->Get(v8_str("sym2")); |
7212 Local<Value> s3 = global->Get(v8_str("sym3")); | 7221 Local<Value> s3 = global->Get(v8_str("sym3")); |
7213 Local<Value> s4 = global->Get(v8_str("sym4")); | 7222 Local<Value> s4 = global->Get(v8_str("sym4")); |
7214 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0)))); | 7223 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); |
7215 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b)))); | 7224 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); |
7216 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1)))); | 7225 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); |
7217 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2)))); | 7226 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); |
7218 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3)))); | 7227 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); |
7219 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4)))); | 7228 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); |
7220 } | 7229 } |
7221 | 7230 |
7222 | 7231 |
7223 THREADED_TEST(ToArrayIndex) { | 7232 THREADED_TEST(ToArrayIndex) { |
7224 LocalContext context; | 7233 LocalContext context; |
7225 v8::HandleScope scope(context->GetIsolate()); | 7234 v8::HandleScope scope(context->GetIsolate()); |
7226 | 7235 |
7227 v8::Handle<String> str = v8_str("42"); | 7236 v8::Handle<String> str = v8_str("42"); |
7228 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 7237 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
7229 CHECK(!index.IsEmpty()); | 7238 CHECK(!index.IsEmpty()); |
(...skipping 4968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12198 void DisposingCallback(v8::Isolate* isolate, | 12207 void DisposingCallback(v8::Isolate* isolate, |
12199 v8::Persistent<v8::Value>* handle, | 12208 v8::Persistent<v8::Value>* handle, |
12200 void*) { | 12209 void*) { |
12201 handle->Dispose(isolate); | 12210 handle->Dispose(isolate); |
12202 } | 12211 } |
12203 | 12212 |
12204 void HandleCreatingCallback(v8::Isolate* isolate, | 12213 void HandleCreatingCallback(v8::Isolate* isolate, |
12205 v8::Persistent<v8::Value>* handle, | 12214 v8::Persistent<v8::Value>* handle, |
12206 void*) { | 12215 void*) { |
12207 v8::HandleScope scope(isolate); | 12216 v8::HandleScope scope(isolate); |
12208 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); | 12217 v8::Persistent<v8::Object>(isolate, v8::Object::New()); |
12209 handle->Dispose(isolate); | 12218 handle->Dispose(isolate); |
12210 } | 12219 } |
12211 | 12220 |
12212 | 12221 |
12213 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { | 12222 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { |
12214 LocalContext context; | 12223 LocalContext context; |
12215 v8::Isolate* isolate = context->GetIsolate(); | 12224 v8::Isolate* isolate = context->GetIsolate(); |
12216 | 12225 |
12217 v8::Persistent<v8::Object> handle1, handle2, handle3; | 12226 v8::Persistent<v8::Object> handle1, handle2, handle3; |
12218 { | 12227 { |
(...skipping 7071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19290 obj->GetIdentityHash(); | 19299 obj->GetIdentityHash(); |
19291 obj->DeleteHiddenValue(v8_str("Bug")); | 19300 obj->DeleteHiddenValue(v8_str("Bug")); |
19292 } | 19301 } |
19293 | 19302 |
19294 | 19303 |
19295 THREADED_TEST(Regress2535) { | 19304 THREADED_TEST(Regress2535) { |
19296 i::FLAG_harmony_collections = true; | 19305 i::FLAG_harmony_collections = true; |
19297 LocalContext context; | 19306 LocalContext context; |
19298 v8::HandleScope scope(context->GetIsolate()); | 19307 v8::HandleScope scope(context->GetIsolate()); |
19299 Local<Value> set_value = CompileRun("new Set();"); | 19308 Local<Value> set_value = CompileRun("new Set();"); |
19300 Local<Object> set_object(Object::Cast(*set_value)); | 19309 Local<Object> set_object(Local<Object>::Cast(set_value)); |
19301 CHECK_EQ(0, set_object->InternalFieldCount()); | 19310 CHECK_EQ(0, set_object->InternalFieldCount()); |
19302 Local<Value> map_value = CompileRun("new Map();"); | 19311 Local<Value> map_value = CompileRun("new Map();"); |
19303 Local<Object> map_object(Object::Cast(*map_value)); | 19312 Local<Object> map_object(Local<Object>::Cast(map_value)); |
19304 CHECK_EQ(0, map_object->InternalFieldCount()); | 19313 CHECK_EQ(0, map_object->InternalFieldCount()); |
19305 } | 19314 } |
19306 | 19315 |
19307 | 19316 |
19308 #ifndef WIN32 | 19317 #ifndef WIN32 |
19309 class ThreadInterruptTest { | 19318 class ThreadInterruptTest { |
19310 public: | 19319 public: |
19311 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } | 19320 ThreadInterruptTest() : sem_(NULL), sem_value_(0) { } |
19312 ~ThreadInterruptTest() { delete sem_; } | 19321 ~ThreadInterruptTest() { delete sem_; } |
19313 | 19322 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19361 i::Semaphore* sem_; | 19370 i::Semaphore* sem_; |
19362 volatile int sem_value_; | 19371 volatile int sem_value_; |
19363 }; | 19372 }; |
19364 | 19373 |
19365 | 19374 |
19366 THREADED_TEST(SemaphoreInterruption) { | 19375 THREADED_TEST(SemaphoreInterruption) { |
19367 ThreadInterruptTest().RunTest(); | 19376 ThreadInterruptTest().RunTest(); |
19368 } | 19377 } |
19369 | 19378 |
19370 #endif // WIN32 | 19379 #endif // WIN32 |
OLD | NEW |