| Index: test/cctest/test-api.cc
|
| diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
|
| index d20d27c60c6f7d17c00f74756ffc6d7ad8ba7968..ef1d81850bc44d24d846e8b5081389420e94ab3c 100644
|
| --- a/test/cctest/test-api.cc
|
| +++ b/test/cctest/test-api.cc
|
| @@ -3166,13 +3166,8 @@ THREADED_TEST(GlobalHandleUpcast) {
|
| v8::HandleScope scope(isolate);
|
| v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
|
| v8::Persistent<String> global_string(isolate, local);
|
| -#ifdef V8_USE_UNSAFE_HANDLES
|
| - v8::Persistent<Value> global_value =
|
| - v8::Persistent<Value>::Cast(global_string);
|
| -#else
|
| v8::Persistent<Value>& global_value =
|
| v8::Persistent<Value>::Cast(global_string);
|
| -#endif
|
| CHECK(v8::Local<v8::Value>::New(isolate, global_value)->IsString());
|
| CHECK(global_string == v8::Persistent<String>::Cast(global_value));
|
| global_string.Dispose();
|
| @@ -12518,6 +12513,44 @@ TEST(DontLeakGlobalObjects) {
|
| }
|
| }
|
|
|
| +template<class T>
|
| +struct CopyablePersistentTraits {
|
| + typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent;
|
| + static const bool kDisposeInDestructor = true;
|
| + template<class S, class M>
|
| + V8_INLINE(static void Copy(const Persistent<S, M>& source,
|
| + CopyablePersistent* dest)) {
|
| + // do nothing, just allow copy
|
| + }
|
| +};
|
| +
|
| +
|
| +TEST(CopyablePersistent) {
|
| + LocalContext context;
|
| + v8::Isolate* isolate = context->GetIsolate();
|
| + i::GlobalHandles* globals =
|
| + reinterpret_cast<i::Isolate*>(isolate)->global_handles();
|
| + int initial_handles = globals->global_handles_count();
|
| + {
|
| + v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle1;
|
| + {
|
| + v8::HandleScope scope(isolate);
|
| + handle1.Reset(isolate, v8::Object::New());
|
| + }
|
| + CHECK_EQ(initial_handles + 1, globals->global_handles_count());
|
| + v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> > handle2;
|
| + handle2 = handle1;
|
| + CHECK(handle1 == handle2);
|
| + CHECK_EQ(initial_handles + 2, globals->global_handles_count());
|
| + v8::Persistent<v8::Object, CopyablePersistentTraits<v8::Object> >
|
| + handle3(handle2);
|
| + CHECK(handle1 == handle3);
|
| + CHECK_EQ(initial_handles + 3, globals->global_handles_count());
|
| + }
|
| + // Verify autodispose
|
| + CHECK_EQ(initial_handles, globals->global_handles_count());
|
| +}
|
| +
|
|
|
| v8::Persistent<v8::Object> some_object;
|
| v8::Persistent<v8::Object> bad_handle;
|
|
|