Implement IsIndependent(Isolate*)
BUG= TEST=cctest/test-api/IndependentWeakHandle Committed: https://code.google.com/p/v8/source/detail?r=12852 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@12854 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
e452c10702
commit
b77e629f1a
11
include/v8.h
11
include/v8.h
@ -416,6 +416,7 @@ template <class T> class Persistent : public Handle<T> {
|
||||
|
||||
/** Returns true if this handle was previously marked as independent. */
|
||||
inline bool IsIndependent() const;
|
||||
inline bool IsIndependent(Isolate* isolate) const;
|
||||
|
||||
/** Checks if the handle holds the only reference to an object. */
|
||||
inline bool IsNearDeath() const;
|
||||
@ -3520,6 +3521,8 @@ class V8EXPORT V8 {
|
||||
static void ClearWeak(internal::Object** global_handle);
|
||||
static void MarkIndependent(internal::Object** global_handle);
|
||||
static bool IsGlobalIndependent(internal::Object** global_handle);
|
||||
static bool IsGlobalIndependent(internal::Isolate* isolate,
|
||||
internal::Object** global_handle);
|
||||
static bool IsGlobalNearDeath(internal::Object** global_handle);
|
||||
static bool IsGlobalWeak(internal::Object** global_handle);
|
||||
static void SetWrapperClassId(internal::Object** global_handle,
|
||||
@ -4261,6 +4264,14 @@ bool Persistent<T>::IsIndependent() const {
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool Persistent<T>::IsIndependent(Isolate* isolate) const {
|
||||
if (this->IsEmpty()) return false;
|
||||
return V8::IsGlobalIndependent(reinterpret_cast<internal::Isolate*>(isolate),
|
||||
reinterpret_cast<internal::Object**>(**this));
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
bool Persistent<T>::IsNearDeath() const {
|
||||
if (this->IsEmpty()) return false;
|
||||
|
@ -659,6 +659,14 @@ bool V8::IsGlobalIndependent(i::Object** obj) {
|
||||
}
|
||||
|
||||
|
||||
bool V8::IsGlobalIndependent(i::Isolate* isolate, i::Object** obj) {
|
||||
ASSERT(isolate == i::Isolate::Current());
|
||||
LOG_API(isolate, "IsGlobalIndependent");
|
||||
if (!isolate->IsInitialized()) return false;
|
||||
return i::GlobalHandles::IsIndependent(obj);
|
||||
}
|
||||
|
||||
|
||||
bool V8::IsGlobalNearDeath(i::Object** obj) {
|
||||
i::Isolate* isolate = i::Isolate::Current();
|
||||
LOG_API(isolate, "IsGlobalNearDeath");
|
||||
|
@ -5419,11 +5419,14 @@ THREADED_TEST(IndependentWeakHandle) {
|
||||
object_a = v8::Persistent<v8::Object>::New(v8::Object::New());
|
||||
}
|
||||
|
||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||
bool object_a_disposed = false;
|
||||
object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
|
||||
CHECK(!object_a.IsIndependent());
|
||||
CHECK(!object_a.IsIndependent(isolate));
|
||||
object_a.MarkIndependent();
|
||||
CHECK(object_a.IsIndependent());
|
||||
CHECK(object_a.IsIndependent(isolate));
|
||||
HEAP->PerformScavenge();
|
||||
CHECK(object_a_disposed);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user