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

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

Issue 23401003: new persistent semantics (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments, etc Created 7 years, 3 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/global-handles.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 3228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 global_handles->Destroy(reinterpret_cast<i::Object**>(str)); 3239 global_handles->Destroy(reinterpret_cast<i::Object**>(str));
3240 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count); 3240 CHECK_EQ(global_handles->global_handles_count(), initial_handle_count);
3241 } 3241 }
3242 3242
3243 3243
3244 THREADED_TEST(GlobalHandleUpcast) { 3244 THREADED_TEST(GlobalHandleUpcast) {
3245 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3245 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3246 v8::HandleScope scope(isolate); 3246 v8::HandleScope scope(isolate);
3247 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 3247 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
3248 v8::Persistent<String> global_string(isolate, local); 3248 v8::Persistent<String> global_string(isolate, local);
3249 #ifdef V8_USE_UNSAFE_HANDLES
3250 v8::Persistent<Value> global_value =
3251 v8::Persistent<Value>::Cast(global_string);
3252 #else
3253 v8::Persistent<Value>& global_value = 3249 v8::Persistent<Value>& global_value =
3254 v8::Persistent<Value>::Cast(global_string); 3250 v8::Persistent<Value>::Cast(global_string);
3255 #endif
3256 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString()); 3251 CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
3257 CHECK(global_string == v8::Persistent<String>::Cast(global_value)); 3252 CHECK(global_string == v8::Persistent<String>::Cast(global_value));
3258 global_string.Dispose(); 3253 global_string.Dispose();
3259 } 3254 }
3260 3255
3261 3256
3262 THREADED_TEST(HandleEquality) { 3257 THREADED_TEST(HandleEquality) {
3263 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 3258 v8::Isolate* isolate = v8::Isolate::GetCurrent();
3264 v8::Persistent<String> global1; 3259 v8::Persistent<String> global1;
3265 v8::Persistent<String> global2; 3260 v8::Persistent<String> global2;
(...skipping 9397 matching lines...) Expand 10 before | Expand all | Expand 10 after
12663 const char* extension_list[] = { "v8/gc" }; 12658 const char* extension_list[] = { "v8/gc" };
12664 v8::ExtensionConfiguration extensions(1, extension_list); 12659 v8::ExtensionConfiguration extensions(1, extension_list);
12665 LocalContext context(&extensions); 12660 LocalContext context(&extensions);
12666 v8_compile("gc();")->Run(); 12661 v8_compile("gc();")->Run();
12667 } 12662 }
12668 v8::V8::ContextDisposedNotification(); 12663 v8::V8::ContextDisposedNotification();
12669 CheckSurvivingGlobalObjectsCount(0); 12664 CheckSurvivingGlobalObjectsCount(0);
12670 } 12665 }
12671 } 12666 }
12672 12667
12668 template<class T>
12669 struct CopyablePersistentTraits {
12670 typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
12671 static const bool kResetInDestructor = true;
12672 template<class S, class M>
12673 V8_INLINE(static void Copy(const Persistent<S, M>& source,
12674 CopyablePersistent* dest)) {
12675 // do nothing, just allow copy
12676 }
12677 };
12678
12679
12680 TEST(CopyablePersistent) {
12681 LocalContext context;
12682 v8::Isolate* isolate = context->GetIsolate();
12683 i::GlobalHandles* globals =
12684 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
12685 int initial_handles = globals->global_handles_count();
12686 {
12687 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1;
12688 {
12689 v8::HandleScope scope(isolate);
12690 handle1.Reset(isolate, v8::Object::New());
12691 }
12692 CHECK_EQ(initial_handles + 1, globals->global_handles_count());
12693 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2;
12694 handle2 = handle1;
12695 CHECK(handle1 == handle2);
12696 CHECK_EQ(initial_handles + 2, globals->global_handles_count());
12697 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> >
12698 handle3(handle2);
12699 CHECK(handle1 == handle3);
12700 CHECK_EQ(initial_handles + 3, globals->global_handles_count());
12701 }
12702 // Verify autodispose
12703 CHECK_EQ(initial_handles, globals->global_handles_count());
12704 }
12705
12706
12707 static void WeakApiCallback(
12708 const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) {
12709 Local<Value> value = data.GetValue()->Get(v8_str("key"));
12710 CHECK_EQ(231, static_cast<int32_t>(Local<v8::Integer>::Cast(value)->Value()));
12711 data.GetParameter()->Reset();
12712 delete data.GetParameter();
12713 }
12714
12715
12716 TEST(WeakCallbackApi) {
12717 LocalContext context;
12718 v8::Isolate* isolate = context->GetIsolate();
12719 i::GlobalHandles* globals =
12720 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
12721 int initial_handles = globals->global_handles_count();
12722 {
12723 v8::HandleScope scope(isolate);
12724 v8::Local<v8::Object> obj = v8::Object::New();
12725 obj->Set(v8_str("key"), v8::Integer::New(231, isolate));
12726 v8::Persistent<v8::Object>* handle =
12727 new v8::Persistent<v8::Object>(isolate, obj);
12728 handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle,
12729 WeakApiCallback);
12730 }
12731 reinterpret_cast<i::Isolate*>(isolate)->heap()->
12732 CollectAllGarbage(i::Heap::kNoGCFlags);
12733 // Verify disposed.
12734 CHECK_EQ(initial_handles, globals->global_handles_count());
12735 }
12736
12673 12737
12674 v8::Persistent<v8::Object> some_object; 12738 v8::Persistent<v8::Object> some_object;
12675 v8::Persistent<v8::Object> bad_handle; 12739 v8::Persistent<v8::Object> bad_handle;
12676 12740
12677 void NewPersistentHandleCallback(v8::Isolate* isolate, 12741 void NewPersistentHandleCallback(v8::Isolate* isolate,
12678 v8::Persistent<v8::Value>* handle, 12742 v8::Persistent<v8::Value>* handle,
12679 void*) { 12743 void*) {
12680 v8::HandleScope scope(isolate); 12744 v8::HandleScope scope(isolate);
12681 bad_handle.Reset(isolate, some_object); 12745 bad_handle.Reset(isolate, some_object);
12682 handle->Dispose(); 12746 handle->Dispose();
(...skipping 7832 matching lines...) Expand 10 before | Expand all | Expand 10 after
20515 // Verify function not cached 20579 // Verify function not cached
20516 int serial_number = 20580 int serial_number =
20517 i::Smi::cast(v8::Utils::OpenHandle(*func) 20581 i::Smi::cast(v8::Utils::OpenHandle(*func)
20518 ->shared()->get_api_func_data()->serial_number())->value(); 20582 ->shared()->get_api_func_data()->serial_number())->value();
20519 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 20583 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
20520 i::Object* elm = i_isolate->native_context()->function_cache() 20584 i::Object* elm = i_isolate->native_context()->function_cache()
20521 ->GetElementNoExceptionThrown(i_isolate, serial_number); 20585 ->GetElementNoExceptionThrown(i_isolate, serial_number);
20522 CHECK(elm->IsNull()); 20586 CHECK(elm->IsNull());
20523 } 20587 }
20524 20588
OLDNEW
« no previous file with comments | « src/global-handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698