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

Side by Side Diff: third_party/WebKit/Source/wtf/TypeTraits.h

Issue 1999343002: Unify and provide one IsGarbageCollectedType<T> implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test 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 | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType) ; 293 static const bool value = sizeof(checkMarker<T>(nullptr)) == sizeof(YesType) ;
294 }; 294 };
295 295
296 template<typename T> 296 template<typename T>
297 class IsGarbageCollectedType { 297 class IsGarbageCollectedType {
298 typedef char YesType; 298 typedef char YesType;
299 typedef struct NoType { 299 typedef struct NoType {
300 char padding[8]; 300 char padding[8];
301 } NoType; 301 } NoType;
302 302
303 static_assert(sizeof(T), "T must be fully defined");
304
305 using NonConstType = typename std::remove_const<T>::type;
303 template <typename U> static YesType checkGarbageCollectedType(typename U::I sGarbageCollectedTypeMarker*); 306 template <typename U> static YesType checkGarbageCollectedType(typename U::I sGarbageCollectedTypeMarker*);
304 template <typename U> static NoType checkGarbageCollectedType(...); 307 template <typename U> static NoType checkGarbageCollectedType(...);
308
309 // Separately check for GarbageCollectedMixin, which declares a different
310 // marker typedef, to avoid resolution ambiguity for cases like
311 // IsGarbageCollectedType<B> over:
312 //
313 // class A : public GarbageCollected<A>, public GarbageCollectedMixin {
314 // USING_GARBAGE_COLLECTED_MIXIN(A);
315 // ...
316 // };
317 // class B : public A, public GarbageCollectedMixin { ... };
318 //
319 template <typename U> static YesType checkGarbageCollectedMixinType(typename U::IsGarbageCollectedMixinMarker*);
320 template <typename U> static NoType checkGarbageCollectedMixinType(...);
305 public: 321 public:
306 static const bool value = (sizeof(YesType) == sizeof(checkGarbageCollectedTy pe<T>(nullptr))); 322 static const bool value = (sizeof(YesType) == sizeof(checkGarbageCollectedTy pe<NonConstType>(nullptr)))
323 || (sizeof(YesType) == sizeof(checkGarbageCollectedMixinType<NonConstTyp e>(nullptr)));
324 };
325
326 template<>
327 class IsGarbageCollectedType<void> {
328 public:
329 static const bool value = false;
307 }; 330 };
308 331
309 template<typename T> 332 template<typename T>
310 class IsPersistentReferenceType { 333 class IsPersistentReferenceType {
311 typedef char YesType; 334 typedef char YesType;
312 typedef struct NoType { 335 typedef struct NoType {
313 char padding[8]; 336 char padding[8];
314 } NoType; 337 } NoType;
315 338
316 template <typename U> static YesType checkPersistentReferenceType(typename U ::IsPersistentReferenceTypeMarker*); 339 template <typename U> static YesType checkPersistentReferenceType(typename U ::IsPersistentReferenceTypeMarker*);
317 template <typename U> static NoType checkPersistentReferenceType(...); 340 template <typename U> static NoType checkPersistentReferenceType(...);
318 public: 341 public:
319 static const bool value = (sizeof(YesType) == sizeof(checkPersistentReferenc eType<T>(nullptr))); 342 static const bool value = (sizeof(YesType) == sizeof(checkPersistentReferenc eType<T>(nullptr)));
320 }; 343 };
321 344
322 template<typename T> 345 template<typename T, bool = std::is_function<typename std::remove_const<typename std::remove_pointer<T>::type>::type>::value || std::is_void<typename std::remov e_const<typename std::remove_pointer<T>::type>::type>::value>
323 class IsPointerToGarbageCollectedType { 346 class IsPointerToGarbageCollectedType {
324 public: 347 public:
325 static const bool value = false; 348 static const bool value = false;
326 }; 349 };
350
327 template<typename T> 351 template<typename T>
328 class IsPointerToGarbageCollectedType<T*> { 352 class IsPointerToGarbageCollectedType<T*, false> {
329 public: 353 public:
330 static const bool value = IsGarbageCollectedType<T>::value; 354 static const bool value = IsGarbageCollectedType<T>::value;
331 }; 355 };
332 356
333 } // namespace WTF 357 } // namespace WTF
334 358
359 using WTF::IsGarbageCollectedType;
360
335 #endif // TypeTraits_h 361 #endif // TypeTraits_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698