OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 namespace blink { | 5 namespace blink { |
6 | 6 |
7 // Note: do not add any copy or move constructors to this class: doing so will | 7 // Note: do not add any copy or move constructors to this class: doing so will |
8 // break test coverage that we don't clobber the class name by trying to emit | 8 // break test coverage that we don't clobber the class name by trying to emit |
9 // replacements for synthesized functions. | 9 // replacements for synthesized functions. |
10 class C { | 10 class C { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // https://crbug.com/640749#c1: Some type traits are inside blink namespace. | 65 // https://crbug.com/640749#c1: Some type traits are inside blink namespace. |
66 struct IsGarbageCollectedMixin { | 66 struct IsGarbageCollectedMixin { |
67 static const bool value = true; | 67 static const bool value = true; |
68 }; | 68 }; |
69 | 69 |
70 } // namespace blink | 70 } // namespace blink |
71 | 71 |
72 namespace WTF { | 72 namespace WTF { |
73 | 73 |
74 // We don't want to capitalize fields in type traits | 74 // We don't want to capitalize fields in type traits |
75 // (i.e. no |value| -> |kValue| rename is undesirable below). | 75 // (i.e. the |value| -> |kValue| rename is undesirable below). |
76 struct TypeTrait1 { | 76 struct TypeTrait1 { |
77 static const bool value = true; | 77 static const bool value = true; |
78 }; | 78 }; |
79 | 79 |
80 // Some type traits are implemented as classes, not structs | 80 // Some type traits are implemented as classes, not structs |
81 // (e.g. WTF::IsGarbageCollectedType or WTF::IsAssignable). | 81 // (e.g. WTF::IsGarbageCollectedType or WTF::IsAssignable). |
| 82 // We should not perform a |value| -> |kValue| rename in the type trait below. |
82 template <typename T> | 83 template <typename T> |
83 class TypeTrait2 { | 84 class TypeTrait2 { |
84 public: | 85 public: |
85 static const bool value = false; | 86 static const bool value = false; |
86 }; | 87 }; |
87 template <> | 88 template <> |
88 class TypeTrait2<void> { | 89 class TypeTrait2<void> { |
89 public: | 90 public: |
90 static const bool value = false; | 91 static const bool value = false; |
91 }; | 92 }; |
92 | 93 |
| 94 // Some type traits have static methods. We should not perform |
| 95 // a |value| -> |kValue| rename in the type trait below. |
| 96 template <typename T, typename U> |
| 97 struct IsSubclass { |
| 98 private: |
| 99 typedef char YesType; |
| 100 struct NoType { |
| 101 char padding[8]; |
| 102 }; |
| 103 |
| 104 static YesType subclassCheck(U*); |
| 105 static NoType subclassCheck(...); |
| 106 static T* t; |
| 107 |
| 108 public: |
| 109 static const bool value = sizeof(subclassCheck(t)) == sizeof(YesType); |
| 110 }; |
| 111 |
| 112 // Some type traits have deleted instance methods. We should not perform |
| 113 // a |value| -> |kValue| rename in the type trait below. |
| 114 template <typename U = void> |
| 115 struct IsTraceableInCollection { |
| 116 // Expanded from STATIC_ONLY(IsTraceableInCollection) macro: |
| 117 private: |
| 118 IsTraceableInCollection() = delete; |
| 119 IsTraceableInCollection(const IsTraceableInCollection&) = delete; |
| 120 IsTraceableInCollection& operator=(const IsTraceableInCollection&) = delete; |
| 121 void* operator new(unsigned long) = delete; |
| 122 void* operator new(unsigned long, void*) = delete; |
| 123 |
| 124 public: |
| 125 static const bool value = true; |
| 126 }; |
| 127 |
| 128 // Some type traits have a non-boolean value. |
| 129 enum LifetimeManagementType { |
| 130 RefCountedLifetime, |
| 131 GarbageCollectedLifetime, |
| 132 }; |
| 133 template <typename T> |
| 134 struct LifetimeOf { |
| 135 private: |
| 136 // Okay to rename |isGarbageCollected| to |kIsGarbageCollected|. |
| 137 static const bool isGarbageCollected = true; |
| 138 |
| 139 public: |
| 140 // Expecting no rename of |value|. |
| 141 static const LifetimeManagementType value = |
| 142 !isGarbageCollected ? RefCountedLifetime : GarbageCollectedLifetime; |
| 143 }; |
| 144 |
93 }; // namespace WTF | 145 }; // namespace WTF |
94 | 146 |
95 void F() { | 147 void F() { |
96 // Test that references to a static field are correctly rewritten. | 148 // Test that references to a static field are correctly rewritten. |
97 blink::C::instanceCount++; | 149 blink::C::instanceCount++; |
98 // Force instantiation of a copy constructor for blink::C to make sure field | 150 // Force instantiation of a copy constructor for blink::C to make sure field |
99 // initializers for synthesized functions don't cause weird rewrites. | 151 // initializers for synthesized functions don't cause weird rewrites. |
100 blink::C c; | 152 blink::C c; |
101 blink::C c2 = c; | 153 blink::C c2 = c; |
102 | 154 |
103 bool b1 = WTF::TypeTrait1::value; | 155 bool b1 = WTF::TypeTrait1::value; |
104 bool b2 = WTF::TypeTrait2<void>::value; | 156 bool b2 = WTF::TypeTrait2<void>::value; |
105 } | 157 } |
OLD | NEW |