OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/inspector/v8-debugger.h" | 5 #include "src/inspector/v8-debugger.h" |
6 | 6 |
7 #include "src/inspector/debugger-script.h" | 7 #include "src/inspector/debugger-script.h" |
8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
10 #include "src/inspector/script-breakpoint.h" | 10 #include "src/inspector/script-breakpoint.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 int contextGroupId = inspector->contextGroupId(contextId); | 40 int contextGroupId = inspector->contextGroupId(contextId); |
41 if (!contextGroupId) return nullptr; | 41 if (!contextGroupId) return nullptr; |
42 return inspector->enabledDebuggerAgentForGroup(contextGroupId); | 42 return inspector->enabledDebuggerAgentForGroup(contextGroupId); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 static bool inLiveEditScope = false; | 47 static bool inLiveEditScope = false; |
48 | 48 |
49 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( | 49 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( |
50 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { | 50 const char* functionName, int argc, v8::Local<v8::Value> argv[], |
| 51 bool catchExceptions) { |
51 v8::MicrotasksScope microtasks(m_isolate, | 52 v8::MicrotasksScope microtasks(m_isolate, |
52 v8::MicrotasksScope::kDoNotRunMicrotasks); | 53 v8::MicrotasksScope::kDoNotRunMicrotasks); |
53 DCHECK(m_isolate->InContext()); | 54 DCHECK(m_isolate->InContext()); |
54 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | 55 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
55 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); | 56 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); |
56 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( | 57 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( |
57 debuggerScript | 58 debuggerScript |
58 ->Get(context, toV8StringInternalized(m_isolate, functionName)) | 59 ->Get(context, toV8StringInternalized(m_isolate, functionName)) |
59 .ToLocalChecked()); | 60 .ToLocalChecked()); |
60 v8::TryCatch try_catch(m_isolate); | 61 if (catchExceptions) { |
| 62 v8::TryCatch try_catch(m_isolate); |
| 63 return function->Call(context, debuggerScript, argc, argv); |
| 64 } |
61 return function->Call(context, debuggerScript, argc, argv); | 65 return function->Call(context, debuggerScript, argc, argv); |
62 } | 66 } |
63 | 67 |
64 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) | 68 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) |
65 : m_isolate(isolate), | 69 : m_isolate(isolate), |
66 m_inspector(inspector), | 70 m_inspector(inspector), |
67 m_enableCount(0), | 71 m_enableCount(0), |
68 m_breakpointsActivated(true), | 72 m_breakpointsActivated(true), |
69 m_runningNestedMessageLoop(false), | 73 m_runningNestedMessageLoop(false), |
70 m_ignoreScriptParsedEventsCounter(0), | 74 m_ignoreScriptParsedEventsCounter(0), |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 342 |
339 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, | 343 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, |
340 v8Boolean(dryRun, m_isolate)}; | 344 v8Boolean(dryRun, m_isolate)}; |
341 | 345 |
342 v8::Local<v8::Value> v8result; | 346 v8::Local<v8::Value> v8result; |
343 { | 347 { |
344 EnableLiveEditScope enableLiveEditScope(m_isolate); | 348 EnableLiveEditScope enableLiveEditScope(m_isolate); |
345 v8::TryCatch tryCatch(m_isolate); | 349 v8::TryCatch tryCatch(m_isolate); |
346 tryCatch.SetVerbose(false); | 350 tryCatch.SetVerbose(false); |
347 v8::MaybeLocal<v8::Value> maybeResult = | 351 v8::MaybeLocal<v8::Value> maybeResult = |
348 callDebuggerMethod("liveEditScriptSource", 3, argv); | 352 callDebuggerMethod("liveEditScriptSource", 3, argv, false); |
349 if (tryCatch.HasCaught()) { | 353 if (tryCatch.HasCaught()) { |
350 v8::Local<v8::Message> message = tryCatch.Message(); | 354 v8::Local<v8::Message> message = tryCatch.Message(); |
351 if (!message.IsEmpty()) | 355 if (!message.IsEmpty()) |
352 return Response::Error(toProtocolStringWithTypeCheck(message->Get())); | 356 return Response::Error(toProtocolStringWithTypeCheck(message->Get())); |
353 else | 357 else |
354 return Response::InternalError(); | 358 return Response::InternalError(); |
355 } | 359 } |
356 v8result = maybeResult.ToLocalChecked(); | 360 v8result = maybeResult.ToLocalChecked(); |
357 } | 361 } |
358 DCHECK(!v8result.IsEmpty()); | 362 DCHECK(!v8result.IsEmpty()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 ->Get(debuggerContext(), | 419 ->Get(debuggerContext(), |
416 toV8StringInternalized(m_isolate, "currentCallFrames")) | 420 toV8StringInternalized(m_isolate, "currentCallFrames")) |
417 .ToLocalChecked()); | 421 .ToLocalChecked()); |
418 if (!v8::debug::Call(debuggerContext(), currentCallFramesFunction, | 422 if (!v8::debug::Call(debuggerContext(), currentCallFramesFunction, |
419 v8::Integer::New(m_isolate, limit)) | 423 v8::Integer::New(m_isolate, limit)) |
420 .ToLocal(¤tCallFramesV8)) | 424 .ToLocal(¤tCallFramesV8)) |
421 return JavaScriptCallFrames(); | 425 return JavaScriptCallFrames(); |
422 } else { | 426 } else { |
423 v8::Local<v8::Value> argv[] = {m_executionState, | 427 v8::Local<v8::Value> argv[] = {m_executionState, |
424 v8::Integer::New(m_isolate, limit)}; | 428 v8::Integer::New(m_isolate, limit)}; |
425 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv) | 429 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv, true) |
426 .ToLocal(¤tCallFramesV8)) | 430 .ToLocal(¤tCallFramesV8)) |
427 return JavaScriptCallFrames(); | 431 return JavaScriptCallFrames(); |
428 } | 432 } |
429 DCHECK(!currentCallFramesV8.IsEmpty()); | 433 DCHECK(!currentCallFramesV8.IsEmpty()); |
430 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); | 434 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); |
431 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); | 435 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); |
432 JavaScriptCallFrames callFrames; | 436 JavaScriptCallFrames callFrames; |
433 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { | 437 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { |
434 v8::Local<v8::Value> callFrameValue; | 438 v8::Local<v8::Value> callFrameValue; |
435 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) | 439 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 V8DebuggerScript::Create(m_isolate, script, inLiveEditScope), | 533 V8DebuggerScript::Create(m_isolate, script, inLiveEditScope), |
530 !has_compile_error); | 534 !has_compile_error); |
531 } | 535 } |
532 } | 536 } |
533 | 537 |
534 void V8Debugger::BreakProgramRequested(v8::Local<v8::Context> pausedContext, | 538 void V8Debugger::BreakProgramRequested(v8::Local<v8::Context> pausedContext, |
535 v8::Local<v8::Object> execState, | 539 v8::Local<v8::Object> execState, |
536 v8::Local<v8::Value> breakPointsHit) { | 540 v8::Local<v8::Value> breakPointsHit) { |
537 v8::Local<v8::Value> argv[] = {breakPointsHit}; | 541 v8::Local<v8::Value> argv[] = {breakPointsHit}; |
538 v8::Local<v8::Value> hitBreakpoints; | 542 v8::Local<v8::Value> hitBreakpoints; |
539 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv) | 543 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv, true) |
540 .ToLocal(&hitBreakpoints)) { | 544 .ToLocal(&hitBreakpoints)) { |
541 return; | 545 return; |
542 } | 546 } |
543 DCHECK(hitBreakpoints->IsArray()); | 547 DCHECK(hitBreakpoints->IsArray()); |
544 handleProgramBreak(pausedContext, execState, v8::Local<v8::Value>(), | 548 handleProgramBreak(pausedContext, execState, v8::Local<v8::Value>(), |
545 hitBreakpoints.As<v8::Array>()); | 549 hitBreakpoints.As<v8::Array>()); |
546 } | 550 } |
547 | 551 |
548 void V8Debugger::ExceptionThrown(v8::Local<v8::Context> pausedContext, | 552 void V8Debugger::ExceptionThrown(v8::Local<v8::Context> pausedContext, |
549 v8::Local<v8::Object> execState, | 553 v8::Local<v8::Object> execState, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 const char* debuggerMethod = nullptr; | 645 const char* debuggerMethod = nullptr; |
642 switch (kind) { | 646 switch (kind) { |
643 case FUNCTION: | 647 case FUNCTION: |
644 debuggerMethod = "getFunctionScopes"; | 648 debuggerMethod = "getFunctionScopes"; |
645 break; | 649 break; |
646 case GENERATOR: | 650 case GENERATOR: |
647 debuggerMethod = "getGeneratorScopes"; | 651 debuggerMethod = "getGeneratorScopes"; |
648 break; | 652 break; |
649 } | 653 } |
650 | 654 |
651 if (!callDebuggerMethod(debuggerMethod, 1, argv).ToLocal(&scopesValue)) | 655 if (!callDebuggerMethod(debuggerMethod, 1, argv, true).ToLocal(&scopesValue)) |
652 return v8::MaybeLocal<v8::Value>(); | 656 return v8::MaybeLocal<v8::Value>(); |
653 v8::Local<v8::Value> copied; | 657 v8::Local<v8::Value> copied; |
654 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, | 658 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, |
655 scopesValue) | 659 scopesValue) |
656 .ToLocal(&copied) || | 660 .ToLocal(&copied) || |
657 !copied->IsArray()) | 661 !copied->IsArray()) |
658 return v8::MaybeLocal<v8::Value>(); | 662 return v8::MaybeLocal<v8::Value>(); |
659 if (!markAsInternal(context, v8::Local<v8::Array>::Cast(copied), | 663 if (!markAsInternal(context, v8::Local<v8::Array>::Cast(copied), |
660 V8InternalValueType::kScopeList)) | 664 V8InternalValueType::kScopeList)) |
661 return v8::MaybeLocal<v8::Value>(); | 665 return v8::MaybeLocal<v8::Value>(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 742 } |
739 | 743 |
740 v8::Local<v8::Value> V8Debugger::collectionEntries( | 744 v8::Local<v8::Value> V8Debugger::collectionEntries( |
741 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { | 745 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { |
742 if (!enabled()) { | 746 if (!enabled()) { |
743 UNREACHABLE(); | 747 UNREACHABLE(); |
744 return v8::Undefined(m_isolate); | 748 return v8::Undefined(m_isolate); |
745 } | 749 } |
746 v8::Local<v8::Value> argv[] = {object}; | 750 v8::Local<v8::Value> argv[] = {object}; |
747 v8::Local<v8::Value> entriesValue; | 751 v8::Local<v8::Value> entriesValue; |
748 if (!callDebuggerMethod("getCollectionEntries", 1, argv) | 752 if (!callDebuggerMethod("getCollectionEntries", 1, argv, true) |
749 .ToLocal(&entriesValue) || | 753 .ToLocal(&entriesValue) || |
750 !entriesValue->IsArray()) | 754 !entriesValue->IsArray()) |
751 return v8::Undefined(m_isolate); | 755 return v8::Undefined(m_isolate); |
752 | 756 |
753 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); | 757 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); |
754 v8::Local<v8::Array> copiedArray = | 758 v8::Local<v8::Array> copiedArray = |
755 v8::Array::New(m_isolate, entries->Length()); | 759 v8::Array::New(m_isolate, entries->Length()); |
756 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 760 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
757 return v8::Undefined(m_isolate); | 761 return v8::Undefined(m_isolate); |
758 for (uint32_t i = 0; i < entries->Length(); ++i) { | 762 for (uint32_t i = 0; i < entries->Length(); ++i) { |
(...skipping 17 matching lines...) Expand all Loading... |
776 | 780 |
777 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( | 781 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( |
778 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { | 782 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { |
779 if (!enabled()) { | 783 if (!enabled()) { |
780 UNREACHABLE(); | 784 UNREACHABLE(); |
781 return v8::Null(m_isolate); | 785 return v8::Null(m_isolate); |
782 } | 786 } |
783 v8::Local<v8::Value> argv[] = {object}; | 787 v8::Local<v8::Value> argv[] = {object}; |
784 v8::Local<v8::Value> location; | 788 v8::Local<v8::Value> location; |
785 v8::Local<v8::Value> copied; | 789 v8::Local<v8::Value> copied; |
786 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv) | 790 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv, true) |
787 .ToLocal(&location) || | 791 .ToLocal(&location) || |
788 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, | 792 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, |
789 location) | 793 location) |
790 .ToLocal(&copied) || | 794 .ToLocal(&copied) || |
791 !copied->IsObject()) | 795 !copied->IsObject()) |
792 return v8::Null(m_isolate); | 796 return v8::Null(m_isolate); |
793 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), | 797 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), |
794 V8InternalValueType::kLocation)) | 798 V8InternalValueType::kLocation)) |
795 return v8::Null(m_isolate); | 799 return v8::Null(m_isolate); |
796 return copied; | 800 return copied; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 966 |
963 size_t stackSize = | 967 size_t stackSize = |
964 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 968 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
965 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 969 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
966 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 970 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
967 | 971 |
968 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 972 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
969 } | 973 } |
970 | 974 |
971 } // namespace v8_inspector | 975 } // namespace v8_inspector |
OLD | NEW |