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 3148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); | 3159 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); |
3160 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); | 3160 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); |
3161 } | 3161 } |
3162 | 3162 |
3163 | 3163 |
3164 THREADED_TEST(GlobalHandleUpcast) { | 3164 THREADED_TEST(GlobalHandleUpcast) { |
3165 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3165 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
3166 v8::HandleScope scope(isolate); | 3166 v8::HandleScope scope(isolate); |
3167 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); | 3167 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); |
3168 v8::Persistent<String> global_string(isolate, local); | 3168 v8::Persistent<String> global_string(isolate, local); |
3169 #ifdef V8_USE_UNSAFE_HANDLES | |
3170 v8::Persistent<Value> global_value = | |
3171 v8::Persistent<Value>::Cast(global_string); | |
3172 #else | |
3173 v8::Persistent<Value>& global_value = | 3169 v8::Persistent<Value>& global_value = |
3174 v8::Persistent<Value>::Cast(global_string); | 3170 v8::Persistent<Value>::Cast(global_string); |
3175 #endif | |
3176 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); | 3171 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); |
3177 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); | 3172 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); |
3178 global_string.Dispose(); | 3173 global_string.Dispose(); |
3179 } | 3174 } |
3180 | 3175 |
3181 | 3176 |
3182 THREADED_TEST(HandleEquality) { | 3177 THREADED_TEST(HandleEquality) { |
3183 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 3178 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
3184 v8::Persistent<String> global1; | 3179 v8::Persistent<String> global1; |
3185 v8::Persistent<String> global2; | 3180 v8::Persistent<String> global2; |
(...skipping 9325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12511 const char* extension_list[] = { "v8/gc" }; | 12506 const char* extension_list[] = { "v8/gc" }; |
12512 v8::ExtensionConfiguration extensions(1, extension_list); | 12507 v8::ExtensionConfiguration extensions(1, extension_list); |
12513 LocalContext context(&extensions); | 12508 LocalContext context(&extensions); |
12514 v8_compile("gc();")->Run(); | 12509 v8_compile("gc();")->Run(); |
12515 } | 12510 } |
12516 v8::V8::ContextDisposedNotification(); | 12511 v8::V8::ContextDisposedNotification(); |
12517 CheckSurvivingGlobalObjectsCount(0); | 12512 CheckSurvivingGlobalObjectsCount(0); |
12518 } | 12513 } |
12519 } | 12514 } |
12520 | 12515 |
| 12516 template<class T> |
| 12517 struct CopyablePersistentTraits { |
| 12518 typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; |
| 12519 static const bool kDisposeInDestructor = true; |
| 12520 template<class S, class M> |
| 12521 V8_INLINE(static void Copy(const Persistent<S, M>& source, |
| 12522 CopyablePersistent* dest)) { |
| 12523 // do nothing, just allow copy |
| 12524 } |
| 12525 }; |
| 12526 |
| 12527 |
| 12528 TEST(CopyablePersistent) { |
| 12529 LocalContext context; |
| 12530 v8::Isolate* isolate = context->GetIsolate(); |
| 12531 i::GlobalHandles* globals = |
| 12532 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); |
| 12533 int initial_handles = globals->global_handles_count(); |
| 12534 { |
| 12535 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1; |
| 12536 { |
| 12537 v8::HandleScope scope(isolate); |
| 12538 handle1.Reset(isolate, v8::Object::New()); |
| 12539 } |
| 12540 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); |
| 12541 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2; |
| 12542 handle2 = handle1; |
| 12543 CHECK(handle1 == handle2); |
| 12544 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); |
| 12545 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > |
| 12546 handle3(handle2); |
| 12547 CHECK(handle1 == handle3); |
| 12548 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); |
| 12549 } |
| 12550 // Verify autodispose |
| 12551 CHECK_EQ(initial_handles, globals->global_handles_count()); |
| 12552 } |
| 12553 |
12521 | 12554 |
12522 v8::Persistent<v8::Object> some_object; | 12555 v8::Persistent<v8::Object> some_object; |
12523 v8::Persistent<v8::Object> bad_handle; | 12556 v8::Persistent<v8::Object> bad_handle; |
12524 | 12557 |
12525 void NewPersistentHandleCallback(v8::Isolate* isolate, | 12558 void NewPersistentHandleCallback(v8::Isolate* isolate, |
12526 v8::Persistent<v8::Value>* handle, | 12559 v8::Persistent<v8::Value>* handle, |
12527 void*) { | 12560 void*) { |
12528 v8::HandleScope scope(isolate); | 12561 v8::HandleScope scope(isolate); |
12529 bad_handle.Reset(isolate, some_object); | 12562 bad_handle.Reset(isolate, some_object); |
12530 handle->Dispose(isolate); | 12563 handle->Dispose(isolate); |
(...skipping 7664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20195 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); | 20228 CheckCorrectThrow("%GetLocalPropertyNames(other, true)"); |
20196 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" | 20229 CheckCorrectThrow("%DefineOrRedefineAccessorProperty(" |
20197 "other, 'x', null, null, 1)"); | 20230 "other, 'x', null, null, 1)"); |
20198 | 20231 |
20199 // Reset the failed access check callback so it does not influence | 20232 // Reset the failed access check callback so it does not influence |
20200 // the other tests. | 20233 // the other tests. |
20201 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); | 20234 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); |
20202 } | 20235 } |
20203 | 20236 |
20204 #endif // WIN32 | 20237 #endif // WIN32 |
OLD | NEW |