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

Side by Side Diff: Source/bindings/core/v8/ScriptDebugServer.cpp

Issue 1129473003: DevTools: respond with error when Debugger command is sent to disabled debugger agent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 5 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 DEFINE_TRACE(ScriptDebugServer) 98 DEFINE_TRACE(ScriptDebugServer)
99 { 99 {
100 } 100 }
101 101
102 void ScriptDebugServer::enable() 102 void ScriptDebugServer::enable()
103 { 103 {
104 ASSERT(!enabled()); 104 ASSERT(!enabled());
105 v8::HandleScope scope(m_isolate); 105 v8::HandleScope scope(m_isolate);
106 v8::Debug::SetDebugEventListener(&ScriptDebugServer::v8DebugEventCallback, v 8::External::New(m_isolate, this)); 106 v8::Debug::SetDebugEventListener(&ScriptDebugServer::v8DebugEventCallback, v 8::External::New(m_isolate, this));
107 ensureDebuggerScriptCompiled(); 107 compileDebuggerScript();
108 } 108 }
109 109
110 void ScriptDebugServer::disable() 110 void ScriptDebugServer::disable()
111 { 111 {
112 ASSERT(enabled()); 112 ASSERT(enabled());
113 clearBreakpoints(); 113 clearBreakpoints();
114 clearCompiledScripts(); 114 clearCompiledScripts();
115 m_debuggerScript.Reset(); 115 m_debuggerScript.Reset();
116 v8::Debug::SetDebugEventListener(nullptr); 116 v8::Debug::SetDebugEventListener(nullptr);
117 } 117 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 v8::HandleScope scope(m_isolate); 187 v8::HandleScope scope(m_isolate);
188 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); 188 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
189 v8::Context::Scope contextScope(debuggerContext); 189 v8::Context::Scope contextScope(debuggerContext);
190 190
191 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(deb uggerScriptLocal()->Get(v8InternalizedString("clearBreakpoints"))); 191 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(deb uggerScriptLocal()->Get(v8InternalizedString("clearBreakpoints")));
192 v8::Debug::Call(clearBreakpoints); 192 v8::Debug::Call(clearBreakpoints);
193 } 193 }
194 194
195 void ScriptDebugServer::setBreakpointsActivated(bool activated) 195 void ScriptDebugServer::setBreakpointsActivated(bool activated)
196 { 196 {
197 ensureDebuggerScriptCompiled(); 197 if (!enabled()) {
198 ASSERT_NOT_REACHED();
199 return;
200 }
198 v8::HandleScope scope(m_isolate); 201 v8::HandleScope scope(m_isolate);
199 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); 202 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
200 v8::Context::Scope contextScope(debuggerContext); 203 v8::Context::Scope contextScope(debuggerContext);
201 204
202 v8::Local<v8::Object> info = v8::Object::New(m_isolate); 205 v8::Local<v8::Object> info = v8::Object::New(m_isolate);
203 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ ated)); 206 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ ated));
204 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated"))) ; 207 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated"))) ;
205 v8::Debug::Call(setBreakpointsActivated, info); 208 v8::Debug::Call(setBreakpointsActivated, info);
206 209
207 m_breakpointsActivated = activated; 210 m_breakpointsActivated = activated;
208 } 211 }
209 212
210 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt ate() 213 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt ate()
211 { 214 {
212 ensureDebuggerScriptCompiled(); 215 ASSERT(enabled());
213 v8::HandleScope scope(m_isolate); 216 v8::HandleScope scope(m_isolate);
214 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 217 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
215 218
216 v8::Local<v8::Value> argv[] = { v8Undefined() }; 219 v8::Local<v8::Value> argv[] = { v8Undefined() };
217 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0 , argv).ToLocalChecked(); 220 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0 , argv).ToLocalChecked();
218 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V alue()); 221 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V alue());
219 } 222 }
220 223
221 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn ExceptionsState) 224 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn ExceptionsState)
222 { 225 {
223 ensureDebuggerScriptCompiled(); 226 ASSERT(enabled());
224 v8::HandleScope scope(m_isolate); 227 v8::HandleScope scope(m_isolate);
225 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 228 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
226 229
227 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS tate) }; 230 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS tate) };
228 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); 231 callDebuggerMethod("setPauseOnExceptionsState", 1, argv);
229 } 232 }
230 233
231 void ScriptDebugServer::setPauseOnNextStatement(bool pause) 234 void ScriptDebugServer::setPauseOnNextStatement(bool pause)
232 { 235 {
233 ASSERT(!m_runningNestedMessageLoop); 236 ASSERT(!m_runningNestedMessageLoop);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 ASSERT(isPaused()); 309 ASSERT(isPaused());
307 ASSERT(!m_executionState.IsEmpty()); 310 ASSERT(!m_executionState.IsEmpty());
308 v8::HandleScope handleScope(m_isolate); 311 v8::HandleScope handleScope(m_isolate);
309 v8::Local<v8::Value> argv[] = { m_executionState }; 312 v8::Local<v8::Value> argv[] = { m_executionState };
310 callDebuggerMethod(stepOutV8MethodName, 1, argv); 313 callDebuggerMethod(stepOutV8MethodName, 1, argv);
311 continueProgram(); 314 continueProgram();
312 } 315 }
313 316
314 void ScriptDebugServer::clearStepping() 317 void ScriptDebugServer::clearStepping()
315 { 318 {
316 ensureDebuggerScriptCompiled(); 319 ASSERT(enabled());
317 v8::HandleScope scope(m_isolate); 320 v8::HandleScope scope(m_isolate);
318 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 321 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
319 322
320 v8::Local<v8::Value> argv[] = { v8Undefined() }; 323 v8::Local<v8::Value> argv[] = { v8Undefined() };
321 callDebuggerMethod("clearStepping", 0, argv); 324 callDebuggerMethod("clearStepping", 0, argv);
322 } 325 }
323 326
324 bool ScriptDebugServer::setScriptSource(const String& sourceID, const String& ne wContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSo urceError>& errorData, ScriptValue* newCallFrames, RefPtr<JSONObject>* result) 327 bool ScriptDebugServer::setScriptSource(const String& sourceID, const String& ne wContent, bool preview, String* error, RefPtr<TypeBuilder::Debugger::SetScriptSo urceError>& errorData, ScriptValue* newCallFrames, RefPtr<JSONObject>* result)
325 { 328 {
326 class EnableLiveEditScope { 329 class EnableLiveEditScope {
327 public: 330 public:
328 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); } 331 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); }
329 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; } 332 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; }
330 private: 333 private:
331 v8::Isolate* m_isolate; 334 v8::Isolate* m_isolate;
332 }; 335 };
333 336
334 ensureDebuggerScriptCompiled(); 337 ASSERT(enabled());
335 v8::HandleScope scope(m_isolate); 338 v8::HandleScope scope(m_isolate);
336 339
337 OwnPtr<v8::Context::Scope> contextScope; 340 OwnPtr<v8::Context::Scope> contextScope;
338 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); 341 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
339 if (!isPaused()) 342 if (!isPaused())
340 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext)); 343 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext));
341 344
342 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is olate, newContent), v8Boolean(preview, m_isolate) }; 345 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is olate, newContent), v8Boolean(preview, m_isolate) };
343 346
344 v8::Local<v8::Value> v8result; 347 v8::Local<v8::Value> v8result;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger( m_isolate)->Value()) 671 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger( m_isolate)->Value())
669 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte ger(m_isolate)->Value()) 672 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte ger(m_isolate)->Value())
670 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is olate)->Value()) 673 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is olate)->Value())
671 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger( m_isolate)->Value()) 674 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger( m_isolate)->Value())
672 .setIsContentScript(object->Get(v8InternalizedString("isContentScript")) ->ToBoolean(m_isolate)->Value()) 675 .setIsContentScript(object->Get(v8InternalizedString("isContentScript")) ->ToBoolean(m_isolate)->Value())
673 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript" ))->ToBoolean(m_isolate)->Value()); 676 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript" ))->ToBoolean(m_isolate)->Value());
674 677
675 listener->didParseSource(sourceID, script, compileResult); 678 listener->didParseSource(sourceID, script, compileResult);
676 } 679 }
677 680
678 void ScriptDebugServer::ensureDebuggerScriptCompiled() 681 void ScriptDebugServer::compileDebuggerScript()
679 { 682 {
680 if (!m_debuggerScript.IsEmpty()) 683 if (!m_debuggerScript.IsEmpty()) {
684 ASSERT_NOT_REACHED();
681 return; 685 return;
686 }
682 687
683 v8::HandleScope scope(m_isolate); 688 v8::HandleScope scope(m_isolate);
684 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 689 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
685 v8::Local<v8::Object> value = m_client->compileDebuggerScript(); 690 v8::Local<v8::Object> value = m_client->compileDebuggerScript();
686 if (value.IsEmpty()) 691 if (value.IsEmpty())
687 return; 692 return;
688 m_debuggerScript.Reset(m_isolate, value); 693 m_debuggerScript.Reset(m_isolate, value);
689 } 694 }
690 695
691 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const 696 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const
692 { 697 {
693 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript); 698 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript);
694 } 699 }
695 700
696 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c onst 701 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c onst
697 { 702 {
698 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked(); 703 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked();
699 } 704 }
700 705
701 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f unction) 706 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f unction)
702 { 707 {
703 ensureDebuggerScriptCompiled(); 708 if (!enabled()) {
704 709 ASSERT_NOT_REACHED();
710 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
711 }
705 v8::Local<v8::Value> argv[] = { function }; 712 v8::Local<v8::Value> argv[] = { function };
706 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked(); 713 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked();
707 } 714 }
708 715
709 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj ect>& object) 716 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj ect>& object)
710 { 717 {
711 ensureDebuggerScriptCompiled(); 718 if (!enabled()) {
712 719 ASSERT_NOT_REACHED();
720 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
721 }
713 v8::Local<v8::Value> argv[] = { object }; 722 v8::Local<v8::Value> argv[] = { object };
714 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck ed(); 723 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck ed();
715 } 724 }
716 725
717 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>& object) 726 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>& object)
718 { 727 {
719 ensureDebuggerScriptCompiled(); 728 if (!enabled()) {
720 729 ASSERT_NOT_REACHED();
730 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
731 }
721 v8::Local<v8::Value> argv[] = { object }; 732 v8::Local<v8::Value> argv[] = { object };
722 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); 733 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked();
723 } 734 }
724 735
725 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje ct>& object) 736 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje ct>& object)
726 { 737 {
727 if (m_debuggerScript.IsEmpty()) 738 if (!enabled()) {
739 // FIXME: provide a way to collect internal properties without enabling debugger. See crbug.com/485451
728 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); 740 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
729 741 }
730 v8::Local<v8::Value> argv[] = { object }; 742 v8::Local<v8::Value> argv[] = { object };
731 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked() ; 743 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked() ;
732 } 744 }
733 745
734 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local< v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local <v8::Value> newValue) 746 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local< v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local <v8::Value> newValue)
735 { 747 {
736 if (m_debuggerScript.IsEmpty()) 748 if (m_debuggerScript.IsEmpty()) {
749 ASSERT_NOT_REACHED();
737 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked()); 750 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked());
751 }
738 752
739 v8::Local<v8::Value> argv[] = { 753 v8::Local<v8::Value> argv[] = {
740 functionValue, 754 functionValue,
741 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), 755 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)),
742 v8String(m_isolate, variableName), 756 v8String(m_isolate, variableName),
743 newValue 757 newValue
744 }; 758 };
745 return callDebuggerMethod("setFunctionVariableValue", 4, argv); 759 return callDebuggerMethod("setFunctionVariableValue", 4, argv);
746 } 760 }
747 761
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 *lineNumber = message->GetLineNumber(); 824 *lineNumber = message->GetLineNumber();
811 *columnNumber = message->GetStartColumn(); 825 *columnNumber = message->GetStartColumn();
812 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace (); 826 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace ();
813 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount () > 0) 827 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount () > 0)
814 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace , messageStackTrace->GetFrameCount()); 828 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace , messageStackTrace->GetFrameCount());
815 } 829 }
816 } 830 }
817 } 831 }
818 832
819 } // namespace blink 833 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptDebugServer.h ('k') | Source/core/inspector/InspectorDOMDebuggerAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698