OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 3085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3096 | 3096 |
3097 void Debug::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { | 3097 void Debug::EnqueueDebugCommand(v8::Debug::ClientData* client_data) { |
3098 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); | 3098 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); |
3099 event_command_queue_.Put(message); | 3099 event_command_queue_.Put(message); |
3100 | 3100 |
3101 // Set the debug command break flag to have the command processed. | 3101 // Set the debug command break flag to have the command processed. |
3102 if (!in_debug_scope()) isolate_->stack_guard()->RequestDebugCommand(); | 3102 if (!in_debug_scope()) isolate_->stack_guard()->RequestDebugCommand(); |
3103 } | 3103 } |
3104 | 3104 |
3105 | 3105 |
| 3106 void Debug::EnqueueEmbedderTask(v8::Task* task) { |
| 3107 embedder_task_queue_.Enqueue(task); |
| 3108 |
| 3109 // Set the debug command break flag to have the command processed. |
| 3110 if (!in_debug_scope()) { |
| 3111 isolate_->stack_guard()->RequestDebugCommand(); |
| 3112 } |
| 3113 } |
| 3114 |
| 3115 |
| 3116 bool Debug::ProcessEmbedderTasks() { |
| 3117 bool did_process_task = false; |
| 3118 while (v8::Task* task = embedder_task_queue_.Dequeue()) { |
| 3119 did_process_task = true; |
| 3120 task->Run(); |
| 3121 delete task; |
| 3122 } |
| 3123 return did_process_task; |
| 3124 } |
| 3125 |
| 3126 |
3106 MaybeHandle<Object> Debug::Call(Handle<JSFunction> fun, Handle<Object> data) { | 3127 MaybeHandle<Object> Debug::Call(Handle<JSFunction> fun, Handle<Object> data) { |
3107 DebugScope debug_scope(this); | 3128 DebugScope debug_scope(this); |
3108 if (debug_scope.failed()) return isolate_->factory()->undefined_value(); | 3129 if (debug_scope.failed()) return isolate_->factory()->undefined_value(); |
3109 | 3130 |
3110 // Create the execution state. | 3131 // Create the execution state. |
3111 Handle<Object> exec_state; | 3132 Handle<Object> exec_state; |
3112 if (!MakeExecutionState().ToHandle(&exec_state)) { | 3133 if (!MakeExecutionState().ToHandle(&exec_state)) { |
3113 return isolate_->factory()->undefined_value(); | 3134 return isolate_->factory()->undefined_value(); |
3114 } | 3135 } |
3115 | 3136 |
3116 Handle<Object> argv[] = { exec_state, data }; | 3137 Handle<Object> argv[] = { exec_state, data }; |
3117 return Execution::Call( | 3138 return Execution::Call( |
3118 isolate_, | 3139 isolate_, |
3119 fun, | 3140 fun, |
3120 Handle<Object>(debug_context()->global_proxy(), isolate_), | 3141 Handle<Object>(debug_context()->global_proxy(), isolate_), |
3121 arraysize(argv), | 3142 arraysize(argv), |
3122 argv); | 3143 argv); |
3123 } | 3144 } |
3124 | 3145 |
3125 | 3146 |
3126 void Debug::HandleDebugBreak() { | 3147 void Debug::HandleDebugBreak() { |
3127 // Ignore debug break during bootstrapping. | 3148 // Ignore debug break during bootstrapping. |
3128 if (isolate_->bootstrapper()->IsActive()) return; | 3149 if (isolate_->bootstrapper()->IsActive()) return; |
3129 // Just continue if breaks are disabled. | 3150 // Just continue if breaks are disabled. |
3130 if (break_disabled()) return; | 3151 if (break_disabled()) return; |
| 3152 if (ProcessEmbedderTasks()) { |
| 3153 isolate_->stack_guard()->ClearDebugCommand(); |
| 3154 } |
3131 // Ignore debug break if debugger is not active. | 3155 // Ignore debug break if debugger is not active. |
3132 if (!is_active()) return; | 3156 if (!is_active()) return; |
3133 | 3157 |
3134 StackLimitCheck check(isolate_); | 3158 StackLimitCheck check(isolate_); |
3135 if (check.HasOverflowed()) return; | 3159 if (check.HasOverflowed()) return; |
3136 | 3160 |
3137 { JavaScriptFrameIterator it(isolate_); | 3161 { JavaScriptFrameIterator it(isolate_); |
3138 DCHECK(!it.done()); | 3162 DCHECK(!it.done()); |
3139 Object* fun = it.frame()->function(); | 3163 Object* fun = it.frame()->function(); |
3140 if (fun && fun->IsJSFunction()) { | 3164 if (fun && fun->IsJSFunction()) { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3473 queue_.Put(message); | 3497 queue_.Put(message); |
3474 logger_->DebugEvent("Put", message.text()); | 3498 logger_->DebugEvent("Put", message.text()); |
3475 } | 3499 } |
3476 | 3500 |
3477 | 3501 |
3478 void LockingCommandMessageQueue::Clear() { | 3502 void LockingCommandMessageQueue::Clear() { |
3479 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 3503 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
3480 queue_.Clear(); | 3504 queue_.Clear(); |
3481 } | 3505 } |
3482 | 3506 |
| 3507 |
| 3508 LockingTaskQueue::LockingTaskQueue() {} |
| 3509 |
| 3510 |
| 3511 LockingTaskQueue::~LockingTaskQueue() { Clear(); } |
| 3512 |
| 3513 |
| 3514 void LockingTaskQueue::Enqueue(v8::Task* task) { |
| 3515 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 3516 queue_.push(task); |
| 3517 } |
| 3518 |
| 3519 |
| 3520 v8::Task* LockingTaskQueue::Dequeue() { |
| 3521 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 3522 if (queue_.empty()) return NULL; |
| 3523 v8::Task* task = queue_.front(); |
| 3524 queue_.pop(); |
| 3525 return task; |
| 3526 } |
| 3527 |
| 3528 |
| 3529 void LockingTaskQueue::Clear() { |
| 3530 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
| 3531 while (!queue_.empty()) { |
| 3532 delete queue_.front(); |
| 3533 queue_.pop(); |
| 3534 } |
| 3535 } |
3483 } } // namespace v8::internal | 3536 } } // namespace v8::internal |
OLD | NEW |