Implement IsIndependent(Isolate*)

BUG=
TEST=cctest/test-api/IndependentWeakHandle

Review URL: https://codereview.chromium.org/11368053
Patch from Kentaro Hara <haraken@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12852 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e26012e7
......@@ -392,6 +392,7 @@ template <class T> class Persistent : public Handle<T> {
* cell remain and IsEmpty will still return false.
*/
inline void Dispose();
inline void Dispose(Isolate* isolate);
/**
* Make the reference to this object weak. When only weak handles
......@@ -3511,6 +3512,8 @@ class V8EXPORT V8 {
static internal::Object** GlobalizeReference(internal::Object** handle);
static void DisposeGlobal(internal::Object** global_handle);
static void DisposeGlobal(internal::Isolate* isolate,
internal::Object** global_handle);
static void MakeWeak(internal::Object** global_handle,
void* data,
WeakReferenceCallback);
......@@ -4279,6 +4282,14 @@ void Persistent<T>::Dispose() {
}
template <class T>
void Persistent<T>::Dispose(Isolate* isolate) {
if (this->IsEmpty()) return;
V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(**this));
}
template <class T>
Persistent<T>::Persistent() : Handle<T>() { }
......
......@@ -682,6 +682,14 @@ void V8::DisposeGlobal(i::Object** obj) {
isolate->global_handles()->Destroy(obj);
}
void V8::DisposeGlobal(i::Isolate* isolate, i::Object** obj) {
ASSERT(isolate == i::Isolate::Current());
LOG_API(isolate, "DisposeGlobal");
if (!isolate->IsInitialized()) return;
isolate->global_handles()->Destroy(obj);
}
// --- H a n d l e s ---
......
......@@ -2345,6 +2345,14 @@ THREADED_TEST(GlobalHandle) {
}
CHECK_EQ(global->Length(), 3);
global.Dispose();
{
v8::HandleScope scope;
Local<String> str = v8_str("str");
global = v8::Persistent<String>::New(str);
}
CHECK_EQ(global->Length(), 3);
global.Dispose(v8::Isolate::GetCurrent());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment