Revision: 14624
Author: [email protected]
Date: Fri May 10 07:04:51 2013
Log: Add Persistent::ClearAndLeak.
This will be relevant after Persistent is changed to Dispose itself when
destructed. With Persistent::ClearAndLeak, Blink can take the ownership of
the
object pointed by a Persistent and avoid it getting destructed.
BUG=
[email protected]
Review URL: https://codereview.chromium.org/15023010
Patch from Marja Hölttä <[email protected]>.
http://code.google.com/p/v8/source/detail?r=14624
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Fri May 10 05:59:20 2013
+++ /branches/bleeding_edge/include/v8.h Fri May 10 07:04:51 2013
@@ -695,6 +695,16 @@
*/
V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
+ /**
+ * Returns the underlying raw pointer and clears the handle. The caller
is
+ * responsible of eventually destroying the underlying object (by
creating a
+ * Persistent handle which points to it and Disposing it). In the future,
+ * destructing a Persistent will also Dispose it. With this function, the
+ * embedder can let the Persistent go out of scope without it getting
+ * disposed.
+ */
+ V8_INLINE(T* ClearAndLeak());
+
#ifndef V8_USE_UNSAFE_HANDLES
#ifndef V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT
@@ -5382,6 +5392,7 @@
void Persistent<T>::SetWrapperClassId(uint16_t class_id) {
SetWrapperClassId(Isolate::GetCurrent(), class_id);
}
+
template <class T>
void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
@@ -5398,6 +5409,21 @@
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p));
#endif
}
+
+
+template <class T>
+T* Persistent<T>::ClearAndLeak() {
+ T* old;
+#ifdef V8_USE_UNSAFE_HANDLES
+ old = **this;
+ *this = Persistent<T>();
+#else
+ old = val_;
+ val_ = NULL;
+#endif
+ return old;
+}
+
template <class T>
void Persistent<T>::SetWrapperClassId(Isolate* isolate, uint16_t class_id)
{
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Wed May 8 00:45:16 2013
+++ /branches/bleeding_edge/test/cctest/test-api.cc Fri May 10 07:04:51 2013
@@ -2537,6 +2537,30 @@
CHECK(global.IsEmpty());
CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count);
}
+
+
+THREADED_TEST(ClearAndLeakGlobal) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::internal::GlobalHandles* global_handles = NULL;
+ int initial_handle_count = 0;
+ v8::Persistent<String> global;
+ {
+ v8::HandleScope scope(isolate);
+ Local<String> str = v8_str("str");
+ global_handles =
+
reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
+ initial_handle_count = global_handles->NumberOfGlobalHandles();
+ global = v8::Persistent<String>::New(isolate, str);
+ }
+ CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count +
1);
+ String* str = global.ClearAndLeak();
+ CHECK(global.IsEmpty());
+ CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count +
1);
+ v8::Persistent<String>* new_global =
+ reinterpret_cast<v8::Persistent<String>*>(&str);
+ new_global->Dispose();
+ CHECK_EQ(global_handles->NumberOfGlobalHandles(), initial_handle_count);
+}
THREADED_TEST(LocalHandle) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.