Pass Isolate to MakeWeak(), IsWeak(), and AddObjectGroup().

BUG=
TEST=cctest/test-api/ApiObjectGroupsCycle

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13139 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mstarzinger@chromium.org 2012-12-05 10:14:10 +00:00
parent 0e3fece02d
commit e46b251324
3 changed files with 93 additions and 5 deletions

View File

@ -408,6 +408,9 @@ template <class T> class Persistent : public Handle<T> {
* it the object reference and the given parameters.
*/
V8_INLINE(void MakeWeak(void* parameters, WeakReferenceCallback callback));
V8_INLINE(void MakeWeak(Isolate* isolate,
void* parameters,
WeakReferenceCallback callback));
/** Clears the weak reference to this object. */
V8_INLINE(void ClearWeak());
@ -442,6 +445,7 @@ template <class T> class Persistent : public Handle<T> {
/** Returns true if the handle's reference is weak. */
V8_INLINE(bool IsWeak() const);
V8_INLINE(bool IsWeak(Isolate* isolate) const);
/**
* Assigns a wrapper class ID to the handle. See RetainedObjectInfo
@ -3310,6 +3314,10 @@ class V8EXPORT V8 {
static void AddObjectGroup(Persistent<Value>* objects,
size_t length,
RetainedObjectInfo* info = NULL);
static void AddObjectGroup(Isolate* isolate,
Persistent<Value>* objects,
size_t length,
RetainedObjectInfo* info = NULL);
/**
* Allows the host application to declare implicit references between
@ -3543,6 +3551,10 @@ class V8EXPORT V8 {
static void MakeWeak(internal::Object** global_handle,
void* data,
WeakReferenceCallback);
static void MakeWeak(internal::Isolate* isolate,
internal::Object** global_handle,
void* data,
WeakReferenceCallback);
static void ClearWeak(internal::Object** global_handle);
static void MarkIndependent(internal::Object** global_handle);
static void MarkIndependent(internal::Isolate* isolate,
@ -3555,6 +3567,8 @@ class V8EXPORT V8 {
internal::Object** global_handle);
static bool IsGlobalNearDeath(internal::Object** global_handle);
static bool IsGlobalWeak(internal::Object** global_handle);
static bool IsGlobalWeak(internal::Isolate* isolate,
internal::Object** global_handle);
static void SetWrapperClassId(internal::Object** global_handle,
uint16_t class_id);
static uint16_t GetWrapperClassId(internal::Object** global_handle);
@ -4335,6 +4349,14 @@ bool Persistent<T>::IsWeak() const {
}
template <class T>
bool Persistent<T>::IsWeak(Isolate* isolate) const {
if (this->IsEmpty()) return false;
return V8::IsGlobalWeak(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(**this));
}
template <class T>
void Persistent<T>::Dispose() {
if (this->IsEmpty()) return;
@ -4360,6 +4382,15 @@ void Persistent<T>::MakeWeak(void* parameters, WeakReferenceCallback callback) {
callback);
}
template <class T>
void Persistent<T>::MakeWeak(Isolate* isolate, void* parameters,
WeakReferenceCallback callback) {
V8::MakeWeak(reinterpret_cast<internal::Isolate*>(isolate),
reinterpret_cast<internal::Object**>(**this),
parameters,
callback);
}
template <class T>
void Persistent<T>::ClearWeak() {
V8::ClearWeak(reinterpret_cast<internal::Object**>(**this));

View File

@ -630,7 +630,16 @@ void V8::MakeWeak(i::Object** object, void* parameters,
i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "MakeWeak");
isolate->global_handles()->MakeWeak(object, parameters,
callback);
callback);
}
void V8::MakeWeak(i::Isolate* isolate, i::Object** object,
void* parameters, WeakReferenceCallback callback) {
ASSERT(isolate == i::Isolate::Current());
LOG_API(isolate, "MakeWeak");
isolate->global_handles()->MakeWeak(object, parameters,
callback);
}
@ -701,6 +710,14 @@ bool V8::IsGlobalWeak(i::Object** obj) {
}
bool V8::IsGlobalWeak(i::Isolate* isolate, i::Object** obj) {
ASSERT(isolate == i::Isolate::Current());
LOG_API(isolate, "IsGlobalWeak");
if (!isolate->IsInitialized()) return false;
return i::GlobalHandles::IsWeak(obj);
}
void V8::DisposeGlobal(i::Object** obj) {
i::Isolate* isolate = i::Isolate::Current();
LOG_API(isolate, "DisposeGlobal");
@ -5390,6 +5407,7 @@ void V8::SetFailedAccessCheckCallbackFunction(
isolate->SetFailedAccessCheckCallback(callback);
}
void V8::AddObjectGroup(Persistent<Value>* objects,
size_t length,
RetainedObjectInfo* info) {
@ -5401,6 +5419,19 @@ void V8::AddObjectGroup(Persistent<Value>* objects,
}
void V8::AddObjectGroup(Isolate* exportedIsolate,
Persistent<Value>* objects,
size_t length,
RetainedObjectInfo* info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(exportedIsolate);
ASSERT(isolate == i::Isolate::Current());
if (IsDeadCheck(isolate, "v8::V8::AddObjectGroup()")) return;
STATIC_ASSERT(sizeof(Persistent<Value>) == sizeof(i::Object**));
isolate->global_handles()->AddObjectGroup(
reinterpret_cast<i::Object***>(objects), length, info);
}
void V8::AddImplicitReferences(Persistent<Object> parent,
Persistent<Value>* children,
size_t length) {

View File

@ -2487,23 +2487,41 @@ THREADED_TEST(ApiObjectGroupsCycle) {
Persistent<Object> g2s2;
Persistent<Object> g3s1;
Persistent<Object> g3s2;
Persistent<Object> g4s1;
Persistent<Object> g4s2;
v8::Isolate* isolate = v8::Isolate::GetCurrent();
{
HandleScope scope;
g1s1 = Persistent<Object>::New(Object::New());
g1s2 = Persistent<Object>::New(Object::New());
g1s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
g1s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
CHECK(g1s1.IsWeak());
CHECK(g1s2.IsWeak());
g2s1 = Persistent<Object>::New(Object::New());
g2s2 = Persistent<Object>::New(Object::New());
g2s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
g2s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
CHECK(g2s1.IsWeak());
CHECK(g2s2.IsWeak());
g3s1 = Persistent<Object>::New(Object::New());
g3s2 = Persistent<Object>::New(Object::New());
g3s1.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
g3s2.MakeWeak(reinterpret_cast<void*>(&counter), &WeakPointerCallback);
CHECK(g3s1.IsWeak());
CHECK(g3s2.IsWeak());
g4s1 = Persistent<Object>::New(Object::New());
g4s2 = Persistent<Object>::New(Object::New());
g4s1.MakeWeak(isolate,
reinterpret_cast<void*>(&counter), &WeakPointerCallback);
g4s2.MakeWeak(isolate,
reinterpret_cast<void*>(&counter), &WeakPointerCallback);
CHECK(g4s1.IsWeak(isolate));
CHECK(g4s2.IsWeak(isolate));
}
Persistent<Object> root = Persistent<Object>::New(g1s1); // make a root.
@ -2517,13 +2535,17 @@ THREADED_TEST(ApiObjectGroupsCycle) {
Persistent<Value> g2_objects[] = { g2s1, g2s2 };
Persistent<Value> g2_children[] = { g3s1 };
Persistent<Value> g3_objects[] = { g3s1, g3s2 };
Persistent<Value> g3_children[] = { g1s1 };
Persistent<Value> g3_children[] = { g4s1 };
Persistent<Value> g4_objects[] = { g4s1, g4s2 };
Persistent<Value> g4_children[] = { g1s1 };
V8::AddObjectGroup(g1_objects, 2);
V8::AddImplicitReferences(g1s1, g1_children, 1);
V8::AddObjectGroup(g2_objects, 2);
V8::AddImplicitReferences(g2s1, g2_children, 1);
V8::AddObjectGroup(g3_objects, 2);
V8::AddImplicitReferences(g3s1, g3_children, 1);
V8::AddObjectGroup(isolate, g4_objects, 2);
V8::AddImplicitReferences(g4s1, g4_children, 1);
}
// Do a single full GC
HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
@ -2541,19 +2563,23 @@ THREADED_TEST(ApiObjectGroupsCycle) {
Persistent<Value> g2_objects[] = { g2s1, g2s2 };
Persistent<Value> g2_children[] = { g3s1 };
Persistent<Value> g3_objects[] = { g3s1, g3s2 };
Persistent<Value> g3_children[] = { g1s1 };
Persistent<Value> g3_children[] = { g4s1 };
Persistent<Value> g4_objects[] = { g4s1, g4s2 };
Persistent<Value> g4_children[] = { g1s1 };
V8::AddObjectGroup(g1_objects, 2);
V8::AddImplicitReferences(g1s1, g1_children, 1);
V8::AddObjectGroup(g2_objects, 2);
V8::AddImplicitReferences(g2s1, g2_children, 1);
V8::AddObjectGroup(g3_objects, 2);
V8::AddImplicitReferences(g3s1, g3_children, 1);
V8::AddObjectGroup(g4_objects, 2);
V8::AddImplicitReferences(g4s1, g4_children, 1);
}
HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
// All objects should be gone. 7 global handles in total.
CHECK_EQ(7, counter.NumberOfWeakCalls());
// All objects should be gone. 9 global handles in total.
CHECK_EQ(9, counter.NumberOfWeakCalls());
}