| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 "platform/v8_inspector/V8Debugger.h" | 5 #include "platform/v8_inspector/V8Debugger.h" |
| 6 | 6 |
| 7 #include "platform/v8_inspector/DebuggerScript.h" | 7 #include "platform/v8_inspector/DebuggerScript.h" |
| 8 #include "platform/v8_inspector/ScriptBreakpoint.h" | 8 #include "platform/v8_inspector/ScriptBreakpoint.h" |
| 9 #include "platform/v8_inspector/V8Compat.h" | 9 #include "platform/v8_inspector/V8Compat.h" |
| 10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 11 #include "platform/v8_inspector/V8InspectorImpl.h" | 11 #include "platform/v8_inspector/V8InspectorImpl.h" |
| 12 #include "platform/v8_inspector/V8InternalValueType.h" | 12 #include "platform/v8_inspector/V8InternalValueType.h" |
| 13 #include "platform/v8_inspector/V8StackTraceImpl.h" | 13 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 14 #include "platform/v8_inspector/V8StringUtil.h" | 14 #include "platform/v8_inspector/V8StringUtil.h" |
| 15 #include "platform/v8_inspector/V8ValueCopier.h" |
| 15 #include "platform/v8_inspector/public/V8InspectorClient.h" | 16 #include "platform/v8_inspector/public/V8InspectorClient.h" |
| 16 | 17 |
| 17 namespace v8_inspector { | 18 namespace v8_inspector { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const char stepIntoV8MethodName[] = "stepIntoStatement"; | 21 const char stepIntoV8MethodName[] = "stepIntoStatement"; |
| 21 const char stepOutV8MethodName[] = "stepOutOfFunction"; | 22 const char stepOutV8MethodName[] = "stepOutOfFunction"; |
| 22 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; | 23 static const char v8AsyncTaskEventEnqueue[] = "enqueue"; |
| 23 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; | 24 static const char v8AsyncTaskEventWillHandle[] = "willHandle"; |
| 24 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; | 25 static const char v8AsyncTaskEventDidHandle[] = "didHandle"; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 DCHECK(value->IsObject()); | 575 DCHECK(value->IsObject()); |
| 575 m_debuggerScript.Reset(m_isolate, value.As<v8::Object>()); | 576 m_debuggerScript.Reset(m_isolate, value.As<v8::Object>()); |
| 576 } | 577 } |
| 577 | 578 |
| 578 v8::Local<v8::Context> V8Debugger::debuggerContext() const | 579 v8::Local<v8::Context> V8Debugger::debuggerContext() const |
| 579 { | 580 { |
| 580 DCHECK(!m_debuggerContext.IsEmpty()); | 581 DCHECK(!m_debuggerContext.IsEmpty()); |
| 581 return m_debuggerContext.Get(m_isolate); | 582 return m_debuggerContext.Get(m_isolate); |
| 582 } | 583 } |
| 583 | 584 |
| 584 v8::MaybeLocal<v8::Value> V8Debugger::functionScopes(v8::Local<v8::Function> fun
ction) | 585 v8::MaybeLocal<v8::Value> V8Debugger::functionScopes(v8::Local<v8::Context> cont
ext, v8::Local<v8::Function> function) |
| 585 { | 586 { |
| 586 if (!enabled()) { | 587 if (!enabled()) { |
| 587 NOTREACHED(); | 588 NOTREACHED(); |
| 588 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); | 589 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 589 } | 590 } |
| 590 v8::Local<v8::Value> argv[] = { function }; | 591 v8::Local<v8::Value> argv[] = { function }; |
| 591 v8::Local<v8::Value> scopesValue; | 592 v8::Local<v8::Value> scopesValue; |
| 592 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue)
|| !scopesValue->IsArray()) | 593 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue)) |
| 593 return v8::MaybeLocal<v8::Value>(); | 594 return v8::MaybeLocal<v8::Value>(); |
| 594 v8::Local<v8::Array> scopes = scopesValue.As<v8::Array>(); | 595 v8::Local<v8::Value> copied; |
| 595 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); | 596 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, sco
pesValue).ToLocal(&copied) || !copied->IsArray()) |
| 596 if (!markAsInternal(context, scopes, V8InternalValueType::kScopeList)) | |
| 597 return v8::MaybeLocal<v8::Value>(); | 597 return v8::MaybeLocal<v8::Value>(); |
| 598 if (!markArrayEntriesAsInternal(context, scopes, V8InternalValueType::kScope
)) | 598 if (!markAsInternal(context, v8::Local<v8::Array>::Cast(copied), V8InternalV
alueType::kScopeList)) |
| 599 return v8::MaybeLocal<v8::Value>(); | 599 return v8::MaybeLocal<v8::Value>(); |
| 600 if (!scopes->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 600 if (!markArrayEntriesAsInternal(context, v8::Local<v8::Array>::Cast(copied),
V8InternalValueType::kScope)) |
| 601 return v8::Undefined(m_isolate); | 601 return v8::MaybeLocal<v8::Value>(); |
| 602 return scopes; | 602 return copied; |
| 603 } | 603 } |
| 604 | 604 |
| 605 v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(v8::Local<v8::Context>
context, v8::Local<v8::Value> value) | 605 v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(v8::Local<v8::Context>
context, v8::Local<v8::Value> value) |
| 606 { | 606 { |
| 607 v8::Local<v8::Array> properties; | 607 v8::Local<v8::Array> properties; |
| 608 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) | 608 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) |
| 609 return v8::MaybeLocal<v8::Array>(); | 609 return v8::MaybeLocal<v8::Array>(); |
| 610 if (value->IsFunction()) { | 610 if (value->IsFunction()) { |
| 611 v8::Local<v8::Function> function = value.As<v8::Function>(); | 611 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 612 v8::Local<v8::Value> location = functionLocation(context, function); | 612 v8::Local<v8::Value> location = functionLocation(context, function); |
| 613 if (location->IsObject()) { | 613 if (location->IsObject()) { |
| 614 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[FunctionLocation]]")); | 614 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[FunctionLocation]]")); |
| 615 properties->Set(properties->Length(), location); | 615 properties->Set(properties->Length(), location); |
| 616 } | 616 } |
| 617 if (function->IsGeneratorFunction()) { | 617 if (function->IsGeneratorFunction()) { |
| 618 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[IsGenerator]]")); | 618 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[IsGenerator]]")); |
| 619 properties->Set(properties->Length(), v8::True(m_isolate)); | 619 properties->Set(properties->Length(), v8::True(m_isolate)); |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 if (!enabled()) | 622 if (!enabled()) |
| 623 return properties; | 623 return properties; |
| 624 if (value->IsMap() || value->IsWeakMap() || value->IsSet() || value->IsWeakS
et() || value->IsSetIterator() || value->IsMapIterator()) { | 624 if (value->IsMap() || value->IsWeakMap() || value->IsSet() || value->IsWeakS
et() || value->IsSetIterator() || value->IsMapIterator()) { |
| 625 v8::Local<v8::Value> entries = collectionEntries(context, v8::Local<v8::
Object>::Cast(value)); | 625 v8::Local<v8::Value> entries = collectionEntries(context, v8::Local<v8::
Object>::Cast(value)); |
| 626 if (entries->IsArray()) { | 626 if (entries->IsArray()) { |
| 627 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[Entries]]")); | 627 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[Entries]]")); |
| 628 properties->Set(properties->Length(), entries); | 628 properties->Set(properties->Length(), entries); |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 if (value->IsGeneratorObject()) { | 631 if (value->IsGeneratorObject()) { |
| 632 v8::Local<v8::Value> location = generatorObjectLocation(v8::Local<v8::Ob
ject>::Cast(value)); | 632 v8::Local<v8::Value> location = generatorObjectLocation(context, v8::Loc
al<v8::Object>::Cast(value)); |
| 633 if (location->IsObject()) { | 633 if (location->IsObject()) { |
| 634 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[GeneratorLocation]]")); | 634 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[GeneratorLocation]]")); |
| 635 properties->Set(properties->Length(), location); | 635 properties->Set(properties->Length(), location); |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 if (value->IsFunction()) { | 638 if (value->IsFunction()) { |
| 639 v8::Local<v8::Function> function = value.As<v8::Function>(); | 639 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 640 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); | 640 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); |
| 641 v8::Local<v8::Value> scopes; | 641 v8::Local<v8::Value> scopes; |
| 642 if (boundFunction->IsUndefined() && functionScopes(function).ToLocal(&sc
opes)) { | 642 if (boundFunction->IsUndefined() && functionScopes(context, function).To
Local(&scopes)) { |
| 643 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[Scopes]]")); | 643 properties->Set(properties->Length(), toV8StringInternalized(m_isola
te, "[[Scopes]]")); |
| 644 properties->Set(properties->Length(), scopes); | 644 properties->Set(properties->Length(), scopes); |
| 645 } | 645 } |
| 646 } | 646 } |
| 647 return properties; | 647 return properties; |
| 648 } | 648 } |
| 649 | 649 |
| 650 v8::Local<v8::Value> V8Debugger::collectionEntries(v8::Local<v8::Context> contex
t, v8::Local<v8::Object> object) | 650 v8::Local<v8::Value> V8Debugger::collectionEntries(v8::Local<v8::Context> contex
t, v8::Local<v8::Object> object) |
| 651 { | 651 { |
| 652 if (!enabled()) { | 652 if (!enabled()) { |
| 653 NOTREACHED(); | 653 NOTREACHED(); |
| 654 return v8::Undefined(m_isolate); | 654 return v8::Undefined(m_isolate); |
| 655 } | 655 } |
| 656 v8::Local<v8::Value> argv[] = { object }; | 656 v8::Local<v8::Value> argv[] = { object }; |
| 657 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); | 657 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); |
| 658 if (!entriesValue->IsArray()) | 658 v8::Local<v8::Value> copied; |
| 659 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, ent
riesValue).ToLocal(&copied) || !copied->IsArray()) |
| 659 return v8::Undefined(m_isolate); | 660 return v8::Undefined(m_isolate); |
| 660 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); | 661 if (!markArrayEntriesAsInternal(context, v8::Local<v8::Array>::Cast(copied),
V8InternalValueType::kEntry)) |
| 661 if (!markArrayEntriesAsInternal(context, entries, V8InternalValueType::kEntr
y)) | |
| 662 return v8::Undefined(m_isolate); | 662 return v8::Undefined(m_isolate); |
| 663 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 663 return copied; |
| 664 return v8::Undefined(m_isolate); | |
| 665 return entries; | |
| 666 } | 664 } |
| 667 | 665 |
| 668 v8::Local<v8::Value> V8Debugger::generatorObjectLocation(v8::Local<v8::Object> o
bject) | 666 v8::Local<v8::Value> V8Debugger::generatorObjectLocation(v8::Local<v8::Context>
context, v8::Local<v8::Object> object) |
| 669 { | 667 { |
| 670 if (!enabled()) { | 668 if (!enabled()) { |
| 671 NOTREACHED(); | 669 NOTREACHED(); |
| 672 return v8::Null(m_isolate); | 670 return v8::Null(m_isolate); |
| 673 } | 671 } |
| 674 v8::Local<v8::Value> argv[] = { object }; | 672 v8::Local<v8::Value> argv[] = { object }; |
| 675 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); | 673 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); |
| 676 if (!location->IsObject()) | 674 v8::Local<v8::Value> copied; |
| 675 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, loc
ation).ToLocal(&copied) || !copied->IsObject()) |
| 677 return v8::Null(m_isolate); | 676 return v8::Null(m_isolate); |
| 678 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); | 677 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), V8Internal
ValueType::kLocation)) |
| 679 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(location), V8Intern
alValueType::kLocation)) | |
| 680 return v8::Null(m_isolate); | 678 return v8::Null(m_isolate); |
| 681 return location; | 679 return copied; |
| 682 } | 680 } |
| 683 | 681 |
| 684 v8::Local<v8::Value> V8Debugger::functionLocation(v8::Local<v8::Context> context
, v8::Local<v8::Function> function) | 682 v8::Local<v8::Value> V8Debugger::functionLocation(v8::Local<v8::Context> context
, v8::Local<v8::Function> function) |
| 685 { | 683 { |
| 686 int scriptId = function->ScriptId(); | 684 int scriptId = function->ScriptId(); |
| 687 if (scriptId == v8::UnboundScript::kNoScriptId) | 685 if (scriptId == v8::UnboundScript::kNoScriptId) |
| 688 return v8::Null(m_isolate); | 686 return v8::Null(m_isolate); |
| 689 int lineNumber = function->GetScriptLineNumber(); | 687 int lineNumber = function->GetScriptLineNumber(); |
| 690 int columnNumber = function->GetScriptColumnNumber(); | 688 int columnNumber = function->GetScriptColumnNumber(); |
| 691 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F
unction::kLineOffsetNotFound) | 689 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F
unction::kLineOffsetNotFound) |
| 692 return v8::Null(m_isolate); | 690 return v8::Null(m_isolate); |
| 693 v8::Local<v8::Object> location = v8::Object::New(m_isolate); | 691 v8::Local<v8::Object> location = v8::Object::New(m_isolate); |
| 692 if (!location->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 693 return v8::Null(m_isolate); |
| 694 if (!location->Set(context, toV8StringInternalized(m_isolate, "scriptId"), t
oV8String(m_isolate, String16::fromInteger(scriptId))).FromMaybe(false)) | 694 if (!location->Set(context, toV8StringInternalized(m_isolate, "scriptId"), t
oV8String(m_isolate, String16::fromInteger(scriptId))).FromMaybe(false)) |
| 695 return v8::Null(m_isolate); | 695 return v8::Null(m_isolate); |
| 696 if (!location->Set(context, toV8StringInternalized(m_isolate, "lineNumber"),
v8::Integer::New(m_isolate, lineNumber)).FromMaybe(false)) | 696 if (!location->Set(context, toV8StringInternalized(m_isolate, "lineNumber"),
v8::Integer::New(m_isolate, lineNumber)).FromMaybe(false)) |
| 697 return v8::Null(m_isolate); | 697 return v8::Null(m_isolate); |
| 698 if (!location->Set(context, toV8StringInternalized(m_isolate, "columnNumber"
), v8::Integer::New(m_isolate, columnNumber)).FromMaybe(false)) | 698 if (!location->Set(context, toV8StringInternalized(m_isolate, "columnNumber"
), v8::Integer::New(m_isolate, columnNumber)).FromMaybe(false)) |
| 699 return v8::Null(m_isolate); | 699 return v8::Null(m_isolate); |
| 700 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) | 700 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) |
| 701 return v8::Null(m_isolate); | 701 return v8::Null(m_isolate); |
| 702 return location; | 702 return location; |
| 703 } | 703 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 return nullptr; | 830 return nullptr; |
| 831 | 831 |
| 832 size_t stackSize = fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture :
1; | 832 size_t stackSize = fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture :
1; |
| 833 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 833 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
| 834 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 834 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 835 | 835 |
| 836 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 836 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 837 } | 837 } |
| 838 | 838 |
| 839 } // namespace v8_inspector | 839 } // namespace v8_inspector |
| OLD | NEW |