Chromium Code Reviews| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 static Global<V> Release(PersistentContainerValue v) { | 315 static Global<V> Release(PersistentContainerValue v) { |
| 316 Global<V> p; | 316 Global<V> p; |
| 317 p.val_ = FromVal(v); | 317 p.val_ = FromVal(v); |
| 318 if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { | 318 if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { |
| 319 Traits::DisposeCallbackData( | 319 Traits::DisposeCallbackData( |
| 320 p.template ClearWeak<typename Traits::WeakCallbackDataType>()); | 320 p.template ClearWeak<typename Traits::WeakCallbackDataType>()); |
| 321 } | 321 } |
| 322 return p.Pass(); | 322 return p.Pass(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void RemoveWeak(const K& key) { Traits::Remove(&impl_, key); } | 325 void RemoveWeak(const K& key) { |
| 326 Global<V> p; | |
| 327 p.val_ = FromVal(Traits::Remove(&impl_, key)); | |
| 328 p.Reset(); | |
|
Erik Corry
2015/03/26 10:07:10
Why do we have to create a Global, then immediatel
dcarney
2015/03/26 10:26:56
here nothing is being created. we're just releasi
| |
| 329 } | |
| 326 | 330 |
| 327 private: | 331 private: |
| 328 PersistentValueMapBase(PersistentValueMapBase&); | 332 PersistentValueMapBase(PersistentValueMapBase&); |
| 329 void operator=(PersistentValueMapBase&); | 333 void operator=(PersistentValueMapBase&); |
| 330 | 334 |
| 331 static bool SetReturnValueFromVal(ReturnValue<Value>* returnValue, | 335 static bool SetReturnValueFromVal(ReturnValue<Value>* returnValue, |
| 332 PersistentContainerValue value) { | 336 PersistentContainerValue value) { |
| 333 bool hasValue = value != kPersistentContainerNotFound; | 337 bool hasValue = value != kPersistentContainerNotFound; |
| 334 if (hasValue) { | 338 if (hasValue) { |
| 335 returnValue->SetInternal( | 339 returnValue->SetInternal( |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 | 473 |
| 470 private: | 474 private: |
| 471 static void WeakCallback( | 475 static void WeakCallback( |
| 472 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { | 476 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { |
| 473 if (Traits::kCallbackType != kNotWeak) { | 477 if (Traits::kCallbackType != kNotWeak) { |
| 474 GlobalValueMap<K, V, Traits>* persistentValueMap = | 478 GlobalValueMap<K, V, Traits>* persistentValueMap = |
| 475 Traits::MapFromWeakCallbackInfo(data); | 479 Traits::MapFromWeakCallbackInfo(data); |
| 476 K key = Traits::KeyFromWeakCallbackInfo(data); | 480 K key = Traits::KeyFromWeakCallbackInfo(data); |
| 477 persistentValueMap->RemoveWeak(key); | 481 persistentValueMap->RemoveWeak(key); |
| 478 Traits::DisposeWeak(data.GetIsolate(), data, key); | 482 Traits::DisposeWeak(data.GetIsolate(), data, key); |
| 479 Traits::DisposeCallbackData(data.GetParameter()); | |
| 480 } | 483 } |
| 481 } | 484 } |
| 482 }; | 485 }; |
| 483 | 486 |
| 484 | 487 |
| 485 /** | 488 /** |
| 486 * A map that uses Global as value and std::map as the backing | 489 * A map that uses Global as value and std::map as the backing |
| 487 * implementation. Persistents are held non-weak. | 490 * implementation. Persistents are held non-weak. |
| 488 * | 491 * |
| 489 * C++11 embedders don't need this class, as they can use | 492 * C++11 embedders don't need this class, as they can use |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 return reinterpret_cast<V*>(v); | 612 return reinterpret_cast<V*>(v); |
| 610 } | 613 } |
| 611 | 614 |
| 612 Isolate* isolate_; | 615 Isolate* isolate_; |
| 613 typename Traits::Impl impl_; | 616 typename Traits::Impl impl_; |
| 614 }; | 617 }; |
| 615 | 618 |
| 616 } // namespace v8 | 619 } // namespace v8 |
| 617 | 620 |
| 618 #endif // V8_UTIL_H | 621 #endif // V8_UTIL_H |
| OLD | NEW |