Index: src/v8.cc |
diff --git a/src/v8.cc b/src/v8.cc |
index 0354fc101a884c902664c14224306ed246ae466e..c882d86f8d9f06c067455edd00edb0e69b7004ca 100644 |
--- a/src/v8.cc |
+++ b/src/v8.cc |
@@ -51,6 +51,7 @@ bool V8::has_been_setup_ = false; |
bool V8::has_been_disposed_ = false; |
bool V8::has_fatal_error_ = false; |
bool V8::use_crankshaft_ = true; |
+List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; |
static Mutex* entropy_mutex = OS::CreateMutex(); |
static EntropySource entropy_source; |
@@ -104,6 +105,9 @@ void V8::TearDown() { |
is_running_ = false; |
has_been_disposed_ = true; |
+ |
+ delete call_completed_callbacks_; |
+ call_completed_callbacks_ = NULL; |
} |
@@ -169,6 +173,41 @@ bool V8::IdleNotification(int hint) { |
} |
+void V8::AddCallCompletedCallback(CallCompletedCallback callback) { |
+ if (call_completed_callbacks_ == NULL) { // Lazy init. |
+ call_completed_callbacks_ = new List<CallCompletedCallback>(); |
+ } |
+ for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
+ if (callback == call_completed_callbacks_->at(i)) return; |
+ } |
+ call_completed_callbacks_->Add(callback); |
+} |
+ |
+ |
+void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { |
+ if (call_completed_callbacks_ == NULL) return; |
+ for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
+ if (callback == call_completed_callbacks_->at(i)) { |
+ call_completed_callbacks_->Remove(i); |
+ } |
+ } |
+} |
+ |
+ |
+void V8::FireCallCompletedCallback(Isolate* isolate) { |
+ if (call_completed_callbacks_ == NULL) return; |
+ HandleScopeImplementer* handle_scope_implementer = |
+ isolate->handle_scope_implementer(); |
+ if (!handle_scope_implementer->CallDepthIsZero()) return; |
+ // Fire callbacks. Increase call depth to prevent recursive callbacks. |
+ handle_scope_implementer->IncrementCallDepth(); |
+ for (int i = 0; i < call_completed_callbacks_->length(); i++) { |
+ call_completed_callbacks_->at(i)(); |
+ } |
+ handle_scope_implementer->DecrementCallDepth(); |
+} |
+ |
+ |
// Use a union type to avoid type-aliasing optimizations in GCC. |
typedef union { |
double double_value; |