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
This commit is contained in:
parent
8795d02bfd
commit
c27da0c9b2
18
include/v8.h
18
include/v8.h
@ -4745,24 +4745,6 @@ class V8_EXPORT V8 {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
21
src/api.cc
21
src/api.cc
@ -106,7 +106,7 @@ namespace v8 {
|
||||
|
||||
#define EXCEPTION_BAILOUT_CHECK_DO_CALLBACK(isolate, value) \
|
||||
EXCEPTION_BAILOUT_CHECK_GENERIC( \
|
||||
isolate, value, i::V8::FireCallCompletedCallback(isolate);)
|
||||
isolate, value, isolate->FireCallCompletedCallback();)
|
||||
|
||||
|
||||
#define EXCEPTION_BAILOUT_CHECK(isolate, value) \
|
||||
@ -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) {
|
||||
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
||||
i::HandleScope scope(i_isolate);
|
||||
@ -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) {
|
||||
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
|
||||
}
|
||||
@ -6669,14 +6658,14 @@ void Isolate::SetEventLogger(LogEventCallback that) {
|
||||
|
||||
void Isolate::AddCallCompletedCallback(CallCompletedCallback callback) {
|
||||
if (callback == NULL) return;
|
||||
// TODO(jochen): Make this per isolate.
|
||||
i::V8::AddCallCompletedCallback(callback);
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
||||
isolate->AddCallCompletedCallback(callback);
|
||||
}
|
||||
|
||||
|
||||
void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
|
||||
// TODO(jochen): Make this per isolate.
|
||||
i::V8::RemoveCallCompletedCallback(callback);
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
|
||||
isolate->RemoveCallCompletedCallback(callback);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -1096,6 +1096,10 @@ class Isolate {
|
||||
// Get (and lazily initialize) the registry for per-isolate symbols.
|
||||
Handle<JSObject> GetSymbolRegistry();
|
||||
|
||||
void AddCallCompletedCallback(CallCompletedCallback callback);
|
||||
void RemoveCallCompletedCallback(CallCompletedCallback callback);
|
||||
void FireCallCompletedCallback();
|
||||
|
||||
private:
|
||||
Isolate();
|
||||
|
||||
@ -1314,6 +1318,9 @@ class Isolate {
|
||||
|
||||
int next_optimization_id_;
|
||||
|
||||
// List of callbacks when a Call completes.
|
||||
List<CallCompletedCallback> call_completed_callbacks_;
|
||||
|
||||
friend class ExecutionAccess;
|
||||
friend class HandleScopeImplementer;
|
||||
friend class IsolateInitializer;
|
||||
|
46
src/v8.cc
46
src/v8.cc
@ -53,7 +53,6 @@ namespace internal {
|
||||
|
||||
V8_DECLARE_ONCE(init_once);
|
||||
|
||||
List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
|
||||
v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL;
|
||||
v8::Platform* V8::platform_ = NULL;
|
||||
|
||||
@ -94,9 +93,6 @@ void V8::TearDown() {
|
||||
RegisteredExtension::UnregisterAll();
|
||||
Isolate::GlobalTearDown();
|
||||
|
||||
delete call_completed_callbacks_;
|
||||
call_completed_callbacks_ = NULL;
|
||||
|
||||
Sampler::TearDown();
|
||||
Serializer::TearDown();
|
||||
|
||||
@ -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) {
|
||||
if (!isolate->microtask_pending())
|
||||
return;
|
||||
|
6
src/v8.h
6
src/v8.h
@ -98,10 +98,6 @@ class V8 : public AllStatic {
|
||||
// Support for entry hooking JITed code.
|
||||
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 v8::ArrayBuffer::Allocator* ArrayBufferAllocator() {
|
||||
@ -121,8 +117,6 @@ class V8 : public AllStatic {
|
||||
static void InitializeOncePerProcessImpl();
|
||||
static void InitializeOncePerProcess();
|
||||
|
||||
// List of callbacks when a Call completes.
|
||||
static List<CallCompletedCallback>* call_completed_callbacks_;
|
||||
// Allocator for external array buffers.
|
||||
static v8::ArrayBuffer::Allocator* array_buffer_allocator_;
|
||||
// v8::Platform to use.
|
||||
|
@ -20643,9 +20643,9 @@ TEST(CallCompletedCallback) {
|
||||
env->Global()->Set(v8_str("recursion"),
|
||||
recursive_runtime->GetFunction());
|
||||
// Adding the same callback a second time has no effect.
|
||||
v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
|
||||
v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
|
||||
v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
|
||||
env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
|
||||
env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
|
||||
env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2);
|
||||
i::OS::Print("--- Script (1) ---\n");
|
||||
Local<Script> script = v8::Script::Compile(
|
||||
v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
|
||||
@ -20654,7 +20654,7 @@ TEST(CallCompletedCallback) {
|
||||
|
||||
i::OS::Print("\n--- Script (2) ---\n");
|
||||
callback_fired = 0;
|
||||
v8::V8::RemoveCallCompletedCallback(CallCompletedCallback1);
|
||||
env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1);
|
||||
script->Run();
|
||||
CHECK_EQ(2, callback_fired);
|
||||
|
||||
@ -20683,7 +20683,7 @@ void CallCompletedCallbackException() {
|
||||
TEST(CallCompletedCallbackOneException) {
|
||||
LocalContext env;
|
||||
v8::HandleScope scope(env->GetIsolate());
|
||||
v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException);
|
||||
env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackNoException);
|
||||
CompileRun("throw 'exception';");
|
||||
}
|
||||
|
||||
@ -20691,7 +20691,7 @@ TEST(CallCompletedCallbackOneException) {
|
||||
TEST(CallCompletedCallbackTwoExceptions) {
|
||||
LocalContext env;
|
||||
v8::HandleScope scope(env->GetIsolate());
|
||||
v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
|
||||
env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallbackException);
|
||||
CompileRun("throw 'first exception';");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user