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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // https://crbug.com/640749#c1: Some type traits are inside blink namespace. | 68 // https://crbug.com/640749#c1: Some type traits are inside blink namespace. |
69 struct IsGarbageCollectedMixin { | 69 struct IsGarbageCollectedMixin { |
70 static const bool value = true; | 70 static const bool value = true; |
71 }; | 71 }; |
72 | 72 |
73 } // namespace blink | 73 } // namespace blink |
74 | 74 |
75 namespace WTF { | 75 namespace WTF { |
76 | 76 |
77 // We don't want to capitalize fields in type traits | 77 // We don't want to capitalize fields in type traits |
78 // (i.e. no |value| -> |kValue| rename is undesirable below). | 78 // (i.e. the |value| -> |kValue| rename is undesirable below). |
79 struct TypeTrait1 { | 79 struct TypeTrait1 { |
80 static const bool value = true; | 80 static const bool value = true; |
81 }; | 81 }; |
82 | 82 |
83 // Some type traits are implemented as classes, not structs | 83 // Some type traits are implemented as classes, not structs |
84 // (e.g. WTF::IsGarbageCollectedType or WTF::IsAssignable). | 84 // (e.g. WTF::IsGarbageCollectedType or WTF::IsAssignable). |
| 85 // We should not perform a |value| -> |kValue| rename in the type trait below. |
85 template <typename T> | 86 template <typename T> |
86 class TypeTrait2 { | 87 class TypeTrait2 { |
87 public: | 88 public: |
88 static const bool value = false; | 89 static const bool value = false; |
89 }; | 90 }; |
90 template <> | 91 template <> |
91 class TypeTrait2<void> { | 92 class TypeTrait2<void> { |
92 public: | 93 public: |
93 static const bool value = false; | 94 static const bool value = false; |
94 }; | 95 }; |
95 | 96 |
| 97 // Some type traits have static methods. We should not perform |
| 98 // a |value| -> |kValue| rename in the type trait below. |
| 99 template <typename T, typename U> |
| 100 struct IsSubclass { |
| 101 private: |
| 102 typedef char YesType; |
| 103 struct NoType { |
| 104 char padding[8]; |
| 105 }; |
| 106 |
| 107 static YesType SubclassCheck(U*); |
| 108 static NoType SubclassCheck(...); |
| 109 static T* t_; |
| 110 |
| 111 public: |
| 112 static const bool value = sizeof(SubclassCheck(t_)) == sizeof(YesType); |
| 113 }; |
| 114 |
| 115 // Some type traits have deleted instance methods. We should not perform |
| 116 // a |value| -> |kValue| rename in the type trait below. |
| 117 template <typename U = void> |
| 118 struct IsTraceableInCollection { |
| 119 // Expanded from STATIC_ONLY(IsTraceableInCollection) macro: |
| 120 private: |
| 121 IsTraceableInCollection() = delete; |
| 122 IsTraceableInCollection(const IsTraceableInCollection&) = delete; |
| 123 IsTraceableInCollection& operator=(const IsTraceableInCollection&) = delete; |
| 124 void* operator new(unsigned long) = delete; |
| 125 void* operator new(unsigned long, void*) = delete; |
| 126 |
| 127 public: |
| 128 static const bool value = true; |
| 129 }; |
| 130 |
| 131 // Some type traits have a non-boolean value. |
| 132 enum LifetimeManagementType { |
| 133 kRefCountedLifetime, |
| 134 kGarbageCollectedLifetime, |
| 135 }; |
| 136 template <typename T> |
| 137 struct LifetimeOf { |
| 138 private: |
| 139 // Okay to rename |isGarbageCollected| to |kIsGarbageCollected|. |
| 140 static const bool kIsGarbageCollected = true; |
| 141 |
| 142 public: |
| 143 // Expecting no rename of |value|. |
| 144 static const LifetimeManagementType value = |
| 145 !kIsGarbageCollected ? kRefCountedLifetime : kGarbageCollectedLifetime; |
| 146 }; |
| 147 |
96 }; // namespace WTF | 148 }; // namespace WTF |
97 | 149 |
98 void F() { | 150 void F() { |
99 // Test that references to a static field are correctly rewritten. | 151 // Test that references to a static field are correctly rewritten. |
100 blink::C::instance_count_++; | 152 blink::C::instance_count_++; |
101 // Force instantiation of a copy constructor for blink::C to make sure field | 153 // Force instantiation of a copy constructor for blink::C to make sure field |
102 // initializers for synthesized functions don't cause weird rewrites. | 154 // initializers for synthesized functions don't cause weird rewrites. |
103 blink::C c; | 155 blink::C c; |
104 blink::C c2 = c; | 156 blink::C c2 = c; |
105 | 157 |
106 bool b1 = WTF::TypeTrait1::value; | 158 bool b1 = WTF::TypeTrait1::value; |
107 bool b2 = WTF::TypeTrait2<void>::value; | 159 bool b2 = WTF::TypeTrait2<void>::value; |
108 } | 160 } |
OLD | NEW |