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

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

Issue 24356002: move CopyablePersistentTraits to v8.h (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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 | « include/v8.h ('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 12658 matching lines...) Expand 10 before | Expand all | Expand 10 after
12669 const char* extension_list[] = { "v8/gc" }; 12669 const char* extension_list[] = { "v8/gc" };
12670 v8::ExtensionConfiguration extensions(1, extension_list); 12670 v8::ExtensionConfiguration extensions(1, extension_list);
12671 LocalContext context(&extensions); 12671 LocalContext context(&extensions);
12672 v8_compile("gc();")->Run(); 12672 v8_compile("gc();")->Run();
12673 } 12673 }
12674 v8::V8::ContextDisposedNotification(); 12674 v8::V8::ContextDisposedNotification();
12675 CheckSurvivingGlobalObjectsCount(0); 12675 CheckSurvivingGlobalObjectsCount(0);
12676 } 12676 }
12677 } 12677 }
12678 12678
12679 template<class T>
12680 struct CopyablePersistentTraits {
12681 typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
12682 static const bool kResetInDestructor = true;
12683 template<class S, class M>
12684 static V8_INLINE void Copy(const Persistent<S, M>& source,
12685 CopyablePersistent* dest) {
12686 // do nothing, just allow copy
12687 }
12688 };
12689
12690 12679
12691 TEST(CopyablePersistent) { 12680 TEST(CopyablePersistent) {
12692 LocalContext context; 12681 LocalContext context;
12693 v8::Isolate* isolate = context->GetIsolate(); 12682 v8::Isolate* isolate = context->GetIsolate();
12694 i::GlobalHandles* globals = 12683 i::GlobalHandles* globals =
12695 reinterpret_cast<i::Isolate*>(isolate)->global_handles(); 12684 reinterpret_cast<i::Isolate*>(isolate)->global_handles();
12696 int initial_handles = globals->global_handles_count(); 12685 int initial_handles = globals->global_handles_count();
12686 typedef v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object> >
12687 CopyableObject;
12697 { 12688 {
12698 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1; 12689 CopyableObject handle1;
12699 { 12690 {
12700 v8::HandleScope scope(isolate); 12691 v8::HandleScope scope(isolate);
12701 handle1.Reset(isolate, v8::Object::New()); 12692 handle1.Reset(isolate, v8::Object::New());
12702 } 12693 }
12703 CHECK_EQ(initial_handles + 1, globals->global_handles_count()); 12694 CHECK_EQ(initial_handles + 1, globals->global_handles_count());
12704 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2; 12695 CopyableObject handle2;
12705 handle2 = handle1; 12696 handle2 = handle1;
12706 CHECK(handle1 == handle2); 12697 CHECK(handle1 == handle2);
12707 CHECK_EQ(initial_handles + 2, globals->global_handles_count()); 12698 CHECK_EQ(initial_handles + 2, globals->global_handles_count());
12708 v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > 12699 CopyableObject handle3(handle2);
12709 handle3(handle2);
12710 CHECK(handle1 == handle3); 12700 CHECK(handle1 == handle3);
12711 CHECK_EQ(initial_handles + 3, globals->global_handles_count()); 12701 CHECK_EQ(initial_handles + 3, globals->global_handles_count());
12712 } 12702 }
12713 // Verify autodispose 12703 // Verify autodispose
12714 CHECK_EQ(initial_handles, globals->global_handles_count()); 12704 CHECK_EQ(initial_handles, globals->global_handles_count());
12715 } 12705 }
12716 12706
12717 12707
12718 static void WeakApiCallback( 12708 static void WeakApiCallback(
12719 const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) { 12709 const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) {
(...skipping 7876 matching lines...) Expand 10 before | Expand all | Expand 10 after
20596 Local<Object> data2 = v8::Object::New(); 20586 Local<Object> data2 = v8::Object::New();
20597 function_new_expected_env = data2; 20587 function_new_expected_env = data2;
20598 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 20588 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
20599 CHECK(!func2->IsNull()); 20589 CHECK(!func2->IsNull());
20600 CHECK_NE(func, func2); 20590 CHECK_NE(func, func2);
20601 env->Global()->Set(v8_str("func2"), func2); 20591 env->Global()->Set(v8_str("func2"), func2);
20602 Local<Value> result2 = CompileRun("func2();"); 20592 Local<Value> result2 = CompileRun("func2();");
20603 CHECK_EQ(v8::Integer::New(17, isolate), result2); 20593 CHECK_EQ(v8::Integer::New(17, isolate), result2);
20604 } 20594 }
20605 20595
OLDNEW
« no previous file with comments | « include/v8.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698