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/debug/debug.h" | 5 #include "src/debug/debug.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 } | 1715 } |
1716 } // anonymous namespace | 1716 } // anonymous namespace |
1717 | 1717 |
1718 bool Debug::IsExceptionBlackboxed(bool uncaught) { | 1718 bool Debug::IsExceptionBlackboxed(bool uncaught) { |
1719 JavaScriptFrameIterator it(isolate_); | 1719 JavaScriptFrameIterator it(isolate_); |
1720 if (it.done()) return false; | 1720 if (it.done()) return false; |
1721 // Uncaught exception is blackboxed if all current frames are blackboxed, | 1721 // Uncaught exception is blackboxed if all current frames are blackboxed, |
1722 // caught exception if top frame is blackboxed. | 1722 // caught exception if top frame is blackboxed. |
1723 bool is_top_frame_blackboxed = IsFrameBlackboxed(it.frame()); | 1723 bool is_top_frame_blackboxed = IsFrameBlackboxed(it.frame()); |
1724 if (!uncaught || !is_top_frame_blackboxed) return is_top_frame_blackboxed; | 1724 if (!uncaught || !is_top_frame_blackboxed) return is_top_frame_blackboxed; |
1725 it.Advance(); | 1725 return !HasNonBlackboxedFrameOnStack(); |
1726 while (!it.done()) { | |
1727 if (!IsFrameBlackboxed(it.frame())) return false; | |
1728 it.Advance(); | |
1729 } | |
1730 return true; | |
1731 } | 1726 } |
1732 | 1727 |
1733 bool Debug::IsFrameBlackboxed(JavaScriptFrame* frame) { | 1728 bool Debug::IsFrameBlackboxed(JavaScriptFrame* frame) { |
1734 HandleScope scope(isolate_); | 1729 HandleScope scope(isolate_); |
1735 if (!frame->HasInlinedFrames()) { | 1730 if (!frame->HasInlinedFrames()) { |
1736 Handle<SharedFunctionInfo> shared(frame->function()->shared(), isolate_); | 1731 Handle<SharedFunctionInfo> shared(frame->function()->shared(), isolate_); |
1737 return IsBlackboxed(shared); | 1732 return IsBlackboxed(shared); |
1738 } | 1733 } |
1739 List<Handle<SharedFunctionInfo>> infos; | 1734 List<Handle<SharedFunctionInfo>> infos; |
1740 frame->GetFunctions(&infos); | 1735 frame->GetFunctions(&infos); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 is_blackboxed = debug_delegate_->IsFunctionBlackboxed( | 1970 is_blackboxed = debug_delegate_->IsFunctionBlackboxed( |
1976 ToApiHandle<debug::Script>(script), start, end); | 1971 ToApiHandle<debug::Script>(script), start, end); |
1977 } | 1972 } |
1978 } | 1973 } |
1979 shared->set_debug_is_blackboxed(is_blackboxed); | 1974 shared->set_debug_is_blackboxed(is_blackboxed); |
1980 shared->set_computed_debug_is_blackboxed(true); | 1975 shared->set_computed_debug_is_blackboxed(true); |
1981 } | 1976 } |
1982 return shared->debug_is_blackboxed(); | 1977 return shared->debug_is_blackboxed(); |
1983 } | 1978 } |
1984 | 1979 |
| 1980 bool Debug::HasPromiseBuiltinOnStack() { |
| 1981 for (JavaScriptFrameIterator it(isolate_); !it.done(); it.Advance()) { |
| 1982 List<SharedFunctionInfo*> raw_shareds; |
| 1983 it.frame()->GetFunctions(&raw_shareds); |
| 1984 for (int i = 0; i < raw_shareds.length(); ++i) { |
| 1985 if (raw_shareds[i]->is_promise_builtin()) return true; |
| 1986 } |
| 1987 } |
| 1988 return false; |
| 1989 } |
| 1990 |
| 1991 bool Debug::HasNonBlackboxedFrameOnStack() { |
| 1992 HandleScope scope(isolate_); |
| 1993 for (StackTraceFrameIterator it(isolate_); !it.done(); it.Advance()) { |
| 1994 if (!it.is_javascript()) continue; |
| 1995 if (!IsFrameBlackboxed(it.javascript_frame())) return true; |
| 1996 } |
| 1997 return false; |
| 1998 } |
| 1999 |
1985 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id, | 2000 void Debug::OnAsyncTaskEvent(debug::PromiseDebugActionType type, int id, |
1986 int parent_id) { | 2001 int parent_id) { |
1987 if (in_debug_scope() || ignore_events()) return; | 2002 if (in_debug_scope() || ignore_events()) return; |
1988 if (!debug_delegate_) return; | 2003 if (!debug_delegate_) return; |
1989 SuppressDebug while_processing(this); | 2004 SuppressDebug while_processing(this); |
1990 DebugScope debug_scope(isolate_->debug()); | 2005 DebugScope debug_scope(isolate_->debug()); |
1991 if (debug_scope.failed()) return; | 2006 if (debug_scope.failed()) return; |
1992 HandleScope scope(isolate_); | 2007 HandleScope scope(isolate_); |
1993 PostponeInterruptsScope no_interrupts(isolate_); | 2008 PostponeInterruptsScope no_interrupts(isolate_); |
1994 DisableBreak no_recursive_break(this); | 2009 DisableBreak no_recursive_break(this); |
1995 debug_delegate_->PromiseEventOccurred(type, id, parent_id); | 2010 // Promise.all and Promise.race implementations use .then internally, |
| 2011 // we don't allow to break on these calls. |
| 2012 bool breakable = type == debug::kDebugPromiseCreated && |
| 2013 !HasPromiseBuiltinOnStack() && |
| 2014 HasNonBlackboxedFrameOnStack(); |
| 2015 debug_delegate_->PromiseEventOccurred( |
| 2016 Utils::ToLocal(debug_scope.GetContext()), type, id, parent_id, breakable); |
1996 } | 2017 } |
1997 | 2018 |
1998 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { | 2019 void Debug::ProcessCompileEvent(v8::DebugEvent event, Handle<Script> script) { |
1999 if (ignore_events()) return; | 2020 if (ignore_events()) return; |
2000 if (script->type() != i::Script::TYPE_NORMAL && | 2021 if (script->type() != i::Script::TYPE_NORMAL && |
2001 script->type() != i::Script::TYPE_WASM) { | 2022 script->type() != i::Script::TYPE_WASM) { |
2002 return; | 2023 return; |
2003 } | 2024 } |
2004 if (!debug_delegate_) return; | 2025 if (!debug_delegate_) return; |
2005 SuppressDebug while_processing(this); | 2026 SuppressDebug while_processing(this); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 DCHECK(isolate_->needs_side_effect_check()); | 2280 DCHECK(isolate_->needs_side_effect_check()); |
2260 if (DebugEvaluate::CallbackHasNoSideEffect(function)) return true; | 2281 if (DebugEvaluate::CallbackHasNoSideEffect(function)) return true; |
2261 side_effect_check_failed_ = true; | 2282 side_effect_check_failed_ = true; |
2262 // Throw an uncatchable termination exception. | 2283 // Throw an uncatchable termination exception. |
2263 isolate_->TerminateExecution(); | 2284 isolate_->TerminateExecution(); |
2264 isolate_->OptionalRescheduleException(false); | 2285 isolate_->OptionalRescheduleException(false); |
2265 return false; | 2286 return false; |
2266 } | 2287 } |
2267 | 2288 |
2268 void LegacyDebugDelegate::PromiseEventOccurred( | 2289 void LegacyDebugDelegate::PromiseEventOccurred( |
2269 v8::debug::PromiseDebugActionType type, int id, int parent_id) { | 2290 v8::Local<v8::Context> context, v8::debug::PromiseDebugActionType type, |
| 2291 int id, int parent_id, bool breakable) { |
2270 Handle<Object> event_data; | 2292 Handle<Object> event_data; |
2271 if (isolate_->debug()->MakeAsyncTaskEvent(type, id).ToHandle(&event_data)) { | 2293 if (isolate_->debug()->MakeAsyncTaskEvent(type, id).ToHandle(&event_data)) { |
2272 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data)); | 2294 ProcessDebugEvent(v8::AsyncTaskEvent, Handle<JSObject>::cast(event_data)); |
2273 } | 2295 } |
2274 } | 2296 } |
2275 | 2297 |
2276 void LegacyDebugDelegate::ScriptCompiled(v8::Local<v8::debug::Script> script, | 2298 void LegacyDebugDelegate::ScriptCompiled(v8::Local<v8::debug::Script> script, |
2277 bool is_compile_error) { | 2299 bool is_compile_error) { |
2278 Handle<Object> event_data; | 2300 Handle<Object> event_data; |
2279 v8::DebugEvent event = is_compile_error ? v8::CompileError : v8::AfterCompile; | 2301 v8::DebugEvent event = is_compile_error ? v8::CompileError : v8::AfterCompile; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 isolate_->Throw(*isolate_->factory()->NewEvalError( | 2435 isolate_->Throw(*isolate_->factory()->NewEvalError( |
2414 MessageTemplate::kNoSideEffectDebugEvaluate)); | 2436 MessageTemplate::kNoSideEffectDebugEvaluate)); |
2415 } | 2437 } |
2416 isolate_->set_needs_side_effect_check(old_needs_side_effect_check_); | 2438 isolate_->set_needs_side_effect_check(old_needs_side_effect_check_); |
2417 isolate_->debug()->UpdateHookOnFunctionCall(); | 2439 isolate_->debug()->UpdateHookOnFunctionCall(); |
2418 isolate_->debug()->side_effect_check_failed_ = false; | 2440 isolate_->debug()->side_effect_check_failed_ = false; |
2419 } | 2441 } |
2420 | 2442 |
2421 } // namespace internal | 2443 } // namespace internal |
2422 } // namespace v8 | 2444 } // namespace v8 |
OLD | NEW |