Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/inspector/v8-debugger.cc

Issue 2669933003: Merged: Fix uncaught exception bug from liveEditScriptSource (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/v8-debugger.h ('k') | test/inspector/debugger/set-script-source-exception.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 28
29 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { 29 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) {
30 return value ? v8::True(isolate) : v8::False(isolate); 30 return value ? v8::True(isolate) : v8::False(isolate);
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 static bool inLiveEditScope = false; 35 static bool inLiveEditScope = false;
36 36
37 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( 37 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod(
38 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { 38 const char* functionName, int argc, v8::Local<v8::Value> argv[],
39 bool catchExceptions) {
39 v8::MicrotasksScope microtasks(m_isolate, 40 v8::MicrotasksScope microtasks(m_isolate,
40 v8::MicrotasksScope::kDoNotRunMicrotasks); 41 v8::MicrotasksScope::kDoNotRunMicrotasks);
41 DCHECK(m_isolate->InContext()); 42 DCHECK(m_isolate->InContext());
42 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 43 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
43 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); 44 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
44 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 45 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
45 debuggerScript 46 debuggerScript
46 ->Get(context, toV8StringInternalized(m_isolate, functionName)) 47 ->Get(context, toV8StringInternalized(m_isolate, functionName))
47 .ToLocalChecked()); 48 .ToLocalChecked());
48 v8::TryCatch try_catch(m_isolate); 49 if (catchExceptions) {
50 v8::TryCatch try_catch(m_isolate);
51 return function->Call(context, debuggerScript, argc, argv);
52 }
49 return function->Call(context, debuggerScript, argc, argv); 53 return function->Call(context, debuggerScript, argc, argv);
50 } 54 }
51 55
52 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) 56 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
53 : m_isolate(isolate), 57 : m_isolate(isolate),
54 m_inspector(inspector), 58 m_inspector(inspector),
55 m_enableCount(0), 59 m_enableCount(0),
56 m_breakpointsActivated(true), 60 m_breakpointsActivated(true),
57 m_runningNestedMessageLoop(false), 61 m_runningNestedMessageLoop(false),
58 m_ignoreScriptParsedEventsCounter(0), 62 m_ignoreScriptParsedEventsCounter(0),
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 335
332 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource, 336 v8::Local<v8::Value> argv[] = {toV8String(m_isolate, sourceID), newSource,
333 v8Boolean(dryRun, m_isolate)}; 337 v8Boolean(dryRun, m_isolate)};
334 338
335 v8::Local<v8::Value> v8result; 339 v8::Local<v8::Value> v8result;
336 { 340 {
337 EnableLiveEditScope enableLiveEditScope(m_isolate); 341 EnableLiveEditScope enableLiveEditScope(m_isolate);
338 v8::TryCatch tryCatch(m_isolate); 342 v8::TryCatch tryCatch(m_isolate);
339 tryCatch.SetVerbose(false); 343 tryCatch.SetVerbose(false);
340 v8::MaybeLocal<v8::Value> maybeResult = 344 v8::MaybeLocal<v8::Value> maybeResult =
341 callDebuggerMethod("liveEditScriptSource", 3, argv); 345 callDebuggerMethod("liveEditScriptSource", 3, argv, false);
342 if (tryCatch.HasCaught()) { 346 if (tryCatch.HasCaught()) {
343 v8::Local<v8::Message> message = tryCatch.Message(); 347 v8::Local<v8::Message> message = tryCatch.Message();
344 if (!message.IsEmpty()) 348 if (!message.IsEmpty())
345 return Response::Error(toProtocolStringWithTypeCheck(message->Get())); 349 return Response::Error(toProtocolStringWithTypeCheck(message->Get()));
346 else 350 else
347 return Response::InternalError(); 351 return Response::InternalError();
348 } 352 }
349 v8result = maybeResult.ToLocalChecked(); 353 v8result = maybeResult.ToLocalChecked();
350 } 354 }
351 DCHECK(!v8result.IsEmpty()); 355 DCHECK(!v8result.IsEmpty());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 ->Get(debuggerContext(), 412 ->Get(debuggerContext(),
409 toV8StringInternalized(m_isolate, "currentCallFrames")) 413 toV8StringInternalized(m_isolate, "currentCallFrames"))
410 .ToLocalChecked()); 414 .ToLocalChecked());
411 if (!v8::debug::Call(debuggerContext(), currentCallFramesFunction, 415 if (!v8::debug::Call(debuggerContext(), currentCallFramesFunction,
412 v8::Integer::New(m_isolate, limit)) 416 v8::Integer::New(m_isolate, limit))
413 .ToLocal(&currentCallFramesV8)) 417 .ToLocal(&currentCallFramesV8))
414 return JavaScriptCallFrames(); 418 return JavaScriptCallFrames();
415 } else { 419 } else {
416 v8::Local<v8::Value> argv[] = {m_executionState, 420 v8::Local<v8::Value> argv[] = {m_executionState,
417 v8::Integer::New(m_isolate, limit)}; 421 v8::Integer::New(m_isolate, limit)};
418 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv) 422 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv, true)
419 .ToLocal(&currentCallFramesV8)) 423 .ToLocal(&currentCallFramesV8))
420 return JavaScriptCallFrames(); 424 return JavaScriptCallFrames();
421 } 425 }
422 DCHECK(!currentCallFramesV8.IsEmpty()); 426 DCHECK(!currentCallFramesV8.IsEmpty());
423 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); 427 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames();
424 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); 428 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>();
425 JavaScriptCallFrames callFrames; 429 JavaScriptCallFrames callFrames;
426 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { 430 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) {
427 v8::Local<v8::Value> callFrameValue; 431 v8::Local<v8::Value> callFrameValue;
428 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) 432 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue))
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); 581 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject();
578 v8::Local<v8::Value> uncaught = 582 v8::Local<v8::Value> uncaught =
579 callInternalGetterFunction(eventData, "uncaught"); 583 callInternalGetterFunction(eventData, "uncaught");
580 bool isUncaught = uncaught->BooleanValue(context).FromJust(); 584 bool isUncaught = uncaught->BooleanValue(context).FromJust();
581 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 585 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
582 exception, v8::Local<v8::Array>(), isPromiseRejection, 586 exception, v8::Local<v8::Array>(), isPromiseRejection,
583 isUncaught); 587 isUncaught);
584 } else if (event == v8::Break) { 588 } else if (event == v8::Break) {
585 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; 589 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()};
586 v8::Local<v8::Value> hitBreakpoints; 590 v8::Local<v8::Value> hitBreakpoints;
587 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv) 591 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv, true)
588 .ToLocal(&hitBreakpoints)) 592 .ToLocal(&hitBreakpoints))
589 return; 593 return;
590 DCHECK(hitBreakpoints->IsArray()); 594 DCHECK(hitBreakpoints->IsArray());
591 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 595 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
592 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); 596 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>());
593 } 597 }
594 } 598 }
595 599
596 void V8Debugger::v8AsyncTaskListener(v8::debug::PromiseDebugActionType type, 600 void V8Debugger::v8AsyncTaskListener(v8::debug::PromiseDebugActionType type,
597 int id, void* data) { 601 int id, void* data) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 const char* debuggerMethod = nullptr; 677 const char* debuggerMethod = nullptr;
674 switch (kind) { 678 switch (kind) {
675 case FUNCTION: 679 case FUNCTION:
676 debuggerMethod = "getFunctionScopes"; 680 debuggerMethod = "getFunctionScopes";
677 break; 681 break;
678 case GENERATOR: 682 case GENERATOR:
679 debuggerMethod = "getGeneratorScopes"; 683 debuggerMethod = "getGeneratorScopes";
680 break; 684 break;
681 } 685 }
682 686
683 if (!callDebuggerMethod(debuggerMethod, 1, argv).ToLocal(&scopesValue)) 687 if (!callDebuggerMethod(debuggerMethod, 1, argv, true).ToLocal(&scopesValue))
684 return v8::MaybeLocal<v8::Value>(); 688 return v8::MaybeLocal<v8::Value>();
685 v8::Local<v8::Value> copied; 689 v8::Local<v8::Value> copied;
686 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, 690 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context,
687 scopesValue) 691 scopesValue)
688 .ToLocal(&copied) || 692 .ToLocal(&copied) ||
689 !copied->IsArray()) 693 !copied->IsArray())
690 return v8::MaybeLocal<v8::Value>(); 694 return v8::MaybeLocal<v8::Value>();
691 if (!markAsInternal(context, v8::Local<v8::Array>::Cast(copied), 695 if (!markAsInternal(context, v8::Local<v8::Array>::Cast(copied),
692 V8InternalValueType::kScopeList)) 696 V8InternalValueType::kScopeList))
693 return v8::MaybeLocal<v8::Value>(); 697 return v8::MaybeLocal<v8::Value>();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 774 }
771 775
772 v8::Local<v8::Value> V8Debugger::collectionEntries( 776 v8::Local<v8::Value> V8Debugger::collectionEntries(
773 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { 777 v8::Local<v8::Context> context, v8::Local<v8::Object> object) {
774 if (!enabled()) { 778 if (!enabled()) {
775 UNREACHABLE(); 779 UNREACHABLE();
776 return v8::Undefined(m_isolate); 780 return v8::Undefined(m_isolate);
777 } 781 }
778 v8::Local<v8::Value> argv[] = {object}; 782 v8::Local<v8::Value> argv[] = {object};
779 v8::Local<v8::Value> entriesValue; 783 v8::Local<v8::Value> entriesValue;
780 if (!callDebuggerMethod("getCollectionEntries", 1, argv) 784 if (!callDebuggerMethod("getCollectionEntries", 1, argv, true)
781 .ToLocal(&entriesValue) || 785 .ToLocal(&entriesValue) ||
782 !entriesValue->IsArray()) 786 !entriesValue->IsArray())
783 return v8::Undefined(m_isolate); 787 return v8::Undefined(m_isolate);
784 788
785 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); 789 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>();
786 v8::Local<v8::Array> copiedArray = 790 v8::Local<v8::Array> copiedArray =
787 v8::Array::New(m_isolate, entries->Length()); 791 v8::Array::New(m_isolate, entries->Length());
788 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) 792 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false))
789 return v8::Undefined(m_isolate); 793 return v8::Undefined(m_isolate);
790 for (uint32_t i = 0; i < entries->Length(); ++i) { 794 for (uint32_t i = 0; i < entries->Length(); ++i) {
(...skipping 17 matching lines...) Expand all
808 812
809 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( 813 v8::Local<v8::Value> V8Debugger::generatorObjectLocation(
810 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { 814 v8::Local<v8::Context> context, v8::Local<v8::Object> object) {
811 if (!enabled()) { 815 if (!enabled()) {
812 UNREACHABLE(); 816 UNREACHABLE();
813 return v8::Null(m_isolate); 817 return v8::Null(m_isolate);
814 } 818 }
815 v8::Local<v8::Value> argv[] = {object}; 819 v8::Local<v8::Value> argv[] = {object};
816 v8::Local<v8::Value> location; 820 v8::Local<v8::Value> location;
817 v8::Local<v8::Value> copied; 821 v8::Local<v8::Value> copied;
818 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv) 822 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv, true)
819 .ToLocal(&location) || 823 .ToLocal(&location) ||
820 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, 824 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context,
821 location) 825 location)
822 .ToLocal(&copied) || 826 .ToLocal(&copied) ||
823 !copied->IsObject()) 827 !copied->IsObject())
824 return v8::Null(m_isolate); 828 return v8::Null(m_isolate);
825 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), 829 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied),
826 V8InternalValueType::kLocation)) 830 V8InternalValueType::kLocation))
827 return v8::Null(m_isolate); 831 return v8::Null(m_isolate);
828 return copied; 832 return copied;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 998
995 size_t stackSize = 999 size_t stackSize =
996 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; 1000 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
997 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) 1001 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId))
998 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; 1002 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
999 1003
1000 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); 1004 return V8StackTraceImpl::capture(this, contextGroupId, stackSize);
1001 } 1005 }
1002 1006
1003 } // namespace v8_inspector 1007 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-debugger.h ('k') | test/inspector/debugger/set-script-source-exception.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698