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

Unified Diff: test/cctest/test-global-handles.cc

Issue 1883173002: [api] Bring back finalizers on global handles (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« src/global-handles.cc ('K') | « src/global-handles.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-global-handles.cc
diff --git a/test/cctest/test-global-handles.cc b/test/cctest/test-global-handles.cc
index 22fd785566c9e2480bcee81948a037c6f5173f36..8fdb46a3e4d53cf2970791c2dd94f3135674242d 100644
--- a/test/cctest/test-global-handles.cc
+++ b/test/cctest/test-global-handles.cc
@@ -417,3 +417,36 @@ TEST(WeakPersistentSmi) {
// Should not crash.
g.SetWeak<void>(nullptr, &WeakCallback, v8::WeakCallbackType::kParameter);
}
+
+void finalizer(const v8::WeakCallbackInfo<v8::Global<v8::Object>>& data) {
+ data.GetParameter()->ClearWeak();
+ v8::Local<v8::Object> o =
+ v8::Local<v8::Object>::New(data.GetIsolate(), *data.GetParameter());
+ o->Set(data.GetIsolate()->GetCurrentContext(), v8_str("finalizer"),
+ v8_str("was here"))
+ .FromJust();
+}
+
+TEST(FinalizerWeakness) {
+ CcTest::InitializeVM();
+ v8::Isolate* isolate = CcTest::isolate();
+
+ v8::Global<v8::Object> g;
+ int identity;
+
+ {
+ v8::HandleScope scope(isolate);
+ v8::Local<v8::Object> o = v8::Object::New(isolate);
+ identity = o->GetIdentityHash();
+ g.Reset(isolate, o);
+ g.SetWeak(&g, finalizer, v8::WeakCallbackType::kFinalizer);
+ }
+
+ CcTest::i_isolate()->heap()->CollectAllAvailableGarbage();
+
+ CHECK(!g.IsEmpty());
+ v8::HandleScope scope(isolate);
+ v8::Local<v8::Object> o = v8::Local<v8::Object>::New(isolate, g);
+ CHECK_EQ(identity, o->GetIdentityHash());
+ CHECK(o->Has(isolate->GetCurrentContext(), v8_str("finalizer")).FromJust());
+}
« src/global-handles.cc ('K') | « src/global-handles.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698