| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 #ifndef V8_UTIL_H_ | 5 #ifndef V8_UTIL_H_ |
| 6 #define V8_UTIL_H_ | 6 #define V8_UTIL_H_ |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 static MapType* MapFromWeakCallbackInfo( | 127 static MapType* MapFromWeakCallbackInfo( |
| 128 const WeakCallbackInfo<WeakCallbackInfoType>& data) { | 128 const WeakCallbackInfo<WeakCallbackInfoType>& data) { |
| 129 return nullptr; | 129 return nullptr; |
| 130 } | 130 } |
| 131 static K KeyFromWeakCallbackInfo( | 131 static K KeyFromWeakCallbackInfo( |
| 132 const WeakCallbackInfo<WeakCallbackInfoType>& data) { | 132 const WeakCallbackInfo<WeakCallbackInfoType>& data) { |
| 133 return K(); | 133 return K(); |
| 134 } | 134 } |
| 135 static void DisposeCallbackData(WeakCallbackInfoType* data) {} | 135 static void DisposeCallbackData(WeakCallbackInfoType* data) {} |
| 136 static void Dispose(Isolate* isolate, Global<V> value, K key) {} | 136 static void Dispose(Isolate* isolate, Global<V> value, K key) {} |
| 137 static void DisposeWeak(Isolate* isolate, |
| 138 const WeakCallbackInfo<WeakCallbackInfoType>& data, |
| 139 K key) {} |
| 137 | 140 |
| 138 private: | 141 private: |
| 139 template <typename T> | 142 template <typename T> |
| 140 struct RemovePointer<T*> { | 143 struct RemovePointer<T*> { |
| 141 typedef T Type; | 144 typedef T Type; |
| 142 }; | 145 }; |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 | 148 |
| 146 /** | 149 /** |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 static Global<V> Release(PersistentContainerValue v) { | 315 static Global<V> Release(PersistentContainerValue v) { |
| 313 Global<V> p; | 316 Global<V> p; |
| 314 p.val_ = FromVal(v); | 317 p.val_ = FromVal(v); |
| 315 if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { | 318 if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { |
| 316 Traits::DisposeCallbackData( | 319 Traits::DisposeCallbackData( |
| 317 p.template ClearWeak<typename Traits::WeakCallbackDataType>()); | 320 p.template ClearWeak<typename Traits::WeakCallbackDataType>()); |
| 318 } | 321 } |
| 319 return p.Pass(); | 322 return p.Pass(); |
| 320 } | 323 } |
| 321 | 324 |
| 325 void RemoveWeak(const K& key) { Traits::Remove(&impl_, key); } |
| 326 |
| 322 private: | 327 private: |
| 323 PersistentValueMapBase(PersistentValueMapBase&); | 328 PersistentValueMapBase(PersistentValueMapBase&); |
| 324 void operator=(PersistentValueMapBase&); | 329 void operator=(PersistentValueMapBase&); |
| 325 | 330 |
| 326 static bool SetReturnValueFromVal(ReturnValue<Value>* returnValue, | 331 static bool SetReturnValueFromVal(ReturnValue<Value>* returnValue, |
| 327 PersistentContainerValue value) { | 332 PersistentContainerValue value) { |
| 328 bool hasValue = value != kPersistentContainerNotFound; | 333 bool hasValue = value != kPersistentContainerNotFound; |
| 329 if (hasValue) { | 334 if (hasValue) { |
| 330 returnValue->SetInternal( | 335 returnValue->SetInternal( |
| 331 *reinterpret_cast<internal::Object**>(FromVal(value))); | 336 *reinterpret_cast<internal::Object**>(FromVal(value))); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 return SetUnique(key, &value); | 467 return SetUnique(key, &value); |
| 463 } | 468 } |
| 464 | 469 |
| 465 private: | 470 private: |
| 466 static void WeakCallback( | 471 static void WeakCallback( |
| 467 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { | 472 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { |
| 468 if (Traits::kCallbackType != kNotWeak) { | 473 if (Traits::kCallbackType != kNotWeak) { |
| 469 GlobalValueMap<K, V, Traits>* persistentValueMap = | 474 GlobalValueMap<K, V, Traits>* persistentValueMap = |
| 470 Traits::MapFromWeakCallbackInfo(data); | 475 Traits::MapFromWeakCallbackInfo(data); |
| 471 K key = Traits::KeyFromWeakCallbackInfo(data); | 476 K key = Traits::KeyFromWeakCallbackInfo(data); |
| 472 Traits::Dispose(data.GetIsolate(), persistentValueMap->Remove(key).Pass(), | 477 persistentValueMap->RemoveWeak(key); |
| 473 key); | 478 Traits::DisposeWeak(data.GetIsolate(), data, key); |
| 474 Traits::DisposeCallbackData(data.GetParameter()); | 479 Traits::DisposeCallbackData(data.GetParameter()); |
| 475 } | 480 } |
| 476 } | 481 } |
| 477 }; | 482 }; |
| 478 | 483 |
| 479 | 484 |
| 480 /** | 485 /** |
| 481 * A map that uses Global as value and std::map as the backing | 486 * A map that uses Global as value and std::map as the backing |
| 482 * implementation. Persistents are held non-weak. | 487 * implementation. Persistents are held non-weak. |
| 483 * | 488 * |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return reinterpret_cast<V*>(v); | 609 return reinterpret_cast<V*>(v); |
| 605 } | 610 } |
| 606 | 611 |
| 607 Isolate* isolate_; | 612 Isolate* isolate_; |
| 608 typename Traits::Impl impl_; | 613 typename Traits::Impl impl_; |
| 609 }; | 614 }; |
| 610 | 615 |
| 611 } // namespace v8 | 616 } // namespace v8 |
| 612 | 617 |
| 613 #endif // V8_UTIL_H | 618 #endif // V8_UTIL_H |
| OLD | NEW |