Changeset 181010 in webkit for trunk/Source/JavaScriptCore/runtime/WeakGCMapInlines.h
- Timestamp:
- Mar 4, 2015, 12:00:00 PM (10 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/runtime/WeakGCMapInlines.h
r181008 r181010 1 1 /* 2 * Copyright (C) 201 0Apple Inc. All rights reserved.2 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef JSWeakObjectMapRefInternal_h27 #define JSWeakObjectMapRefInternal_h26 #ifndef WeakGCMapInlines_h 27 #define WeakGCMapInlines_h 28 28 29 #include "HeapInlines.h" 29 30 #include "WeakGCMap.h" 30 #include <wtf/RefCounted.h>31 31 32 32 namespace JSC { 33 33 34 class JSObject; 35 34 template<typename KeyArg, typename ValueArg, typename HashArg, typename KeyTraitsArg> 35 inline WeakGCMap<KeyArg, ValueArg, HashArg, KeyTraitsArg>::WeakGCMap(VM& vm) 36 : m_vm(vm) 37 { 38 vm.heap.registerWeakGCMap(this, [this]() { 39 pruneStaleEntries(); 40 }); 36 41 } 37 42 38 typedef void (*JSWeakMapDestroyedCallback)(struct OpaqueJSWeakObjectMap*, void*); 43 template<typename KeyArg, typename ValueArg, typename HashArg, typename KeyTraitsArg> 44 inline WeakGCMap<KeyArg, ValueArg, HashArg, KeyTraitsArg>::~WeakGCMap() 45 { 46 m_vm.heap.unregisterWeakGCMap(this); 47 } 39 48 40 typedef JSC::WeakGCMap<void*, JSC::JSObject> WeakMapType; 49 template<typename KeyArg, typename ValueArg, typename HashArg, typename KeyTraitsArg> 50 NEVER_INLINE void WeakGCMap<KeyArg, ValueArg, HashArg, KeyTraitsArg>::pruneStaleEntries() 51 { 52 m_map.removeIf([](typename HashMapType::KeyValuePairType& entry) { 53 return !entry.value; 54 }); 55 } 41 56 42 struct OpaqueJSWeakObjectMap : public RefCounted<OpaqueJSWeakObjectMap> { 43 public: 44 static PassRefPtr<OpaqueJSWeakObjectMap> create(void* data, JSWeakMapDestroyedCallback callback) 45 { 46 return adoptRef(new OpaqueJSWeakObjectMap(data, callback)); 47 } 57 } // namespace JSC 48 58 49 WeakMapType& map() { return m_map; } 50 51 ~OpaqueJSWeakObjectMap() 52 { 53 m_callback(this, m_data); 54 } 55 56 private: 57 OpaqueJSWeakObjectMap(void* data, JSWeakMapDestroyedCallback callback) 58 : m_data(data) 59 , m_callback(callback) 60 { 61 } 62 WeakMapType m_map; 63 void* m_data; 64 JSWeakMapDestroyedCallback m_callback; 65 }; 66 67 68 #endif // JSWeakObjectMapInternal_h 59 #endif // WeakGCMapInlines_h
Note:
See TracChangeset
for help on using the changeset viewer.