| OLD | NEW |
| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 DEFINE_TRACE(ScriptDebugServer) | 100 DEFINE_TRACE(ScriptDebugServer) |
| 101 { | 101 { |
| 102 } | 102 } |
| 103 | 103 |
| 104 void ScriptDebugServer::enable() | 104 void ScriptDebugServer::enable() |
| 105 { | 105 { |
| 106 ASSERT(!enabled()); | 106 ASSERT(!enabled()); |
| 107 v8::HandleScope scope(m_isolate); | 107 v8::HandleScope scope(m_isolate); |
| 108 v8::Debug::SetDebugEventListener(&ScriptDebugServer::v8DebugEventCallback, v
8::External::New(m_isolate, this)); | 108 v8::Debug::SetDebugEventListener(&ScriptDebugServer::v8DebugEventCallback, v
8::External::New(m_isolate, this)); |
| 109 ensureDebuggerScriptCompiled(); | 109 compileDebuggerScript(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void ScriptDebugServer::disable() | 112 void ScriptDebugServer::disable() |
| 113 { | 113 { |
| 114 ASSERT(enabled()); | 114 ASSERT(enabled()); |
| 115 clearBreakpoints(); | 115 clearBreakpoints(); |
| 116 clearCompiledScripts(); | 116 clearCompiledScripts(); |
| 117 m_debuggerScript.Reset(); | 117 m_debuggerScript.Reset(); |
| 118 v8::Debug::SetDebugEventListener(nullptr); | 118 v8::Debug::SetDebugEventListener(nullptr); |
| 119 } | 119 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 v8::HandleScope scope(m_isolate); | 189 v8::HandleScope scope(m_isolate); |
| 190 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); | 190 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); |
| 191 v8::Context::Scope contextScope(debuggerContext); | 191 v8::Context::Scope contextScope(debuggerContext); |
| 192 | 192 |
| 193 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(deb
uggerScriptLocal()->Get(v8InternalizedString("clearBreakpoints"))); | 193 v8::Local<v8::Function> clearBreakpoints = v8::Local<v8::Function>::Cast(deb
uggerScriptLocal()->Get(v8InternalizedString("clearBreakpoints"))); |
| 194 v8::Debug::Call(clearBreakpoints); | 194 v8::Debug::Call(clearBreakpoints); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void ScriptDebugServer::setBreakpointsActivated(bool activated) | 197 void ScriptDebugServer::setBreakpointsActivated(bool activated) |
| 198 { | 198 { |
| 199 ensureDebuggerScriptCompiled(); | 199 if (!enabled()) { |
| 200 ASSERT_NOT_REACHED(); |
| 201 return; |
| 202 } |
| 200 v8::HandleScope scope(m_isolate); | 203 v8::HandleScope scope(m_isolate); |
| 201 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); | 204 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); |
| 202 v8::Context::Scope contextScope(debuggerContext); | 205 v8::Context::Scope contextScope(debuggerContext); |
| 203 | 206 |
| 204 v8::Local<v8::Object> info = v8::Object::New(m_isolate); | 207 v8::Local<v8::Object> info = v8::Object::New(m_isolate); |
| 205 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ
ated)); | 208 info->Set(v8InternalizedString("enabled"), v8::Boolean::New(m_isolate, activ
ated)); |
| 206 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C
ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated")))
; | 209 v8::Local<v8::Function> setBreakpointsActivated = v8::Local<v8::Function>::C
ast(debuggerScriptLocal()->Get(v8InternalizedString("setBreakpointsActivated")))
; |
| 207 v8::Debug::Call(setBreakpointsActivated, info); | 210 v8::Debug::Call(setBreakpointsActivated, info); |
| 208 | 211 |
| 209 m_breakpointsActivated = activated; | 212 m_breakpointsActivated = activated; |
| 210 } | 213 } |
| 211 | 214 |
| 212 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt
ate() | 215 ScriptDebugServer::PauseOnExceptionsState ScriptDebugServer::pauseOnExceptionsSt
ate() |
| 213 { | 216 { |
| 214 ensureDebuggerScriptCompiled(); | 217 ASSERT(enabled()); |
| 215 v8::HandleScope scope(m_isolate); | 218 v8::HandleScope scope(m_isolate); |
| 216 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 219 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 217 | 220 |
| 218 v8::Local<v8::Value> argv[] = { v8Undefined() }; | 221 v8::Local<v8::Value> argv[] = { v8Undefined() }; |
| 219 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0
, argv).ToLocalChecked(); | 222 v8::Local<v8::Value> result = callDebuggerMethod("pauseOnExceptionsState", 0
, argv).ToLocalChecked(); |
| 220 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V
alue()); | 223 return static_cast<ScriptDebugServer::PauseOnExceptionsState>(result->Int32V
alue()); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn
ExceptionsState) | 226 void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOn
ExceptionsState) |
| 224 { | 227 { |
| 225 ensureDebuggerScriptCompiled(); | 228 ASSERT(enabled()); |
| 226 v8::HandleScope scope(m_isolate); | 229 v8::HandleScope scope(m_isolate); |
| 227 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 230 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 228 | 231 |
| 229 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS
tate) }; | 232 v8::Local<v8::Value> argv[] = { v8::Int32::New(m_isolate, pauseOnExceptionsS
tate) }; |
| 230 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); | 233 callDebuggerMethod("setPauseOnExceptionsState", 1, argv); |
| 231 } | 234 } |
| 232 | 235 |
| 233 void ScriptDebugServer::setPauseOnNextStatement(bool pause) | 236 void ScriptDebugServer::setPauseOnNextStatement(bool pause) |
| 234 { | 237 { |
| 235 ASSERT(!m_runningNestedMessageLoop); | 238 ASSERT(!m_runningNestedMessageLoop); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 ASSERT(isPaused()); | 311 ASSERT(isPaused()); |
| 309 ASSERT(!m_executionState.IsEmpty()); | 312 ASSERT(!m_executionState.IsEmpty()); |
| 310 v8::HandleScope handleScope(m_isolate); | 313 v8::HandleScope handleScope(m_isolate); |
| 311 v8::Local<v8::Value> argv[] = { m_executionState }; | 314 v8::Local<v8::Value> argv[] = { m_executionState }; |
| 312 callDebuggerMethod(stepOutV8MethodName, 1, argv); | 315 callDebuggerMethod(stepOutV8MethodName, 1, argv); |
| 313 continueProgram(); | 316 continueProgram(); |
| 314 } | 317 } |
| 315 | 318 |
| 316 void ScriptDebugServer::clearStepping() | 319 void ScriptDebugServer::clearStepping() |
| 317 { | 320 { |
| 318 ensureDebuggerScriptCompiled(); | 321 ASSERT(enabled()); |
| 319 v8::HandleScope scope(m_isolate); | 322 v8::HandleScope scope(m_isolate); |
| 320 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 323 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 321 | 324 |
| 322 v8::Local<v8::Value> argv[] = { v8Undefined() }; | 325 v8::Local<v8::Value> argv[] = { v8Undefined() }; |
| 323 callDebuggerMethod("clearStepping", 0, argv); | 326 callDebuggerMethod("clearStepping", 0, argv); |
| 324 } | 327 } |
| 325 | 328 |
| 326 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) | 329 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 { | 330 { |
| 328 class EnableLiveEditScope { | 331 class EnableLiveEditScope { |
| 329 public: | 332 public: |
| 330 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate)
{ v8::Debug::SetLiveEditEnabled(m_isolate, true); } | 333 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate)
{ v8::Debug::SetLiveEditEnabled(m_isolate, true); } |
| 331 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false)
; } | 334 ~EnableLiveEditScope() { v8::Debug::SetLiveEditEnabled(m_isolate, false)
; } |
| 332 private: | 335 private: |
| 333 v8::Isolate* m_isolate; | 336 v8::Isolate* m_isolate; |
| 334 }; | 337 }; |
| 335 | 338 |
| 336 ensureDebuggerScriptCompiled(); | 339 ASSERT(enabled()); |
| 337 v8::HandleScope scope(m_isolate); | 340 v8::HandleScope scope(m_isolate); |
| 338 | 341 |
| 339 OwnPtr<v8::Context::Scope> contextScope; | 342 OwnPtr<v8::Context::Scope> contextScope; |
| 340 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); | 343 v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext(); |
| 341 if (!isPaused()) | 344 if (!isPaused()) |
| 342 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext)); | 345 contextScope = adoptPtr(new v8::Context::Scope(debuggerContext)); |
| 343 | 346 |
| 344 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is
olate, newContent), v8Boolean(preview, m_isolate) }; | 347 v8::Local<v8::Value> argv[] = { v8String(m_isolate, sourceID), v8String(m_is
olate, newContent), v8Boolean(preview, m_isolate) }; |
| 345 | 348 |
| 346 v8::Local<v8::Value> v8result; | 349 v8::Local<v8::Value> v8result; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger(
m_isolate)->Value()) | 673 .setStartLine(object->Get(v8InternalizedString("startLine"))->ToInteger(
m_isolate)->Value()) |
| 671 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte
ger(m_isolate)->Value()) | 674 .setStartColumn(object->Get(v8InternalizedString("startColumn"))->ToInte
ger(m_isolate)->Value()) |
| 672 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is
olate)->Value()) | 675 .setEndLine(object->Get(v8InternalizedString("endLine"))->ToInteger(m_is
olate)->Value()) |
| 673 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger(
m_isolate)->Value()) | 676 .setEndColumn(object->Get(v8InternalizedString("endColumn"))->ToInteger(
m_isolate)->Value()) |
| 674 .setIsContentScript(object->Get(v8InternalizedString("isContentScript"))
->ToBoolean(m_isolate)->Value()) | 677 .setIsContentScript(object->Get(v8InternalizedString("isContentScript"))
->ToBoolean(m_isolate)->Value()) |
| 675 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript"
))->ToBoolean(m_isolate)->Value()); | 678 .setIsInternalScript(object->Get(v8InternalizedString("isInternalScript"
))->ToBoolean(m_isolate)->Value()); |
| 676 | 679 |
| 677 listener->didParseSource(sourceID, script, compileResult); | 680 listener->didParseSource(sourceID, script, compileResult); |
| 678 } | 681 } |
| 679 | 682 |
| 680 void ScriptDebugServer::ensureDebuggerScriptCompiled() | 683 void ScriptDebugServer::compileDebuggerScript() |
| 681 { | 684 { |
| 682 if (!m_debuggerScript.IsEmpty()) | 685 if (!m_debuggerScript.IsEmpty()) { |
| 686 ASSERT_NOT_REACHED(); |
| 683 return; | 687 return; |
| 688 } |
| 684 | 689 |
| 685 v8::HandleScope scope(m_isolate); | 690 v8::HandleScope scope(m_isolate); |
| 686 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 691 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 687 const WebData& debuggerScriptSourceResource = Platform::current()->loadResou
rce("DebuggerScriptSource.js"); | 692 const WebData& debuggerScriptSourceResource = Platform::current()->loadResou
rce("DebuggerScriptSource.js"); |
| 688 v8::Local<v8::String> source = v8String(m_isolate, String(debuggerScriptSour
ceResource.data(), debuggerScriptSourceResource.size())); | 693 v8::Local<v8::String> source = v8String(m_isolate, String(debuggerScriptSour
ceResource.data(), debuggerScriptSourceResource.size())); |
| 689 v8::Local<v8::Value> value; | 694 v8::Local<v8::Value> value; |
| 690 if (!V8ScriptRunner::compileAndRunInternalScript(source, m_isolate).ToLocal(
&value)) | 695 if (!V8ScriptRunner::compileAndRunInternalScript(source, m_isolate).ToLocal(
&value)) |
| 691 return; | 696 return; |
| 692 ASSERT(value->IsObject()); | 697 ASSERT(value->IsObject()); |
| 693 m_debuggerScript.Reset(m_isolate, v8::Local<v8::Object>::Cast(value)); | 698 m_debuggerScript.Reset(m_isolate, v8::Local<v8::Object>::Cast(value)); |
| 694 } | 699 } |
| 695 | 700 |
| 696 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const | 701 v8::Local<v8::Object> ScriptDebugServer::debuggerScriptLocal() const |
| 697 { | 702 { |
| 698 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript); | 703 return v8::Local<v8::Object>::New(m_isolate, m_debuggerScript); |
| 699 } | 704 } |
| 700 | 705 |
| 701 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c
onst | 706 v8::Local<v8::String> ScriptDebugServer::v8InternalizedString(const char* str) c
onst |
| 702 { | 707 { |
| 703 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); | 708 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); |
| 704 } | 709 } |
| 705 | 710 |
| 706 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f
unction) | 711 v8::Local<v8::Value> ScriptDebugServer::functionScopes(v8::Local<v8::Function> f
unction) |
| 707 { | 712 { |
| 708 ensureDebuggerScriptCompiled(); | 713 if (!enabled()) { |
| 709 | 714 ASSERT_NOT_REACHED(); |
| 715 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 716 } |
| 710 v8::Local<v8::Value> argv[] = { function }; | 717 v8::Local<v8::Value> argv[] = { function }; |
| 711 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked(); | 718 return callDebuggerMethod("getFunctionScopes", 1, argv).ToLocalChecked(); |
| 712 } | 719 } |
| 713 | 720 |
| 714 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj
ect>& object) | 721 v8::Local<v8::Value> ScriptDebugServer::generatorObjectDetails(v8::Local<v8::Obj
ect>& object) |
| 715 { | 722 { |
| 716 ensureDebuggerScriptCompiled(); | 723 if (!enabled()) { |
| 717 | 724 ASSERT_NOT_REACHED(); |
| 725 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 726 } |
| 718 v8::Local<v8::Value> argv[] = { object }; | 727 v8::Local<v8::Value> argv[] = { object }; |
| 719 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck
ed(); | 728 return callDebuggerMethod("getGeneratorObjectDetails", 1, argv).ToLocalCheck
ed(); |
| 720 } | 729 } |
| 721 | 730 |
| 722 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>&
object) | 731 v8::Local<v8::Value> ScriptDebugServer::collectionEntries(v8::Local<v8::Object>&
object) |
| 723 { | 732 { |
| 724 ensureDebuggerScriptCompiled(); | 733 if (!enabled()) { |
| 725 | 734 ASSERT_NOT_REACHED(); |
| 735 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 736 } |
| 726 v8::Local<v8::Value> argv[] = { object }; | 737 v8::Local<v8::Value> argv[] = { object }; |
| 727 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); | 738 return callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); |
| 728 } | 739 } |
| 729 | 740 |
| 730 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje
ct>& object) | 741 v8::Local<v8::Value> ScriptDebugServer::getInternalProperties(v8::Local<v8::Obje
ct>& object) |
| 731 { | 742 { |
| 732 if (m_debuggerScript.IsEmpty()) | 743 if (!enabled()) { |
| 744 ASSERT_NOT_REACHED(); |
| 733 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); | 745 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 734 | 746 } |
| 735 v8::Local<v8::Value> argv[] = { object }; | 747 v8::Local<v8::Value> argv[] = { object }; |
| 736 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked()
; | 748 return callDebuggerMethod("getInternalProperties", 1, argv).ToLocalChecked()
; |
| 737 } | 749 } |
| 738 | 750 |
| 739 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local<
v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local
<v8::Value> newValue) | 751 v8::MaybeLocal<v8::Value> ScriptDebugServer::setFunctionVariableValue(v8::Local<
v8::Value> functionValue, int scopeNumber, const String& variableName, v8::Local
<v8::Value> newValue) |
| 740 { | 752 { |
| 741 if (m_debuggerScript.IsEmpty()) | 753 if (m_debuggerScript.IsEmpty()) { |
| 754 ASSERT_NOT_REACHED(); |
| 742 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb
ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked()); | 755 return m_isolate->ThrowException(v8::String::NewFromUtf8(m_isolate, "Deb
ugging is not enabled.", v8::NewStringType::kNormal).ToLocalChecked()); |
| 756 } |
| 743 | 757 |
| 744 v8::Local<v8::Value> argv[] = { | 758 v8::Local<v8::Value> argv[] = { |
| 745 functionValue, | 759 functionValue, |
| 746 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), | 760 v8::Local<v8::Value>(v8::Integer::New(m_isolate, scopeNumber)), |
| 747 v8String(m_isolate, variableName), | 761 v8String(m_isolate, variableName), |
| 748 newValue | 762 newValue |
| 749 }; | 763 }; |
| 750 return callDebuggerMethod("setFunctionVariableValue", 4, argv); | 764 return callDebuggerMethod("setFunctionVariableValue", 4, argv); |
| 751 } | 765 } |
| 752 | 766 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 *lineNumber = message->GetLineNumber(); | 829 *lineNumber = message->GetLineNumber(); |
| 816 *columnNumber = message->GetStartColumn(); | 830 *columnNumber = message->GetStartColumn(); |
| 817 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace
(); | 831 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace
(); |
| 818 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount
() > 0) | 832 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount
() > 0) |
| 819 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace
, messageStackTrace->GetFrameCount()); | 833 *stackTrace = createScriptCallStack(m_isolate, messageStackTrace
, messageStackTrace->GetFrameCount()); |
| 820 } | 834 } |
| 821 } | 835 } |
| 822 } | 836 } |
| 823 | 837 |
| 824 } // namespace blink | 838 } // namespace blink |
| OLD | NEW |