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 3257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3268 TEST(TwoPassPhantomCallbacks) { | 3268 TEST(TwoPassPhantomCallbacks) { |
3269 auto isolate = CcTest::isolate(); | 3269 auto isolate = CcTest::isolate(); |
3270 const size_t kLength = 20; | 3270 const size_t kLength = 20; |
3271 int instance_counter = 0; | 3271 int instance_counter = 0; |
3272 for (size_t i = 0; i < kLength; ++i) { | 3272 for (size_t i = 0; i < kLength; ++i) { |
3273 auto data = new TwoPassCallbackData(isolate, &instance_counter); | 3273 auto data = new TwoPassCallbackData(isolate, &instance_counter); |
3274 data->SetWeak(); | 3274 data->SetWeak(); |
3275 } | 3275 } |
3276 CHECK_EQ(static_cast<int>(kLength), instance_counter); | 3276 CHECK_EQ(static_cast<int>(kLength), instance_counter); |
3277 CcTest::heap()->CollectAllGarbage(); | 3277 CcTest::heap()->CollectAllGarbage(); |
| 3278 EmptyMessageQueues(isolate); |
3278 CHECK_EQ(0, instance_counter); | 3279 CHECK_EQ(0, instance_counter); |
3279 } | 3280 } |
3280 | 3281 |
3281 | 3282 |
3282 TEST(TwoPassPhantomCallbacksNestedGc) { | 3283 TEST(TwoPassPhantomCallbacksNestedGc) { |
3283 auto isolate = CcTest::isolate(); | 3284 auto isolate = CcTest::isolate(); |
3284 const size_t kLength = 20; | 3285 const size_t kLength = 20; |
3285 TwoPassCallbackData* array[kLength]; | 3286 TwoPassCallbackData* array[kLength]; |
3286 int instance_counter = 0; | 3287 int instance_counter = 0; |
3287 for (size_t i = 0; i < kLength; ++i) { | 3288 for (size_t i = 0; i < kLength; ++i) { |
3288 array[i] = new TwoPassCallbackData(isolate, &instance_counter); | 3289 array[i] = new TwoPassCallbackData(isolate, &instance_counter); |
3289 array[i]->SetWeak(); | 3290 array[i]->SetWeak(); |
3290 } | 3291 } |
3291 array[5]->MarkTriggerGc(); | 3292 array[5]->MarkTriggerGc(); |
3292 array[10]->MarkTriggerGc(); | 3293 array[10]->MarkTriggerGc(); |
3293 array[15]->MarkTriggerGc(); | 3294 array[15]->MarkTriggerGc(); |
3294 CHECK_EQ(static_cast<int>(kLength), instance_counter); | 3295 CHECK_EQ(static_cast<int>(kLength), instance_counter); |
3295 CcTest::heap()->CollectAllGarbage(); | 3296 CcTest::heap()->CollectAllGarbage(); |
| 3297 EmptyMessageQueues(isolate); |
3296 CHECK_EQ(0, instance_counter); | 3298 CHECK_EQ(0, instance_counter); |
3297 } | 3299 } |
3298 | 3300 |
3299 | 3301 |
3300 namespace { | 3302 namespace { |
3301 | 3303 |
3302 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); } | 3304 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); } |
3303 | 3305 |
3304 | 3306 |
3305 Local<v8::Object> NewObjectForIntKey( | 3307 Local<v8::Object> NewObjectForIntKey( |
(...skipping 29 matching lines...) Expand all Loading... |
3335 } | 3337 } |
3336 static K KeyFromWeakCallbackInfo( | 3338 static K KeyFromWeakCallbackInfo( |
3337 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) { | 3339 const v8::WeakCallbackInfo<WeakCallbackDataType>& data) { |
3338 return data.GetParameter()->key; | 3340 return data.GetParameter()->key; |
3339 } | 3341 } |
3340 static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; } | 3342 static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; } |
3341 static void Dispose(v8::Isolate* isolate, v8::Global<V> value, K key) { | 3343 static void Dispose(v8::Isolate* isolate, v8::Global<V> value, K key) { |
3342 CHECK_EQ(IntKeyToVoidPointer(key), | 3344 CHECK_EQ(IntKeyToVoidPointer(key), |
3343 v8::Object::GetAlignedPointerFromInternalField(value, 0)); | 3345 v8::Object::GetAlignedPointerFromInternalField(value, 0)); |
3344 } | 3346 } |
| 3347 static void OnWeakCallback( |
| 3348 const v8::WeakCallbackInfo<WeakCallbackDataType>&) {} |
3345 static void DisposeWeak( | 3349 static void DisposeWeak( |
3346 const v8::WeakCallbackInfo<WeakCallbackDataType>& info) { | 3350 const v8::WeakCallbackInfo<WeakCallbackDataType>& info) { |
3347 K key = KeyFromWeakCallbackInfo(info); | 3351 K key = KeyFromWeakCallbackInfo(info); |
3348 CHECK_EQ(IntKeyToVoidPointer(key), info.GetInternalField(0)); | 3352 CHECK_EQ(IntKeyToVoidPointer(key), info.GetInternalField(0)); |
3349 DisposeCallbackData(info.GetParameter()); | 3353 DisposeCallbackData(info.GetParameter()); |
3350 } | 3354 } |
3351 }; | 3355 }; |
3352 | 3356 |
3353 | 3357 |
3354 template <typename Map> | 3358 template <typename Map> |
(...skipping 3444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6799 FlagAndPersistent object; | 6803 FlagAndPersistent object; |
6800 { | 6804 { |
6801 v8::HandleScope handle_scope(isolate); | 6805 v8::HandleScope handle_scope(isolate); |
6802 object.handle.Reset(isolate, v8::Object::New(isolate)); | 6806 object.handle.Reset(isolate, v8::Object::New(isolate)); |
6803 } | 6807 } |
6804 object.flag = false; | 6808 object.flag = false; |
6805 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc], | 6809 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc], |
6806 v8::WeakCallbackType::kParameter); | 6810 v8::WeakCallbackType::kParameter); |
6807 object.handle.MarkIndependent(); | 6811 object.handle.MarkIndependent(); |
6808 invoke_gc[outer_gc](); | 6812 invoke_gc[outer_gc](); |
| 6813 EmptyMessageQueues(isolate); |
6809 CHECK(object.flag); | 6814 CHECK(object.flag); |
6810 } | 6815 } |
6811 } | 6816 } |
6812 } | 6817 } |
6813 | 6818 |
6814 | 6819 |
6815 v8::Handle<Function> args_fun; | 6820 v8::Handle<Function> args_fun; |
6816 | 6821 |
6817 | 6822 |
6818 static void ArgumentsTestCallback( | 6823 static void ArgumentsTestCallback( |
(...skipping 5059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11878 v8::HandleScope scope(isolate); | 11883 v8::HandleScope scope(isolate); |
11879 handle3.Reset(isolate, v8::Object::New(isolate)); | 11884 handle3.Reset(isolate, v8::Object::New(isolate)); |
11880 handle2.Reset(isolate, v8::Object::New(isolate)); | 11885 handle2.Reset(isolate, v8::Object::New(isolate)); |
11881 handle1.Reset(isolate, v8::Object::New(isolate)); | 11886 handle1.Reset(isolate, v8::Object::New(isolate)); |
11882 } | 11887 } |
11883 handle2.SetWeak(&handle2, DisposingCallback, | 11888 handle2.SetWeak(&handle2, DisposingCallback, |
11884 v8::WeakCallbackType::kParameter); | 11889 v8::WeakCallbackType::kParameter); |
11885 handle3.SetWeak(&handle3, HandleCreatingCallback1, | 11890 handle3.SetWeak(&handle3, HandleCreatingCallback1, |
11886 v8::WeakCallbackType::kParameter); | 11891 v8::WeakCallbackType::kParameter); |
11887 CcTest::heap()->CollectAllGarbage(); | 11892 CcTest::heap()->CollectAllGarbage(); |
| 11893 EmptyMessageQueues(isolate); |
11888 } | 11894 } |
11889 | 11895 |
11890 | 11896 |
11891 THREADED_TEST(CheckForCrossContextObjectLiterals) { | 11897 THREADED_TEST(CheckForCrossContextObjectLiterals) { |
11892 v8::V8::Initialize(); | 11898 v8::V8::Initialize(); |
11893 | 11899 |
11894 const int nof = 2; | 11900 const int nof = 2; |
11895 const char* sources[nof] = { | 11901 const char* sources[nof] = { |
11896 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", | 11902 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", |
11897 "Object()" | 11903 "Object()" |
(...skipping 9951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21849 " fake.age;\n" | 21855 " fake.age;\n" |
21850 " result = 1;\n" | 21856 " result = 1;\n" |
21851 " } catch (e) {\n" | 21857 " } catch (e) {\n" |
21852 " }\n" | 21858 " }\n" |
21853 " test(d+1);\n" | 21859 " test(d+1);\n" |
21854 "}\n" | 21860 "}\n" |
21855 "test(0);\n" | 21861 "test(0);\n" |
21856 "result;\n", | 21862 "result;\n", |
21857 0); | 21863 0); |
21858 } | 21864 } |
OLD | NEW |