}
-template <typename K, typename V>
-class WeakStdMapTraits : public v8::StdMapTraits<K, V> {
- public:
- typedef typename v8::PersistentValueMap<K, V, WeakStdMapTraits<K, V>> MapType;
- static const v8::PersistentContainerCallbackType kCallbackType = v8::kWeak;
- struct WeakCallbackDataType {
- MapType* map;
- K key;
- };
- static WeakCallbackDataType* WeakCallbackParameter(MapType* map, const K& key,
- Local<V> value) {
- WeakCallbackDataType* data = new WeakCallbackDataType;
- data->map = map;
- data->key = key;
- return data;
- }
- static MapType* MapFromWeakCallbackData(
- const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
- return data.GetParameter()->map;
- }
- static K KeyFromWeakCallbackData(
- const v8::WeakCallbackData<V, WeakCallbackDataType>& data) {
- return data.GetParameter()->key;
- }
- static void DisposeCallbackData(WeakCallbackDataType* data) { delete data; }
- static void Dispose(v8::Isolate* isolate, v8::Global<V> value, K key) {}
-};
-
-
-template <typename Map>
-static void TestPersistentValueMap() {
- LocalContext env;
- v8::Isolate* isolate = env->GetIsolate();
- Map map(isolate);
- v8::internal::GlobalHandles* global_handles =
- reinterpret_cast<v8::internal::Isolate*>(isolate)->global_handles();
- int initial_handle_count = global_handles->global_handles_count();
- CHECK_EQ(0, static_cast<int>(map.Size()));
- {
- HandleScope scope(isolate);
- Local<v8::Object> obj = map.Get(7);
- CHECK(obj.IsEmpty());
- Local<v8::Object> expected = v8::Object::New(isolate);
- map.Set(7, expected);
- CHECK_EQ(1, static_cast<int>(map.Size()));
- obj = map.Get(7);
- CHECK(expected->Equals(obj));
- {
- typename Map::PersistentValueReference ref = map.GetReference(7);
- CHECK(expected->Equals(ref.NewLocal(isolate)));
- }
- v8::Global<v8::Object> removed = map.Remove(7);
- CHECK_EQ(0, static_cast<int>(map.Size()));
- CHECK(expected == removed);
- removed = map.Remove(7);
- CHECK(removed.IsEmpty());
- map.Set(8, expected);
- CHECK_EQ(1, static_cast<int>(map.Size()));
- map.Set(8, expected);
- CHECK_EQ(1, static_cast<int>(map.Size()));
- {
- typename Map::PersistentValueReference ref;
- Local<v8::Object> expected2 = v8::Object::New(isolate);
- removed = map.Set(8, v8::Global<v8::Object>(isolate, expected2), &ref);
- CHECK_EQ(1, static_cast<int>(map.Size()));
- CHECK(expected == removed);
- CHECK(expected2->Equals(ref.NewLocal(isolate)));
- }
- }
- CHECK_EQ(initial_handle_count + 1, global_handles->global_handles_count());
- if (map.IsWeak()) {
- reinterpret_cast<v8::internal::Isolate*>(isolate)
- ->heap()
- ->CollectAllGarbage();
- } else {
- map.Clear();
- }
- CHECK_EQ(0, static_cast<int>(map.Size()));
- CHECK_EQ(initial_handle_count, global_handles->global_handles_count());
-}
-
-
-TEST(PersistentValueMap) {
- // Default case, w/o weak callbacks:
- TestPersistentValueMap<v8::StdPersistentValueMap<int, v8::Object>>();
-
- // Custom traits with weak callbacks:
- typedef v8::PersistentValueMap<int, v8::Object,
- WeakStdMapTraits<int, v8::Object>>
- WeakPersistentValueMap;
- TestPersistentValueMap<WeakPersistentValueMap>();
-}
-
-
namespace {
void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); }
template <typename T>
static void WeakPointerCallback(
- const v8::WeakCallbackData<T, WeakCallCounterAndPersistent<T>>& data) {
+ const v8::WeakCallbackInfo<WeakCallCounterAndPersistent<T>>& data) {
CHECK_EQ(1234, data.GetParameter()->counter->id());
data.GetParameter()->counter->increment();
data.GetParameter()->handle.Reset();
g1s1.handle.Reset(iso, Object::New(iso));
g1s2.handle.Reset(iso, Object::New(iso));
g1c1.handle.Reset(iso, Object::New(iso));
- g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
- g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
- g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
+ g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
g2s1.handle.Reset(iso, Object::New(iso));
g2s2.handle.Reset(iso, Object::New(iso));
g2c1.handle.Reset(iso, Object::New(iso));
- g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
- g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
- g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
+ g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
}
WeakCallCounterAndPersistent<Value> root(&counter);
CHECK_EQ(0, counter.NumberOfWeakCalls());
// Weaken the root.
- root.handle.SetWeak(&root, &WeakPointerCallback);
+ root.handle.SetWeak(&root, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
// But make children strong roots---all the objects (except for children)
// should be collectable now.
g1c1.handle.ClearWeak();
CHECK_EQ(5, counter.NumberOfWeakCalls());
// And now make children weak again and collect them.
- g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
- g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
+ g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
heap->CollectAllGarbage();
CHECK_EQ(7, counter.NumberOfWeakCalls());
g1s1.handle.Reset(iso, Object::New(iso));
g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1"));
g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2"));
- g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
- g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
- g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
+ g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
g2s1.handle.Reset(iso, Object::New(iso));
g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3"));
g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4"));
- g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
- g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
- g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
+ g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
}
WeakCallCounterAndPersistent<Value> root(&counter);
CHECK_EQ(0, counter.NumberOfWeakCalls());
// Weaken the root.
- root.handle.SetWeak(&root, &WeakPointerCallback);
+ root.handle.SetWeak(&root, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
// But make children strong roots---all the objects (except for children)
// should be collectable now.
g1c1.handle.ClearWeak();
CHECK_EQ(5, counter.NumberOfWeakCalls());
// And now make children weak again and collect them.
- g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback);
- g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback);
+ g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
heap->CollectAllGarbage();
CHECK_EQ(7, counter.NumberOfWeakCalls());
HandleScope scope(iso);
g1s1.handle.Reset(iso, Object::New(iso));
g1s2.handle.Reset(iso, Object::New(iso));
- g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
- g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
+ g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
CHECK(g1s1.handle.IsWeak());
CHECK(g1s2.handle.IsWeak());
g2s1.handle.Reset(iso, Object::New(iso));
g2s2.handle.Reset(iso, Object::New(iso));
- g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
- g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
+ g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
CHECK(g2s1.handle.IsWeak());
CHECK(g2s2.handle.IsWeak());
g3s1.handle.Reset(iso, Object::New(iso));
g3s2.handle.Reset(iso, Object::New(iso));
- g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
- g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
+ g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
CHECK(g3s1.handle.IsWeak());
CHECK(g3s2.handle.IsWeak());
g4s1.handle.Reset(iso, Object::New(iso));
g4s2.handle.Reset(iso, Object::New(iso));
- g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback);
- g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback);
+ g4s1.handle.SetWeak(&g4s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g4s2.handle.SetWeak(&g4s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
CHECK(g4s1.handle.IsWeak());
CHECK(g4s2.handle.IsWeak());
}
CHECK_EQ(0, counter.NumberOfWeakCalls());
// Weaken the root.
- root.handle.SetWeak(&root, &WeakPointerCallback);
+ root.handle.SetWeak(&root, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
// Groups are deleted, rebuild groups.
{
}
-THREADED_TEST(WeakRootsSurviveTwoRoundsOfGC) {
- LocalContext env;
- v8::Isolate* iso = env->GetIsolate();
- HandleScope scope(iso);
-
- WeakCallCounter counter(1234);
-
- WeakCallCounterAndPersistent<Value> weak_obj(&counter);
-
- // Create a weak object that references a internalized string.
- {
- HandleScope scope(iso);
- weak_obj.handle.Reset(iso, Object::New(iso));
- weak_obj.handle.SetWeak(&weak_obj, &WeakPointerCallback);
- CHECK(weak_obj.handle.IsWeak());
- Local<Object>::New(iso, weak_obj.handle.As<Object>())
- ->Set(v8_str("x"), String::NewFromUtf8(iso, "magic cookie",
- String::kInternalizedString));
- }
- // Do a single full GC
- i::Isolate* i_iso = reinterpret_cast<v8::internal::Isolate*>(iso);
- i::Heap* heap = i_iso->heap();
- heap->CollectAllGarbage();
-
- // We should have received the weak callback.
- CHECK_EQ(1, counter.NumberOfWeakCalls());
-
- // Check that the string is still alive.
- {
- HandleScope scope(iso);
- i::MaybeHandle<i::String> magic_string =
- i::StringTable::LookupStringIfExists(
- i_iso,
- v8::Utils::OpenHandle(*String::NewFromUtf8(iso, "magic cookie")));
- magic_string.Check();
- }
-}
-
-
// TODO(mstarzinger): This should be a THREADED_TEST but causes failures
// on the buildbots, so was made non-threaded for the time being.
TEST(ApiObjectGroupsCycleForScavenger) {
HandleScope scope(iso);
g1s1.handle.Reset(iso, Object::New(iso));
g1s2.handle.Reset(iso, Object::New(iso));
- g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback);
- g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback);
+ g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
g2s1.handle.Reset(iso, Object::New(iso));
g2s2.handle.Reset(iso, Object::New(iso));
- g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback);
- g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback);
+ g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
g3s1.handle.Reset(iso, Object::New(iso));
g3s2.handle.Reset(iso, Object::New(iso));
- g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback);
- g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback);
+ g3s1.handle.SetWeak(&g3s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ g3s2.handle.SetWeak(&g3s2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
}
// Make a root.
CHECK_EQ(0, counter.NumberOfWeakCalls());
// Weaken the root.
- root.handle.SetWeak(&root, &WeakPointerCallback);
+ root.handle.SetWeak(&root, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
root.handle.MarkPartiallyDependent();
// Groups are deleted, rebuild groups.
CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle))));
}
- o1.handle.SetWeak(&o1, &WeakPointerCallback);
- o2.handle.SetWeak(&o2, &WeakPointerCallback);
- s1.handle.SetWeak(&s1, &WeakPointerCallback);
+ o1.handle.SetWeak(&o1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ o2.handle.SetWeak(&o2, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
+ s1.handle.SetWeak(&s1, &WeakPointerCallback,
+ v8::WeakCallbackType::kParameter);
CcTest::heap()->CollectAllGarbage();
CHECK_EQ(3, counter.NumberOfWeakCalls());
static void ResetUseValueAndSetFlag(
- const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
+ const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
// Blink will reset the handle, and then use the other handle, so they
// can't use the same backing slot.
data.GetParameter()->handle.Reset();
- data.GetValue()->IsBoolean(); // Make sure the handle still works.
data.GetParameter()->flag = true;
}
object_a.flag = false;
object_b.flag = false;
- object_a.handle.SetWeak(&object_a, &ResetUseValueAndSetFlag);
- object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag);
+ object_a.handle.SetWeak(&object_a, &ResetUseValueAndSetFlag,
+ v8::WeakCallbackType::kParameter);
+ object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag,
+ v8::WeakCallbackType::kParameter);
if (!global_gc) {
object_a.handle.MarkIndependent();
object_b.handle.MarkIndependent();
static void InvokeMarkSweep() { CcTest::heap()->CollectAllGarbage(); }
-static void ForceScavenge(
- const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
- data.GetParameter()->handle.Reset();
+static void ForceScavenge2(
+ const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
InvokeScavenge();
}
-
-static void ForceMarkSweep(
- const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
+static void ForceScavenge1(
+ const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->handle.Reset();
+ data.SetSecondPassCallback(ForceScavenge2);
+}
+
+
+static void ForceMarkSweep2(
+ const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
InvokeMarkSweep();
}
+static void ForceMarkSweep1(
+ const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
+ data.GetParameter()->handle.Reset();
+ data.SetSecondPassCallback(ForceMarkSweep2);
+}
+
THREADED_TEST(GCFromWeakCallbacks) {
v8::Isolate* isolate = CcTest::isolate();
Context::Scope context_scope(context);
static const int kNumberOfGCTypes = 2;
- typedef v8::WeakCallbackData<v8::Object, FlagAndPersistent>::Callback
- Callback;
- Callback gc_forcing_callback[kNumberOfGCTypes] =
- {&ForceScavenge, &ForceMarkSweep};
+ typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback;
+ Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1,
+ &ForceMarkSweep1};
typedef void (*GCInvoker)();
GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
object.handle.Reset(isolate, v8::Object::New(isolate));
}
object.flag = false;
- object.handle.SetWeak(&object, gc_forcing_callback[inner_gc]);
+ object.handle.SetWeak(&object, gc_forcing_callback[inner_gc],
+ v8::WeakCallbackType::kParameter);
object.handle.MarkIndependent();
invoke_gc[outer_gc]();
CHECK(object.flag);
}
-static void RevivingCallback(
- const v8::WeakCallbackData<v8::Object, FlagAndPersistent>& data) {
- data.GetParameter()->handle.ClearWeak();
- data.GetParameter()->flag = true;
-}
-
-
-THREADED_TEST(IndependentHandleRevival) {
- v8::Isolate* isolate = CcTest::isolate();
- v8::HandleScope scope(isolate);
- v8::Handle<Context> context = Context::New(isolate);
- Context::Scope context_scope(context);
-
- FlagAndPersistent object;
- {
- v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Object> o = v8::Object::New(isolate);
- object.handle.Reset(isolate, o);
- o->Set(v8_str("x"), v8::Integer::New(isolate, 1));
- v8::Local<String> y_str = v8_str("y");
- o->Set(y_str, y_str);
- }
- object.flag = false;
- object.handle.SetWeak(&object, &RevivingCallback);
- object.handle.MarkIndependent();
- CcTest::heap()->CollectGarbage(i::NEW_SPACE);
- CHECK(object.flag);
- CcTest::heap()->CollectAllGarbage();
- {
- v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Object> o =
- v8::Local<v8::Object>::New(isolate, object.handle);
- v8::Local<String> y_str = v8_str("y");
- CHECK(v8::Integer::New(isolate, 1)->Equals(o->Get(v8_str("x"))));
- CHECK(o->Get(y_str)->Equals(y_str));
- }
-}
-
-
v8::Handle<Function> args_fun;
static void WeakApiCallback(
- const v8::WeakCallbackData<v8::Object, Persistent<v8::Object> >& data) {
- Local<Value> value = data.GetValue()->Get(v8_str("key"));
- CHECK_EQ(231, static_cast<int32_t>(Local<v8::Integer>::Cast(value)->Value()));
+ const v8::WeakCallbackInfo<Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
delete data.GetParameter();
}
obj->Set(v8_str("key"), v8::Integer::New(isolate, 231));
v8::Persistent<v8::Object>* handle =
new v8::Persistent<v8::Object>(isolate, obj);
- handle->SetWeak<v8::Object, v8::Persistent<v8::Object> >(handle,
- WeakApiCallback);
+ handle->SetWeak<v8::Persistent<v8::Object>>(
+ handle, WeakApiCallback, v8::WeakCallbackType::kParameter);
}
reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage(
i::Heap::kAbortIncrementalMarkingMask);
v8::Persistent<v8::Object> some_object;
v8::Persistent<v8::Object> bad_handle;
-void NewPersistentHandleCallback(
- const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
+
+void NewPersistentHandleCallback2(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
v8::HandleScope scope(data.GetIsolate());
bad_handle.Reset(data.GetIsolate(), some_object);
+}
+
+
+void NewPersistentHandleCallback1(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
+ data.SetSecondPassCallback(NewPersistentHandleCallback2);
}
// global handle nodes are processed by PostGarbageCollectionProcessing
// in reverse allocation order, so if second allocated handle is deleted,
// weak callback of the first handle would be able to 'reallocate' it.
- handle1.SetWeak(&handle1, NewPersistentHandleCallback);
+ handle1.SetWeak(&handle1, NewPersistentHandleCallback1,
+ v8::WeakCallbackType::kParameter);
handle2.Reset();
CcTest::heap()->CollectAllGarbage();
}
v8::Persistent<v8::Object> to_be_disposed;
-void DisposeAndForceGcCallback(
- const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
+
+void DisposeAndForceGcCallback2(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
to_be_disposed.Reset();
CcTest::heap()->CollectAllGarbage();
+}
+
+
+void DisposeAndForceGcCallback1(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
+ data.SetSecondPassCallback(DisposeAndForceGcCallback2);
}
handle1.Reset(isolate, v8::Object::New(isolate));
handle2.Reset(isolate, v8::Object::New(isolate));
}
- handle1.SetWeak(&handle1, DisposeAndForceGcCallback);
+ handle1.SetWeak(&handle1, DisposeAndForceGcCallback1,
+ v8::WeakCallbackType::kParameter);
to_be_disposed.Reset(isolate, handle2);
CcTest::heap()->CollectAllGarbage();
}
void DisposingCallback(
- const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
}
-void HandleCreatingCallback(
- const v8::WeakCallbackData<v8::Object, v8::Persistent<v8::Object> >& data) {
+void HandleCreatingCallback2(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
v8::HandleScope scope(data.GetIsolate());
- v8::Persistent<v8::Object>(data.GetIsolate(),
- v8::Object::New(data.GetIsolate()));
+ v8::Global<v8::Object>(data.GetIsolate(), v8::Object::New(data.GetIsolate()));
+}
+
+
+void HandleCreatingCallback1(
+ const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
data.GetParameter()->Reset();
+ data.SetSecondPassCallback(HandleCreatingCallback2);
}
handle2.Reset(isolate, v8::Object::New(isolate));
handle1.Reset(isolate, v8::Object::New(isolate));
}
- handle2.SetWeak(&handle2, DisposingCallback);
- handle3.SetWeak(&handle3, HandleCreatingCallback);
+ handle2.SetWeak(&handle2, DisposingCallback,
+ v8::WeakCallbackType::kParameter);
+ handle3.SetWeak(&handle3, HandleCreatingCallback1,
+ v8::WeakCallbackType::kParameter);
CcTest::heap()->CollectAllGarbage();
}