| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "platform/v8_inspector/V8DebuggerImpl.h" | 31 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 32 | 32 |
| 33 #include "platform/inspector_protocol/Values.h" | 33 #include "platform/inspector_protocol/Values.h" |
| 34 #include "platform/v8_inspector/Atomics.h" | 34 #include "platform/v8_inspector/Atomics.h" |
| 35 #include "platform/v8_inspector/DebuggerScript.h" | 35 #include "platform/v8_inspector/DebuggerScript.h" |
| 36 #include "platform/v8_inspector/JavaScriptCallFrame.h" | 36 #include "platform/v8_inspector/JavaScriptCallFrame.h" |
| 37 #include "platform/v8_inspector/ScriptBreakpoint.h" | 37 #include "platform/v8_inspector/ScriptBreakpoint.h" |
| 38 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 38 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 39 #include "platform/v8_inspector/V8JavaScriptCallFrame.h" | |
| 40 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 39 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 41 #include "platform/v8_inspector/V8StackTraceImpl.h" | 40 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 42 #include "platform/v8_inspector/V8StringUtil.h" | 41 #include "platform/v8_inspector/V8StringUtil.h" |
| 43 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 42 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 44 | 43 |
| 45 namespace blink { | 44 namespace blink { |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 const char stepIntoV8MethodName[] = "stepIntoStatement"; | 47 const char stepIntoV8MethodName[] = "stepIntoStatement"; |
| 49 const char stepOutV8MethodName[] = "stepOutOfFunction"; | 48 const char stepOutV8MethodName[] = "stepOutOfFunction"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 V8DebuggerImpl::~V8DebuggerImpl() | 82 V8DebuggerImpl::~V8DebuggerImpl() |
| 84 { | 83 { |
| 85 } | 84 } |
| 86 | 85 |
| 87 void V8DebuggerImpl::enable() | 86 void V8DebuggerImpl::enable() |
| 88 { | 87 { |
| 89 ASSERT(!enabled()); | 88 ASSERT(!enabled()); |
| 90 v8::HandleScope scope(m_isolate); | 89 v8::HandleScope scope(m_isolate); |
| 91 v8::Debug::SetDebugEventListener(m_isolate, &V8DebuggerImpl::v8DebugEventCal
lback, v8::External::New(m_isolate, this)); | 90 v8::Debug::SetDebugEventListener(m_isolate, &V8DebuggerImpl::v8DebugEventCal
lback, v8::External::New(m_isolate, this)); |
| 92 m_debuggerContext.Reset(m_isolate, v8::Debug::GetDebugContext(m_isolate)); | 91 m_debuggerContext.Reset(m_isolate, v8::Debug::GetDebugContext(m_isolate)); |
| 93 m_callFrameWrapperTemplate.Reset(m_isolate, V8JavaScriptCallFrame::createWra
pperTemplate(m_isolate)); | |
| 94 compileDebuggerScript(); | 92 compileDebuggerScript(); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void V8DebuggerImpl::disable() | 95 void V8DebuggerImpl::disable() |
| 98 { | 96 { |
| 99 ASSERT(enabled()); | 97 ASSERT(enabled()); |
| 100 clearBreakpoints(); | 98 clearBreakpoints(); |
| 101 m_debuggerScript.Reset(); | 99 m_debuggerScript.Reset(); |
| 102 m_debuggerContext.Reset(); | 100 m_debuggerContext.Reset(); |
| 103 m_callFrameWrapperTemplate.Reset(); | |
| 104 v8::Debug::SetDebugEventListener(m_isolate, nullptr); | 101 v8::Debug::SetDebugEventListener(m_isolate, nullptr); |
| 105 } | 102 } |
| 106 | 103 |
| 107 bool V8DebuggerImpl::enabled() const | 104 bool V8DebuggerImpl::enabled() const |
| 108 { | 105 { |
| 109 return !m_debuggerScript.IsEmpty(); | 106 return !m_debuggerScript.IsEmpty(); |
| 110 } | 107 } |
| 111 | 108 |
| 112 void V8Debugger::setContextDebugData(v8::Local<v8::Context> context, const Strin
g16& type, int contextGroupId) | 109 void V8Debugger::setContextDebugData(v8::Local<v8::Context> context, const Strin
g16& type, int contextGroupId) |
| 113 { | 110 { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 void V8DebuggerImpl::clearStepping() | 389 void V8DebuggerImpl::clearStepping() |
| 393 { | 390 { |
| 394 ASSERT(enabled()); | 391 ASSERT(enabled()); |
| 395 v8::HandleScope scope(m_isolate); | 392 v8::HandleScope scope(m_isolate); |
| 396 v8::Context::Scope contextScope(debuggerContext()); | 393 v8::Context::Scope contextScope(debuggerContext()); |
| 397 | 394 |
| 398 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; | 395 v8::Local<v8::Value> argv[] = { v8::Undefined(m_isolate) }; |
| 399 callDebuggerMethod("clearStepping", 0, argv); | 396 callDebuggerMethod("clearStepping", 0, argv); |
| 400 } | 397 } |
| 401 | 398 |
| 402 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, const String16& n
ewContent, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetScript
SourceError>* errorData, v8::Global<v8::Object>* newCallFrames, Maybe<bool>* sta
ckChanged) | 399 bool V8DebuggerImpl::setScriptSource(const String16& sourceID, const String16& n
ewContent, bool preview, ErrorString* error, Maybe<protocol::Debugger::SetScript
SourceError>* errorData, OwnPtr<JavaScriptCallFrame>* newCallFrames, Maybe<bool>
* stackChanged) |
| 403 { | 400 { |
| 404 class EnableLiveEditScope { | 401 class EnableLiveEditScope { |
| 405 public: | 402 public: |
| 406 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) | 403 explicit EnableLiveEditScope(v8::Isolate* isolate) : m_isolate(isolate) |
| 407 { | 404 { |
| 408 v8::Debug::SetLiveEditEnabled(m_isolate, true); | 405 v8::Debug::SetLiveEditEnabled(m_isolate, true); |
| 409 inLiveEditScope = true; | 406 inLiveEditScope = true; |
| 410 } | 407 } |
| 411 ~EnableLiveEditScope() | 408 ~EnableLiveEditScope() |
| 412 { | 409 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 441 } |
| 445 ASSERT(!v8result.IsEmpty()); | 442 ASSERT(!v8result.IsEmpty()); |
| 446 v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate); | 443 v8::Local<v8::Object> resultTuple = v8result->ToObject(m_isolate); |
| 447 int code = static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value
()); | 444 int code = static_cast<int>(resultTuple->Get(0)->ToInteger(m_isolate)->Value
()); |
| 448 switch (code) { | 445 switch (code) { |
| 449 case 0: | 446 case 0: |
| 450 { | 447 { |
| 451 *stackChanged = resultTuple->Get(1)->BooleanValue(); | 448 *stackChanged = resultTuple->Get(1)->BooleanValue(); |
| 452 // Call stack may have changed after if the edited function was on t
he stack. | 449 // Call stack may have changed after if the edited function was on t
he stack. |
| 453 if (!preview && isPaused()) | 450 if (!preview && isPaused()) |
| 454 newCallFrames->Reset(m_isolate, currentCallFrames()); | 451 *newCallFrames = currentCallFrames(); |
| 455 return true; | 452 return true; |
| 456 } | 453 } |
| 457 // Compile error. | 454 // Compile error. |
| 458 case 1: | 455 case 1: |
| 459 { | 456 { |
| 460 *errorData = protocol::Debugger::SetScriptSourceError::create() | 457 *errorData = protocol::Debugger::SetScriptSourceError::create() |
| 461 .setMessage(toProtocolStringWithTypeCheck(resultTuple->Get(2))) | 458 .setMessage(toProtocolStringWithTypeCheck(resultTuple->Get(2))) |
| 462 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value(
)) | 459 .setLineNumber(resultTuple->Get(3)->ToInteger(m_isolate)->Value(
)) |
| 463 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu
e()).build(); | 460 .setColumnNumber(resultTuple->Get(4)->ToInteger(m_isolate)->Valu
e()).build(); |
| 464 return false; | 461 return false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 488 } else { | 485 } else { |
| 489 v8::Local<v8::Value> argv[] = { m_executionState }; | 486 v8::Local<v8::Value> argv[] = { m_executionState }; |
| 490 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE
NGTH(argv), argv).ToLocalChecked(); | 487 currentCallFrameV8 = callDebuggerMethod("currentCallFrame", WTF_ARRAY_LE
NGTH(argv), argv).ToLocalChecked(); |
| 491 } | 488 } |
| 492 ASSERT(!currentCallFrameV8.IsEmpty()); | 489 ASSERT(!currentCallFrameV8.IsEmpty()); |
| 493 if (!currentCallFrameV8->IsObject()) | 490 if (!currentCallFrameV8->IsObject()) |
| 494 return nullptr; | 491 return nullptr; |
| 495 return JavaScriptCallFrame::create(debuggerContext(), v8::Local<v8::Object>:
:Cast(currentCallFrameV8)); | 492 return JavaScriptCallFrame::create(debuggerContext(), v8::Local<v8::Object>:
:Cast(currentCallFrameV8)); |
| 496 } | 493 } |
| 497 | 494 |
| 498 v8::Local<v8::Object> V8DebuggerImpl::currentCallFrames() | 495 PassOwnPtr<JavaScriptCallFrame> V8DebuggerImpl::currentCallFrames() |
| 499 { | 496 { |
| 500 if (!m_isolate->InContext()) | 497 if (!m_isolate->InContext()) |
| 501 return v8::Local<v8::Object>(); | 498 return nullptr; |
| 502 | 499 |
| 503 // Filter out stack traces entirely consisting of V8's internal scripts. | 500 // Filter out stack traces entirely consisting of V8's internal scripts. |
| 504 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(m_i
solate, 1); | 501 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(m_i
solate, 1); |
| 505 if (!stackTrace->GetFrameCount()) | 502 if (!stackTrace->GetFrameCount()) |
| 506 return v8::Local<v8::Object>(); | 503 return nullptr; |
| 507 | 504 |
| 508 OwnPtr<JavaScriptCallFrame> currentCallFrame = wrapCallFrames(); | 505 return wrapCallFrames(); |
| 509 if (!currentCallFrame) | |
| 510 return v8::Local<v8::Object>(); | |
| 511 | |
| 512 v8::Local<v8::FunctionTemplate> wrapperTemplate = v8::Local<v8::FunctionTemp
late>::New(m_isolate, m_callFrameWrapperTemplate); | |
| 513 v8::Local<v8::Context> context = m_pausedContext.IsEmpty() ? m_isolate->GetC
urrentContext() : m_pausedContext; | |
| 514 v8::Context::Scope scope(context); | |
| 515 v8::Local<v8::Object> wrapper = V8JavaScriptCallFrame::wrap(wrapperTemplate,
context, currentCallFrame.release()); | |
| 516 return wrapper; | |
| 517 } | 506 } |
| 518 | 507 |
| 519 PassOwnPtr<JavaScriptCallFrame> V8DebuggerImpl::callFrame(int index) | 508 PassOwnPtr<JavaScriptCallFrame> V8DebuggerImpl::callFrame(int index) |
| 520 { | 509 { |
| 521 if (!m_isolate->InContext()) | 510 if (!m_isolate->InContext()) |
| 522 return nullptr; | 511 return nullptr; |
| 523 v8::HandleScope handleScope(m_isolate); | 512 v8::HandleScope handleScope(m_isolate); |
| 524 | 513 |
| 525 v8::Local<v8::Value> currentCallFrameV8; | 514 v8::Local<v8::Value> currentCallFrameV8; |
| 526 if (m_executionState.IsEmpty()) { | 515 if (m_executionState.IsEmpty()) { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 } | 884 } |
| 896 | 885 |
| 897 v8::Local<v8::Context> V8DebuggerImpl::regexContext() | 886 v8::Local<v8::Context> V8DebuggerImpl::regexContext() |
| 898 { | 887 { |
| 899 if (m_regexContext.IsEmpty()) | 888 if (m_regexContext.IsEmpty()) |
| 900 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); | 889 m_regexContext.Reset(m_isolate, v8::Context::New(m_isolate)); |
| 901 return m_regexContext.Get(m_isolate); | 890 return m_regexContext.Get(m_isolate); |
| 902 } | 891 } |
| 903 | 892 |
| 904 } // namespace blink | 893 } // namespace blink |
| OLD | NEW |