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

Unified Diff: third_party/WebKit/Source/platform/heap/HeapTest.cpp

Issue 1921733002: Support WeakMember<const T>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/Visitor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/heap/HeapTest.cpp
diff --git a/third_party/WebKit/Source/platform/heap/HeapTest.cpp b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
index 0c4bcb0d472f74923e6647bbfc2f91c988d378d9..ab794f67bcb125843a6412cc0bc90bfc829d078e 100644
--- a/third_party/WebKit/Source/platform/heap/HeapTest.cpp
+++ b/third_party/WebKit/Source/platform/heap/HeapTest.cpp
@@ -6527,4 +6527,43 @@ TEST(HeapTest, TestClearOnShutdown)
ThreadedClearOnShutdownTester::test();
}
+// Verify that WeakMember<const T> compiles and behaves as expected.
+class WithWeakConstObject final : public GarbageCollected<WithWeakConstObject> {
+public:
+ static WithWeakConstObject* create(const IntWrapper* intWrapper)
+ {
+ return new WithWeakConstObject(intWrapper);
+ }
+
+ DEFINE_INLINE_TRACE()
+ {
+ visitor->trace(m_wrapper);
+ }
+
+ const IntWrapper* value() const { return m_wrapper; }
+
+private:
+ WithWeakConstObject(const IntWrapper* intWrapper)
+ : m_wrapper(intWrapper)
+ {
+ }
+
+ WeakMember<const IntWrapper> m_wrapper;
+};
+
+TEST(HeapTest, TestWeakConstObject)
+{
+ Persistent<WithWeakConstObject> weakWrapper;
+ {
+ const IntWrapper* wrapper = IntWrapper::create(42);
+ weakWrapper = WithWeakConstObject::create(wrapper);
+ conservativelyCollectGarbage();
+ EXPECT_EQ(wrapper, weakWrapper->value());
+ // Stub out any stack reference.
+ wrapper = nullptr;
+ }
+ preciselyCollectGarbage();
+ EXPECT_EQ(nullptr, weakWrapper->value());
+}
+
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/Visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698