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

Side by Side Diff: Source/platform/heap/Handle.h

Issue 1332743002: Generalize ScopedDisposal<T> to handle non-GC types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 | 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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 private: 888 private:
889 889
890 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \ 890 #define DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(type) \
891 type::~type() { } 891 type::~type() { }
892 892
893 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \ 893 #define DEFINE_STATIC_REF_WILL_BE_PERSISTENT(type, name, arguments) \
894 DEFINE_STATIC_REF(type, name, arguments) 894 DEFINE_STATIC_REF(type, name, arguments)
895 895
896 #endif // ENABLE(OILPAN) 896 #endif // ENABLE(OILPAN)
897 897
898 template<typename T, bool = IsGarbageCollectedType<T>::value>
899 class PointerFieldStorageTrait {
900 public:
901 using Type = RawPtr<T>;
902 };
903
904 template<typename T>
905 class PointerFieldStorageTrait<T, true> {
906 public:
907 using Type = Member<T>;
908 };
909
898 // Abstraction for injecting calls to an object's 'dispose()' method 910 // Abstraction for injecting calls to an object's 'dispose()' method
899 // on leaving a stack scope, ensuring earlier release of resources 911 // on leaving a stack scope, ensuring earlier release of resources
900 // than waiting until the object is eventually GCed. 912 // than waiting until the object is eventually GCed.
901 template<typename T> 913 template<typename T, void (T::*Disposer)() = (&T::dispose)>
902 class ScopedDisposal { 914 class ScopedDisposal {
903 STACK_ALLOCATED(); 915 STACK_ALLOCATED();
904 public: 916 public:
905 ScopedDisposal(T* object) 917 ScopedDisposal(T* object)
906 : m_object(object) 918 : m_object(object)
907 { 919 {
908 static_assert(IsGarbageCollectedType<T>::value, "can only be used with g arbage collected types");
909 } 920 }
910 921
911 ~ScopedDisposal() 922 ~ScopedDisposal()
912 { 923 {
913 if (m_object) 924 if (m_object)
914 m_object->dispose(); 925 (m_object->*Disposer)();
915 } 926 }
916 927
917 void clear() { m_object.clear(); } 928 void clear() { m_object.clear(); }
918 929
919 private: 930 private:
920 Member<T> m_object; 931 typename PointerFieldStorageTrait<T>::Type m_object;
921 }; 932 };
922 933
923 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep 934 // SelfKeepAlive<Object> is the idiom to use for objects that have to keep
924 // themselves temporarily alive and cannot rely on there being some 935 // themselves temporarily alive and cannot rely on there being some
925 // external reference in that interval: 936 // external reference in that interval:
926 // 937 //
927 // class Opener { 938 // class Opener {
928 // public: 939 // public:
929 // ... 940 // ...
930 // void open() 941 // void open()
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent. 1211 // TODO(sof): extend WTF::FunctionWrapper call overloading to also handle (C rossThread)WeakPersistent.
1201 static T* unwrap(const StorageType& value) { return value.get(); } 1212 static T* unwrap(const StorageType& value) { return value.get(); }
1202 }; 1213 };
1203 1214
1204 template<typename T> 1215 template<typename T>
1205 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete; 1216 PassRefPtr<T> adoptRef(blink::RefCountedGarbageCollected<T>*) = delete;
1206 1217
1207 } // namespace WTF 1218 } // namespace WTF
1208 1219
1209 #endif 1220 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698