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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 thread_local_.last_step_action_ = StepNone; | 561 thread_local_.last_step_action_ = StepNone; |
562 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 562 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
563 thread_local_.step_count_ = 0; | 563 thread_local_.step_count_ = 0; |
564 thread_local_.last_fp_ = 0; | 564 thread_local_.last_fp_ = 0; |
565 thread_local_.queued_step_count_ = 0; | 565 thread_local_.queued_step_count_ = 0; |
566 thread_local_.step_into_fp_ = 0; | 566 thread_local_.step_into_fp_ = 0; |
567 thread_local_.step_out_fp_ = 0; | 567 thread_local_.step_out_fp_ = 0; |
568 // TODO(isolates): frames_are_dropped_? | 568 // TODO(isolates): frames_are_dropped_? |
569 thread_local_.current_debug_scope_ = NULL; | 569 thread_local_.current_debug_scope_ = NULL; |
570 thread_local_.restarter_frame_function_pointer_ = NULL; | 570 thread_local_.restarter_frame_function_pointer_ = NULL; |
571 thread_local_.promise_on_stack_ = NULL; | |
572 } | 571 } |
573 | 572 |
574 | 573 |
575 char* Debug::ArchiveDebug(char* storage) { | 574 char* Debug::ArchiveDebug(char* storage) { |
576 char* to = storage; | 575 char* to = storage; |
577 MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); | 576 MemCopy(to, reinterpret_cast<char*>(&thread_local_), sizeof(ThreadLocal)); |
578 ThreadInit(); | 577 ThreadInit(); |
579 return storage + ArchiveSpacePerThread(); | 578 return storage + ArchiveSpacePerThread(); |
580 } | 579 } |
581 | 580 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 debug_context_ = Handle<Context>::cast( | 847 debug_context_ = Handle<Context>::cast( |
849 isolate_->global_handles()->Create(*context)); | 848 isolate_->global_handles()->Create(*context)); |
850 return true; | 849 return true; |
851 } | 850 } |
852 | 851 |
853 | 852 |
854 void Debug::Unload() { | 853 void Debug::Unload() { |
855 ClearAllBreakPoints(); | 854 ClearAllBreakPoints(); |
856 ClearStepping(); | 855 ClearStepping(); |
857 | 856 |
858 // Match unmatched PopPromise calls. | |
859 while (thread_local_.promise_on_stack_) PopPromise(); | |
860 | |
861 // Return debugger is not loaded. | 857 // Return debugger is not loaded. |
862 if (!is_loaded()) return; | 858 if (!is_loaded()) return; |
863 | 859 |
864 // Clear the script cache. | 860 // Clear the script cache. |
865 if (script_cache_ != NULL) { | 861 if (script_cache_ != NULL) { |
866 delete script_cache_; | 862 delete script_cache_; |
867 script_cache_ = NULL; | 863 script_cache_ = NULL; |
868 } | 864 } |
869 | 865 |
870 // Clear debugger context global handle. | 866 // Clear debugger context global handle. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 | 1261 |
1266 bool Debug::IsBreakOnException(ExceptionBreakType type) { | 1262 bool Debug::IsBreakOnException(ExceptionBreakType type) { |
1267 if (type == BreakUncaughtException) { | 1263 if (type == BreakUncaughtException) { |
1268 return break_on_uncaught_exception_; | 1264 return break_on_uncaught_exception_; |
1269 } else { | 1265 } else { |
1270 return break_on_exception_; | 1266 return break_on_exception_; |
1271 } | 1267 } |
1272 } | 1268 } |
1273 | 1269 |
1274 | 1270 |
1275 PromiseOnStack::PromiseOnStack(Isolate* isolate, PromiseOnStack* prev, | |
1276 Handle<JSObject> promise) | |
1277 : isolate_(isolate), prev_(prev) { | |
1278 handler_ = StackHandler::FromAddress( | |
1279 Isolate::handler(isolate->thread_local_top())); | |
1280 promise_ = | |
1281 Handle<JSObject>::cast(isolate->global_handles()->Create(*promise)); | |
1282 } | |
1283 | |
1284 | |
1285 PromiseOnStack::~PromiseOnStack() { | |
1286 isolate_->global_handles()->Destroy( | |
1287 Handle<Object>::cast(promise_).location()); | |
1288 } | |
1289 | |
1290 | |
1291 void Debug::PushPromise(Handle<JSObject> promise) { | |
1292 PromiseOnStack* prev = thread_local_.promise_on_stack_; | |
1293 thread_local_.promise_on_stack_ = new PromiseOnStack(isolate_, prev, promise); | |
1294 } | |
1295 | |
1296 | |
1297 void Debug::PopPromise() { | |
1298 if (thread_local_.promise_on_stack_ == NULL) return; | |
1299 PromiseOnStack* prev = thread_local_.promise_on_stack_->prev(); | |
1300 delete thread_local_.promise_on_stack_; | |
1301 thread_local_.promise_on_stack_ = prev; | |
1302 } | |
1303 | |
1304 | |
1305 Handle<Object> Debug::GetPromiseOnStackOnThrow() { | |
1306 Handle<Object> undefined = isolate_->factory()->undefined_value(); | |
1307 if (thread_local_.promise_on_stack_ == NULL) return undefined; | |
1308 StackHandler* promise_try = thread_local_.promise_on_stack_->handler(); | |
1309 // Find the top-most try-catch handler. | |
1310 StackHandler* handler = StackHandler::FromAddress( | |
1311 Isolate::handler(isolate_->thread_local_top())); | |
1312 do { | |
1313 if (handler == promise_try) { | |
1314 // Mark the pushed try-catch handler to prevent a later duplicate event | |
1315 // triggered with the following reject. | |
1316 return thread_local_.promise_on_stack_->promise(); | |
1317 } | |
1318 handler = handler->next(); | |
1319 // Throwing inside a Promise can be intercepted by an inner try-catch, so | |
1320 // we stop at the first try-catch handler. | |
1321 } while (handler != NULL && !handler->is_catch()); | |
1322 return undefined; | |
1323 } | |
1324 | |
1325 | |
1326 bool Debug::PromiseHasRejectHandler(Handle<JSObject> promise) { | 1271 bool Debug::PromiseHasRejectHandler(Handle<JSObject> promise) { |
1327 Handle<JSFunction> fun = Handle<JSFunction>::cast( | 1272 Handle<JSFunction> fun = Handle<JSFunction>::cast( |
1328 JSObject::GetDataProperty(isolate_->js_builtins_object(), | 1273 JSObject::GetDataProperty(isolate_->js_builtins_object(), |
1329 isolate_->factory()->NewStringFromStaticAscii( | 1274 isolate_->factory()->NewStringFromStaticAscii( |
1330 "PromiseHasRejectHandler"))); | 1275 "PromiseHasRejectHandler"))); |
1331 Handle<Object> result = | 1276 Handle<Object> result = |
1332 Execution::Call(isolate_, fun, promise, 0, NULL).ToHandleChecked(); | 1277 Execution::Call(isolate_, fun, promise, 0, NULL).ToHandleChecked(); |
1333 return result->IsTrue(); | 1278 return result->IsTrue(); |
1334 } | 1279 } |
1335 | 1280 |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2560 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<JSObject> task_event) { | 2505 MaybeHandle<Object> Debug::MakeAsyncTaskEvent(Handle<JSObject> task_event) { |
2561 // Create the async task event object. | 2506 // Create the async task event object. |
2562 Handle<Object> argv[] = { task_event }; | 2507 Handle<Object> argv[] = { task_event }; |
2563 return MakeJSObject("MakeAsyncTaskEvent", ARRAY_SIZE(argv), argv); | 2508 return MakeJSObject("MakeAsyncTaskEvent", ARRAY_SIZE(argv), argv); |
2564 } | 2509 } |
2565 | 2510 |
2566 | 2511 |
2567 void Debug::OnThrow(Handle<Object> exception, bool uncaught) { | 2512 void Debug::OnThrow(Handle<Object> exception, bool uncaught) { |
2568 if (in_debug_scope() || ignore_events()) return; | 2513 if (in_debug_scope() || ignore_events()) return; |
2569 HandleScope scope(isolate_); | 2514 HandleScope scope(isolate_); |
2570 OnException(exception, uncaught, GetPromiseOnStackOnThrow()); | 2515 OnException(exception, uncaught, isolate_->GetPromiseOnStackOnThrow()); |
2571 } | 2516 } |
2572 | 2517 |
2573 | 2518 |
2574 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { | 2519 void Debug::OnPromiseReject(Handle<JSObject> promise, Handle<Object> value) { |
2575 if (in_debug_scope() || ignore_events()) return; | 2520 if (in_debug_scope() || ignore_events()) return; |
2576 HandleScope scope(isolate_); | 2521 HandleScope scope(isolate_); |
2577 OnException(value, false, promise); | 2522 OnException(value, false, promise); |
2578 } | 2523 } |
2579 | 2524 |
2580 | 2525 |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3416 logger_->DebugEvent("Put", message.text()); | 3361 logger_->DebugEvent("Put", message.text()); |
3417 } | 3362 } |
3418 | 3363 |
3419 | 3364 |
3420 void LockingCommandMessageQueue::Clear() { | 3365 void LockingCommandMessageQueue::Clear() { |
3421 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 3366 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
3422 queue_.Clear(); | 3367 queue_.Clear(); |
3423 } | 3368 } |
3424 | 3369 |
3425 } } // namespace v8::internal | 3370 } } // namespace v8::internal |
OLD | NEW |