Commit c27da0c9 authored by jochen@chromium.org's avatar jochen@chromium.org

Remove static CallCompletedCallback handlers

BUG=none
R=svenpanne@chromium.org
LOG=y

Review URL: https://codereview.chromium.org/249313002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20985 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8795d02b
...@@ -4745,24 +4745,6 @@ class V8_EXPORT V8 { ...@@ -4745,24 +4745,6 @@ class V8_EXPORT V8 {
*/ */
static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback); static void RemoveMemoryAllocationCallback(MemoryAllocationCallback callback);
/**
* Adds a callback to notify the host application when a script finished
* running. If a script re-enters the runtime during executing, the
* CallCompletedCallback is only invoked when the outer-most script
* execution ends. Executing scripts inside the callback do not trigger
* further callbacks.
*
* Will be deprecated soon. Use Isolate::AddCallCompletedCallback.
*/
static void AddCallCompletedCallback(CallCompletedCallback callback);
/**
* Removes callback that was installed by AddCallCompletedCallback.
*
* Will be deprecated soon. Use Isolate::RemoveCallCompletedCallback.
*/
static void RemoveCallCompletedCallback(CallCompletedCallback callback);
/** /**
* Experimental: Runs the Microtask Work Queue until empty * Experimental: Runs the Microtask Work Queue until empty
*/ */
......
...@@ -106,7 +106,7 @@ namespace v8 { ...@@ -106,7 +106,7 @@ namespace v8 {
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \ #define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \
EXCEPTION_BAILOUT_CHECK_GENERIC( \ EXCEPTION_BAILOUT_CHECK_GENERIC( \
isolate, value, i::V8::FireCallCompletedCallback(isolate);) isolate, value, isolate->FireCallCompletedCallback();)
#define EXCEPTION_BAILOUT_CHECK(isolate, value) \ #define EXCEPTION_BAILOUT_CHECK(isolate, value) \
...@@ -6491,12 +6491,6 @@ void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) { ...@@ -6491,12 +6491,6 @@ void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
} }
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
if (callback == NULL) return;
i::V8::AddCallCompletedCallback(callback);
}
void V8::RunMicrotasks(Isolate* isolate) { void V8::RunMicrotasks(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::HandleScope scope(i_isolate); i::HandleScope scope(i_isolate);
...@@ -6516,11 +6510,6 @@ void V8::SetAutorunMicrotasks(Isolate* isolate, bool autorun) { ...@@ -6516,11 +6510,6 @@ void V8::SetAutorunMicrotasks(Isolate* isolate, bool autorun) {
} }
void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) {
i::V8::RemoveCallCompletedCallback(callback);
}
void V8::TerminateExecution(Isolate* isolate) { void V8::TerminateExecution(Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution(); reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
} }
...@@ -6669,14 +6658,14 @@ void Isolate::SetEventLogger(LogEventCallback that) { ...@@ -6669,14 +6658,14 @@ void Isolate::SetEventLogger(LogEventCallback that) {
void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) { void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
if (callback == NULL) return; if (callback == NULL) return;
// TODO(jochen): Make this per isolate. i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::V8::AddCallCompletedCallback(callback); isolate->AddCallCompletedCallback(callback);
} }
void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) { void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
// TODO(jochen): Make this per isolate. i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::V8::RemoveCallCompletedCallback(callback); isolate->RemoveCallCompletedCallback(callback);
} }
......
...@@ -2243,4 +2243,37 @@ Handle<JSObject> Isolate::GetSymbolRegistry() { ...@@ -2243,4 +2243,37 @@ Handle<JSObject> Isolate::GetSymbolRegistry() {
} }
void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
if (callback == call_completed_callbacks_.at(i)) return;
}
call_completed_callbacks_.Add(callback);
}
void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
if (callback == call_completed_callbacks_.at(i)) {
call_completed_callbacks_.Remove(i);
}
}
}
void Isolate::FireCallCompletedCallback() {
bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty();
bool run_microtasks = autorun_microtasks() && microtask_pending();
if (!has_call_completed_callbacks && !run_microtasks) return;
if (!handle_scope_implementer()->CallDepthIsZero()) return;
// Fire callbacks. Increase call depth to prevent recursive callbacks.
handle_scope_implementer()->IncrementCallDepth();
if (run_microtasks) Execution::RunMicrotasks(this);
for (int i = 0; i < call_completed_callbacks_.length(); i++) {
call_completed_callbacks_.at(i)();
}
handle_scope_implementer()->DecrementCallDepth();
}
} } // namespace v8::internal } } // namespace v8::internal
...@@ -1096,6 +1096,10 @@ class Isolate { ...@@ -1096,6 +1096,10 @@ class Isolate {
// Get (and lazily initialize) the registry for per-isolate symbols. // Get (and lazily initialize) the registry for per-isolate symbols.
Handle<JSObject> GetSymbolRegistry(); Handle<JSObject> GetSymbolRegistry();
void AddCallCompletedCallback(CallCompletedCallback callback);
void RemoveCallCompletedCallback(CallCompletedCallback callback);
void FireCallCompletedCallback();
private: private:
Isolate(); Isolate();
...@@ -1314,6 +1318,9 @@ class Isolate { ...@@ -1314,6 +1318,9 @@ class Isolate {
int next_optimization_id_; int next_optimization_id_;
// List of callbacks when a Call completes.
List<CallCompletedCallback> call_completed_callbacks_;
friend class ExecutionAccess; friend class ExecutionAccess;
friend class HandleScopeImplementer; friend class HandleScopeImplementer;
friend class IsolateInitializer; friend class IsolateInitializer;
......
...@@ -53,7 +53,6 @@ namespace internal { ...@@ -53,7 +53,6 @@ namespace internal {
V8_DECLARE_ONCE(init_once); V8_DECLARE_ONCE(init_once);
List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
v8::Platform* V8::platform_ = NULL; v8::Platform* V8::platform_ = NULL;
...@@ -94,9 +93,6 @@ void V8::TearDown() { ...@@ -94,9 +93,6 @@ void V8::TearDown() {
RegisteredExtension::UnregisterAll(); RegisteredExtension::UnregisterAll();
Isolate::GlobalTearDown(); Isolate::GlobalTearDown();
delete call_completed_callbacks_;
call_completed_callbacks_ = NULL;
Sampler::TearDown(); Sampler::TearDown();
Serializer::TearDown(); Serializer::TearDown();
...@@ -114,48 +110,6 @@ void V8::SetReturnAddressLocationResolver( ...@@ -114,48 +110,6 @@ void V8::SetReturnAddressLocationResolver(
} }
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) {
bool has_call_completed_callbacks = call_completed_callbacks_ != NULL;
bool run_microtasks = isolate->autorun_microtasks() &&
isolate->microtask_pending();
if (!has_call_completed_callbacks && !run_microtasks) 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();
if (run_microtasks) Execution::RunMicrotasks(isolate);
if (has_call_completed_callbacks) {
for (int i = 0; i < call_completed_callbacks_->length(); i++) {
call_completed_callbacks_->at(i)();
}
}
handle_scope_implementer->DecrementCallDepth();
}
void V8::RunMicrotasks(Isolate* isolate) { void V8::RunMicrotasks(Isolate* isolate) {
if (!isolate->microtask_pending()) if (!isolate->microtask_pending())
return; return;
......
...@@ -98,10 +98,6 @@ class V8 : public AllStatic { ...@@ -98,10 +98,6 @@ class V8 : public AllStatic {
// Support for entry hooking JITed code. // Support for entry hooking JITed code.
static void SetFunctionEntryHook(FunctionEntryHook entry_hook); static void SetFunctionEntryHook(FunctionEntryHook entry_hook);
static void AddCallCompletedCallback(CallCompletedCallback callback);
static void RemoveCallCompletedCallback(CallCompletedCallback callback);
static void FireCallCompletedCallback(Isolate* isolate);
static void RunMicrotasks(Isolate* isolate); static void RunMicrotasks(Isolate* isolate);
static v8::ArrayBuffer::Allocator* ArrayBufferAllocator() { static v8::ArrayBuffer::Allocator* ArrayBufferAllocator() {
...@@ -121,8 +117,6 @@ class V8 : public AllStatic { ...@@ -121,8 +117,6 @@ class V8 : public AllStatic {
static void InitializeOncePerProcessImpl(); static void InitializeOncePerProcessImpl();
static void InitializeOncePerProcess(); static void InitializeOncePerProcess();
// List of callbacks when a Call completes.
static List<CallCompletedCallback>* call_completed_callbacks_;
// Allocator for external array buffers. // Allocator for external array buffers.
static v8::ArrayBuffer::Allocator* array_buffer_allocator_; static v8::ArrayBuffer::Allocator* array_buffer_allocator_;
// v8::Platform to use. // v8::Platform to use.
......
...@@ -20643,9 +20643,9 @@ TEST(CallCompletedCallback) { ...@@ -20643,9 +20643,9 @@ TEST(CallCompletedCallback) {
env->Global()->Set(v8_str("recursion"), env->Global()->Set(v8_str("recursion"),
recursive_runtime->GetFunction()); recursive_runtime->GetFunction());
// Adding the same callback a second time has no effect. // Adding the same callback a second time has no effect.
v8::V8::AddCallCompletedCallback(CallCompletedCallback1); env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
v8::V8::AddCallCompletedCallback(CallCompletedCallback1); env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
v8::V8::AddCallCompletedCallback(CallCompletedCallback2); env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2);
i::OS::Print("--- Script (1) ---\n"); i::OS::Print("--- Script (1) ---\n");
Local<Script> script = v8::Script::Compile( Local<Script> script = v8::Script::Compile(
v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
...@@ -20654,7 +20654,7 @@ TEST(CallCompletedCallback) { ...@@ -20654,7 +20654,7 @@ TEST(CallCompletedCallback) {
i::OS::Print("\n--- Script (2) ---\n"); i::OS::Print("\n--- Script (2) ---\n");
callback_fired = 0; callback_fired = 0;
v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1); env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1);
script->Run(); script->Run();
CHECK_EQ(2, callback_fired); CHECK_EQ(2, callback_fired);
...@@ -20683,7 +20683,7 @@ void CallCompletedCallbackException() { ...@@ -20683,7 +20683,7 @@ void CallCompletedCallbackException() {
TEST(CallCompletedCallbackOneException) { TEST(CallCompletedCallbackOneException) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackNoException);
CompileRun("throw 'exception';"); CompileRun("throw 'exception';");
} }
...@@ -20691,7 +20691,7 @@ TEST(CallCompletedCallbackOneException) { ...@@ -20691,7 +20691,7 @@ TEST(CallCompletedCallbackOneException) {
TEST(CallCompletedCallbackTwoExceptions) { TEST(CallCompletedCallbackTwoExceptions) {
LocalContext env; LocalContext env;
v8::HandleScope scope(env->GetIsolate()); v8::HandleScope scope(env->GetIsolate());
v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackException);
CompileRun("throw 'first exception';"); CompileRun("throw 'first exception';");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment