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

Side by Side Diff: include/v8-util.h

Issue 1209403005: Let the second pass phantom callbacks run in a separate task on the foreground thread. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Run second pass callbacks synchronously when GC is forced. Created 5 years, 5 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 | samples/process.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 static MapType* MapFromWeakCallbackInfo( 127 static MapType* MapFromWeakCallbackInfo(
128 const WeakCallbackInfo<WeakCallbackDataType>& data) { 128 const WeakCallbackInfo<WeakCallbackDataType>& data) {
129 return nullptr; 129 return nullptr;
130 } 130 }
131 static K KeyFromWeakCallbackInfo( 131 static K KeyFromWeakCallbackInfo(
132 const WeakCallbackInfo<WeakCallbackDataType>& data) { 132 const WeakCallbackInfo<WeakCallbackDataType>& data) {
133 return K(); 133 return K();
134 } 134 }
135 static void DisposeCallbackData(WeakCallbackDataType* data) {} 135 static void DisposeCallbackData(WeakCallbackDataType* data) {}
136 static void OnWeakCallback(
137 const WeakCallbackInfo<WeakCallbackDataType>& data) {}
136 static void Dispose(Isolate* isolate, Global<V> value, K key) {} 138 static void Dispose(Isolate* isolate, Global<V> value, K key) {}
137 // This is a second pass callback, so SetSecondPassCallback cannot be called. 139 // This is a second pass callback, so SetSecondPassCallback cannot be called.
138 static void DisposeWeak(const WeakCallbackInfo<WeakCallbackDataType>& data) {} 140 static void DisposeWeak(const WeakCallbackInfo<WeakCallbackDataType>& data) {}
139 141
140 private: 142 private:
141 template <typename T> 143 template <typename T>
142 struct RemovePointer<T*> { 144 struct RemovePointer<T*> {
143 typedef T Type; 145 typedef T Type;
144 }; 146 };
145 }; 147 };
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 * by the Traits class. 447 * by the Traits class.
446 */ 448 */
447 Global<V> SetUnique(const K& key, Global<V>* persistent) { 449 Global<V> SetUnique(const K& key, Global<V>* persistent) {
448 if (Traits::kCallbackType != kNotWeak) { 450 if (Traits::kCallbackType != kNotWeak) {
449 WeakCallbackType callback_type = 451 WeakCallbackType callback_type =
450 Traits::kCallbackType == kWeakWithInternalFields 452 Traits::kCallbackType == kWeakWithInternalFields
451 ? WeakCallbackType::kInternalFields 453 ? WeakCallbackType::kInternalFields
452 : WeakCallbackType::kParameter; 454 : WeakCallbackType::kParameter;
453 Local<V> value(Local<V>::New(this->isolate(), *persistent)); 455 Local<V> value(Local<V>::New(this->isolate(), *persistent));
454 persistent->template SetWeak<typename Traits::WeakCallbackDataType>( 456 persistent->template SetWeak<typename Traits::WeakCallbackDataType>(
455 Traits::WeakCallbackParameter(this, key, value), FirstWeakCallback, 457 Traits::WeakCallbackParameter(this, key, value), OnWeakCallback,
456 callback_type); 458 callback_type);
457 } 459 }
458 PersistentContainerValue old_value = 460 PersistentContainerValue old_value =
459 Traits::Set(this->impl(), key, this->ClearAndLeak(persistent)); 461 Traits::Set(this->impl(), key, this->ClearAndLeak(persistent));
460 return this->Release(old_value).Pass(); 462 return this->Release(old_value).Pass();
461 } 463 }
462 464
463 /** 465 /**
464 * Put a value into the map and update the reference. 466 * Put a value into the map and update the reference.
465 * Restrictions of GetReference apply here as well. 467 * Restrictions of GetReference apply here as well.
466 */ 468 */
467 Global<V> Set(const K& key, Global<V> value, 469 Global<V> Set(const K& key, Global<V> value,
468 PersistentValueReference* reference) { 470 PersistentValueReference* reference) {
469 *reference = this->Leak(&value); 471 *reference = this->Leak(&value);
470 return SetUnique(key, &value); 472 return SetUnique(key, &value);
471 } 473 }
472 474
473 private: 475 private:
474 static void FirstWeakCallback( 476 static void OnWeakCallback(
475 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { 477 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) {
476 if (Traits::kCallbackType != kNotWeak) { 478 if (Traits::kCallbackType != kNotWeak) {
477 auto map = Traits::MapFromWeakCallbackInfo(data); 479 auto map = Traits::MapFromWeakCallbackInfo(data);
478 K key = Traits::KeyFromWeakCallbackInfo(data); 480 K key = Traits::KeyFromWeakCallbackInfo(data);
479 map->RemoveWeak(key); 481 map->RemoveWeak(key);
482 Traits::OnWeakCallback(data);
480 data.SetSecondPassCallback(SecondWeakCallback); 483 data.SetSecondPassCallback(SecondWeakCallback);
481 } 484 }
482 } 485 }
483 486
484 static void SecondWeakCallback( 487 static void SecondWeakCallback(
485 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) { 488 const WeakCallbackInfo<typename Traits::WeakCallbackDataType>& data) {
486 Traits::DisposeWeak(data); 489 Traits::DisposeWeak(data);
487 } 490 }
488 }; 491 };
489 492
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 return reinterpret_cast<V*>(v); 634 return reinterpret_cast<V*>(v);
632 } 635 }
633 636
634 Isolate* isolate_; 637 Isolate* isolate_;
635 typename Traits::Impl impl_; 638 typename Traits::Impl impl_;
636 }; 639 };
637 640
638 } // namespace v8 641 } // namespace v8
639 642
640 #endif // V8_UTIL_H 643 #endif // V8_UTIL_H
OLDNEW
« no previous file with comments | « no previous file | samples/process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698