Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Unified Diff: test/cctest/test-api.cc

Issue 1089853005: prepare to deprecate non phantom weak callbacks (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/d8.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 857f8178b58e4b28fbd4190186c5cf7d12845af6..4ef83c71ed5983b03365f69bb564fe6c6fecc54b 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -3214,100 +3214,6 @@ TEST(TwoPassPhantomCallbacksNestedGc) {
}
-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); }
@@ -3568,7 +3474,7 @@ struct WeakCallCounterAndPersistent {
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();
@@ -3600,16 +3506,22 @@ THREADED_TEST(ApiObjectGroups) {
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);
@@ -3643,7 +3555,8 @@ THREADED_TEST(ApiObjectGroups) {
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();
@@ -3667,8 +3580,10 @@ THREADED_TEST(ApiObjectGroups) {
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());
@@ -3694,16 +3609,22 @@ THREADED_TEST(ApiObjectGroupsForSubtypes) {
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);
@@ -3737,7 +3658,8 @@ THREADED_TEST(ApiObjectGroupsForSubtypes) {
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();
@@ -3761,8 +3683,10 @@ THREADED_TEST(ApiObjectGroupsForSubtypes) {
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());
@@ -3789,29 +3713,37 @@ THREADED_TEST(ApiObjectGroupsCycle) {
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());
}
@@ -3849,7 +3781,8 @@ THREADED_TEST(ApiObjectGroupsCycle) {
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.
{
@@ -3878,45 +3811,6 @@ THREADED_TEST(ApiObjectGroupsCycle) {
}
-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) {
@@ -3939,18 +3833,24 @@ 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.
@@ -3991,7 +3891,8 @@ TEST(ApiObjectGroupsCycleForScavenger) {
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.
@@ -4286,9 +4187,12 @@ TEST(NativeWeakMap) {
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());
@@ -6681,11 +6585,10 @@ THREADED_TEST(InternalFieldCallback) {
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;
}
@@ -6714,8 +6617,10 @@ static void ResetWeakHandle(bool global_gc) {
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();
@@ -6744,21 +6649,31 @@ static void InvokeScavenge() { CcTest::heap()->CollectGarbage(i::NEW_SPACE); }
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();
@@ -6767,10 +6682,9 @@ THREADED_TEST(GCFromWeakCallbacks) {
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};
@@ -6783,7 +6697,8 @@ THREADED_TEST(GCFromWeakCallbacks) {
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);
@@ -6792,45 +6707,6 @@ THREADED_TEST(GCFromWeakCallbacks) {
}
-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;
@@ -11799,9 +11675,7 @@ TEST(CopyablePersistent) {
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();
}
@@ -11819,8 +11693,8 @@ TEST(WeakCallbackApi) {
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);
@@ -11832,11 +11706,18 @@ TEST(WeakCallbackApi) {
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);
}
@@ -11855,7 +11736,8 @@ THREADED_TEST(NewPersistentHandleFromWeakCallback) {
// 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();
}
@@ -11863,11 +11745,18 @@ THREADED_TEST(NewPersistentHandleFromWeakCallback) {
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);
}
@@ -11881,22 +11770,28 @@ THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
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);
}
@@ -11911,8 +11806,10 @@ THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
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();
}
« no previous file with comments | « src/d8.cc ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698