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

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

Issue 1124083003: Revert of DevTools: respond with error when Debugger command is sent to disabled debugger agent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 compileDebuggerScript(); 107 ensureDebuggerScriptCompiled();
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 if (!enabled()) { 197 ensureDebuggerScriptCompiled();
198 ASSERT_NOT_REACHED();
199 return;
200 }
201 v8::HandleScope scope(m_isolate); 198 v8::HandleScope scope(m_isolate);
202 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); 199 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
203 v8::Context::Scope contextScope(debuggerContext); 200 v8::Context::Scope contextScope(debuggerContext);
204 201
205 v8::Local<v8::Object> info = v8::Object::New(m_isolate); 202 v8::Local<v8::Object> info = v8::Object::New(m_isolate);
206 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ ated)); 203 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ ated));
207 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated"))) ; 204 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated"))) ;
208 v8::Debug::Call(setBreakpointsActivated, info); 205 v8::Debug::Call(setBreakpointsActivated, info);
209 206
210 m_breakpointsActivated = activated; 207 m_breakpointsActivated = activated;
211 } 208 }
212 209
213 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt ate() 210 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt ate()
214 { 211 {
215 ASSERT(enabled()); 212 ensureDebuggerScriptCompiled();
216 v8::HandleScope scope(m_isolate); 213 v8::HandleScope scope(m_isolate);
217 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 214 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
218 215
219 v8::Local<v8::Value> argv[] = { v8Undefined() }; 216 v8::Local<v8::Value> argv[] = { v8Undefined() };
220 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0 , argv).ToLocalChecked(); 217 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0 , argv).ToLocalChecked();
221 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V alue()); 218 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V alue());
222 } 219 }
223 220
224 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn ExceptionsState) 221 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn ExceptionsState)
225 { 222 {
226 ASSERT(enabled()); 223 ensureDebuggerScriptCompiled();
227 v8::HandleScope scope(m_isolate); 224 v8::HandleScope scope(m_isolate);
228 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 225 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
229 226
230 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS tate) }; 227 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS tate) };
231 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); 228 callDebuggerMethod("setPauseOnExceptionsState", 1, argv);
232 } 229 }
233 230
234 void ScriptDebugServer::setPauseOnNextStatement(bool pause) 231 void ScriptDebugServer::setPauseOnNextStatement(bool pause)
235 { 232 {
236 ASSERT(!m_runningNestedMessageLoop); 233 ASSERT(!m_runningNestedMessageLoop);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ASSERT(isPaused()); 306 ASSERT(isPaused());
310 ASSERT(!m_executionState.IsEmpty()); 307 ASSERT(!m_executionState.IsEmpty());
311 v8::HandleScope handleScope(m_isolate); 308 v8::HandleScope handleScope(m_isolate);
312 v8::Local<v8::Value> argv[] = { m_executionState }; 309 v8::Local<v8::Value> argv[] = { m_executionState };
313 callDebuggerMethod(stepOutV8MethodName, 1, argv); 310 callDebuggerMethod(stepOutV8MethodName, 1, argv);
314 continueProgram(); 311 continueProgram();
315 } 312 }
316 313
317 void ScriptDebugServer::clearStepping() 314 void ScriptDebugServer::clearStepping()
318 { 315 {
319 ASSERT(enabled()); 316 ensureDebuggerScriptCompiled();
320 v8::HandleScope scope(m_isolate); 317 v8::HandleScope scope(m_isolate);
321 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 318 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
322 319
323 v8::Local<v8::Value> argv[] = { v8Undefined() }; 320 v8::Local<v8::Value> argv[] = { v8Undefined() };
324 callDebuggerMethod("clearStepping", 0, argv); 321 callDebuggerMethod("clearStepping", 0, argv);
325 } 322 }
326 323
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) 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)
328 { 325 {
329 class EnableLiveEditScope { 326 class EnableLiveEditScope {
330 public: 327 public:
331 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); } 328 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) { v8::Debug::SetLiveEditEnabled(m_isolate, true); }
332 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; } 329 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false) ; }
333 private: 330 private:
334 v8::Isolate* m_isolate; 331 v8::Isolate* m_isolate;
335 }; 332 };
336 333
337 ASSERT(enabled()); 334 ensureDebuggerScriptCompiled();
338 v8::HandleScope scope(m_isolate); 335 v8::HandleScope scope(m_isolate);
339 336
340 OwnPtr<v8::Context::Scope> contextScope; 337 OwnPtr<v8::Context::Scope> contextScope;
341 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); 338 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
342 if (!isPaused()) 339 if (!isPaused())
343 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext)); 340 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext));
344 341
345 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is olate, newContent), v8Boolean(preview, m_isolate) }; 342 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is olate, newContent), v8Boolean(preview, m_isolate) };
346 343
347 v8::Local<v8::Value> v8result; 344 v8::Local<v8::Value> v8result;
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger( m_isolate)->Value()) 668 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger( m_isolate)->Value())
672 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte ger(m_isolate)->Value()) 669 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte ger(m_isolate)->Value())
673 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is olate)->Value()) 670 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is olate)->Value())
674 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger( m_isolate)->Value()) 671 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger( m_isolate)->Value())
675 .setIsContentScript(object->Get(v8InternalizedString("isContentScript")) ->ToBoolean(m_isolate)->Value()) 672 .setIsContentScript(object->Get(v8InternalizedString("isContentScript")) ->ToBoolean(m_isolate)->Value())
676 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript" ))->ToBoolean(m_isolate)->Value()); 673 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript" ))->ToBoolean(m_isolate)->Value());
677 674
678 listener->didParseSource(sourceID, script, compileResult); 675 listener->didParseSource(sourceID, script, compileResult);
679 } 676 }
680 677
681 void ScriptDebugServer::compileDebuggerScript() 678 void ScriptDebugServer::ensureDebuggerScriptCompiled()
682 { 679 {
683 if (!m_debuggerScript.IsEmpty()) { 680 if (!m_debuggerScript.IsEmpty())
684 ASSERT_NOT_REACHED();
685 return; 681 return;
686 }
687 682
688 v8::HandleScope scope(m_isolate); 683 v8::HandleScope scope(m_isolate);
689 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 684 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
690 v8::Local<v8::Object> value = m_client->compileDebuggerScript(); 685 v8::Local<v8::Object> value = m_client->compileDebuggerScript();
691 if (value.IsEmpty()) 686 if (value.IsEmpty())
692 return; 687 return;
693 m_debuggerScript.Reset(m_isolate, value); 688 m_debuggerScript.Reset(m_isolate, value);
694 } 689 }
695 690
696 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const 691 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const
697 { 692 {
698 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript); 693 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript);
699 } 694 }
700 695
701 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c onst 696 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c onst
702 { 697 {
703 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked(); 698 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked();
704 } 699 }
705 700
706 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f unction) 701 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f unction)
707 { 702 {
708 if (!enabled()) { 703 ensureDebuggerScriptCompiled();
709 ASSERT_NOT_REACHED(); 704
710 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
711 }
712 v8::Local<v8::Value> argv[] = { function }; 705 v8::Local<v8::Value> argv[] = { function };
713 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked(); 706 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked();
714 } 707 }
715 708
716 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj ect>& object) 709 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj ect>& object)
717 { 710 {
718 if (!enabled()) { 711 ensureDebuggerScriptCompiled();
719 ASSERT_NOT_REACHED(); 712
720 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
721 }
722 v8::Local<v8::Value> argv[] = { object }; 713 v8::Local<v8::Value> argv[] = { object };
723 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck ed(); 714 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck ed();
724 } 715 }
725 716
726 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>& object) 717 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>& object)
727 { 718 {
728 if (!enabled()) { 719 ensureDebuggerScriptCompiled();
729 ASSERT_NOT_REACHED(); 720
730 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
731 }
732 v8::Local<v8::Value> argv[] = { object }; 721 v8::Local<v8::Value> argv[] = { object };
733 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); 722 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked();
734 } 723 }
735 724
736 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje ct>& object) 725 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje ct>& object)
737 { 726 {
738 if (!enabled()) { 727 if (m_debuggerScript.IsEmpty())
739 // FIXME: provide a way to collect internal properties without enabling debugger. See crbug.com/485451
740 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); 728 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
741 } 729
742 v8::Local<v8::Value> argv[] = { object }; 730 v8::Local<v8::Value> argv[] = { object };
743 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked() ; 731 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked() ;
744 } 732 }
745 733
746 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local< v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local <v8::Value> newValue) 734 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local< v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local <v8::Value> newValue)
747 { 735 {
748 if (m_debuggerScript.IsEmpty()) { 736 if (m_debuggerScript.IsEmpty())
749 ASSERT_NOT_REACHED();
750 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked()); 737 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked());
751 }
752 738
753 v8::Local<v8::Value> argv[] = { 739 v8::Local<v8::Value> argv[] = {
754 functionValue, 740 functionValue,
755 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), 741 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)),
756 v8String(m_isolate, variableName), 742 v8String(m_isolate, variableName),
757 newValue 743 newValue
758 }; 744 };
759 return callDebuggerMethod("setFunctionVariableValue", 4, argv); 745 return callDebuggerMethod("setFunctionVariableValue", 4, argv);
760 } 746 }
761 747
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 *lineNumber = message->GetLineNumber(); 810 *lineNumber = message->GetLineNumber();
825 *columnNumber = message->GetStartColumn(); 811 *columnNumber = message->GetStartColumn();
826 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace (); 812 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace ();
827 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount () > 0) 813 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount () > 0)
828 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace , messageStackTrace->GetFrameCount()); 814 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace , messageStackTrace->GetFrameCount());
829 } 815 }
830 } 816 }
831 } 817 }
832 818
833 } // namespace blink 819 } // 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