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

Side by Side Diff: Source/platform/heap/HeapTest.cpp

Issue 827723002: Reland: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 5 years, 11 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 | « Source/platform/heap/Heap.h ('k') | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 { 51 {
52 return new IntWrapper(x); 52 return new IntWrapper(x);
53 } 53 }
54 54
55 virtual ~IntWrapper() 55 virtual ~IntWrapper()
56 { 56 {
57 ++s_destructorCalls; 57 ++s_destructorCalls;
58 } 58 }
59 59
60 static int s_destructorCalls; 60 static int s_destructorCalls;
61 static void trace(Visitor*) { } 61 void trace(Visitor*) { }
62 62
63 int value() const { return m_x; } 63 int value() const { return m_x; }
64 64
65 bool operator==(const IntWrapper& other) const { return other.value() == val ue(); } 65 bool operator==(const IntWrapper& other) const { return other.value() == val ue(); }
66 66
67 unsigned hash() { return IntHash<int>::hash(m_x); } 67 unsigned hash() { return IntHash<int>::hash(m_x); }
68 68
69 IntWrapper(int x) : m_x(x) { } 69 IntWrapper(int x) : m_x(x) { }
70 70
71 private: 71 private:
72 IntWrapper(); 72 IntWrapper();
73 int m_x; 73 int m_x;
74 }; 74 };
75 static_assert(WTF::NeedsTracing<IntWrapper>::value, "NeedsTracing macro failed t o recognize trace method.");
75 76
76 class ThreadMarker { 77 class ThreadMarker {
77 public: 78 public:
78 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num( 0) { } 79 ThreadMarker() : m_creatingThread(reinterpret_cast<ThreadState*>(0)), m_num( 0) { }
79 ThreadMarker(unsigned i) : m_creatingThread(ThreadState::current()), m_num(i ) { } 80 ThreadMarker(unsigned i) : m_creatingThread(ThreadState::current()), m_num(i ) { }
80 ThreadMarker(WTF::HashTableDeletedValueType deleted) : m_creatingThread(rein terpret_cast<ThreadState*>(-1)), m_num(0) { } 81 ThreadMarker(WTF::HashTableDeletedValueType deleted) : m_creatingThread(rein terpret_cast<ThreadState*>(-1)), m_num(0) { }
81 ~ThreadMarker() 82 ~ThreadMarker()
82 { 83 {
83 EXPECT_TRUE((m_creatingThread == ThreadState::current()) 84 EXPECT_TRUE((m_creatingThread == ThreadState::current())
84 || (m_creatingThread == reinterpret_cast<ThreadState*>(0)) 85 || (m_creatingThread == reinterpret_cast<ThreadState*>(0))
(...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 3636
3636 TEST(HeapTest, CollectionNesting) 3637 TEST(HeapTest, CollectionNesting)
3637 { 3638 {
3638 clearOutOldGarbage(); 3639 clearOutOldGarbage();
3639 int* key = &IntWrapper::s_destructorCalls; 3640 int* key = &IntWrapper::s_destructorCalls;
3640 IntWrapper::s_destructorCalls = 0; 3641 IntWrapper::s_destructorCalls = 0;
3641 typedef HeapVector<Member<IntWrapper> > IntVector; 3642 typedef HeapVector<Member<IntWrapper> > IntVector;
3642 typedef HeapDeque<Member<IntWrapper> > IntDeque; 3643 typedef HeapDeque<Member<IntWrapper> > IntDeque;
3643 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>(); 3644 HeapHashMap<void*, IntVector>* map = new HeapHashMap<void*, IntVector>();
3644 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>(); 3645 HeapHashMap<void*, IntDeque>* map2 = new HeapHashMap<void*, IntDeque>();
3646 static_assert(WTF::NeedsTracing<IntVector>::value, "Failed to recognize Heap Vector as NeedsTracing");
3647 static_assert(WTF::NeedsTracing<IntDeque>::value, "Failed to recognize HeapD eque as NeedsTracing");
3645 3648
3646 map->add(key, IntVector()); 3649 map->add(key, IntVector());
3647 map2->add(key, IntDeque()); 3650 map2->add(key, IntDeque());
3648 3651
3649 HeapHashMap<void*, IntVector>::iterator it = map->find(key); 3652 HeapHashMap<void*, IntVector>::iterator it = map->find(key);
3650 EXPECT_EQ(0u, map->get(key).size()); 3653 EXPECT_EQ(0u, map->get(key).size());
3651 3654
3652 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key); 3655 HeapHashMap<void*, IntDeque>::iterator it2 = map2->find(key);
3653 EXPECT_EQ(0u, map2->get(key).size()); 3656 EXPECT_EQ(0u, map2->get(key).size());
3654 3657
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after
5483 // re-adjusting both start&end indices in terms of that expanded buffer. 5486 // re-adjusting both start&end indices in terms of that expanded buffer.
5484 EXPECT_EQ(80u, deque->size()); 5487 EXPECT_EQ(80u, deque->size());
5485 i = 0; 5488 i = 0;
5486 for (const auto& intWrapper : *deque) { 5489 for (const auto& intWrapper : *deque) {
5487 EXPECT_EQ(i + 50, intWrapper->value()); 5490 EXPECT_EQ(i + 50, intWrapper->value());
5488 i++; 5491 i++;
5489 } 5492 }
5490 } 5493 }
5491 5494
5492 } // namespace blink 5495 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/Visitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698