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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/Visitor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 6509 matching lines...) Expand 10 before | Expand all | Expand 10 after
6520 } 6520 }
6521 }; 6521 };
6522 6522
6523 } // namespace 6523 } // namespace
6524 6524
6525 TEST(HeapTest, TestClearOnShutdown) 6525 TEST(HeapTest, TestClearOnShutdown)
6526 { 6526 {
6527 ThreadedClearOnShutdownTester::test(); 6527 ThreadedClearOnShutdownTester::test();
6528 } 6528 }
6529 6529
6530 // Verify that WeakMember<const T> compiles and behaves as expected.
6531 class WithWeakConstObject final : public GarbageCollected<WithWeakConstObject> {
6532 public:
6533 static WithWeakConstObject* create(const IntWrapper* intWrapper)
6534 {
6535 return new WithWeakConstObject(intWrapper);
6536 }
6537
6538 DEFINE_INLINE_TRACE()
6539 {
6540 visitor->trace(m_wrapper);
6541 }
6542
6543 const IntWrapper* value() const { return m_wrapper; }
6544
6545 private:
6546 WithWeakConstObject(const IntWrapper* intWrapper)
6547 : m_wrapper(intWrapper)
6548 {
6549 }
6550
6551 WeakMember<const IntWrapper> m_wrapper;
6552 };
6553
6554 TEST(HeapTest, TestWeakConstObject)
6555 {
6556 Persistent<WithWeakConstObject> weakWrapper;
6557 {
6558 const IntWrapper* wrapper = IntWrapper::create(42);
6559 weakWrapper = WithWeakConstObject::create(wrapper);
6560 conservativelyCollectGarbage();
6561 EXPECT_EQ(wrapper, weakWrapper->value());
6562 // Stub out any stack reference.
6563 wrapper = nullptr;
6564 }
6565 preciselyCollectGarbage();
6566 EXPECT_EQ(nullptr, weakWrapper->value());
6567 }
6568
6530 } // namespace blink 6569 } // namespace blink
OLDNEW
« 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