| 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 23 matching lines...) Expand all Loading... |
| 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/InspectedContext.h" | 36 #include "platform/v8_inspector/InspectedContext.h" |
| 37 #include "platform/v8_inspector/ScriptBreakpoint.h" | 37 #include "platform/v8_inspector/ScriptBreakpoint.h" |
| 38 #include "platform/v8_inspector/V8Compat.h" | 38 #include "platform/v8_inspector/V8Compat.h" |
| 39 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" | 39 #include "platform/v8_inspector/V8ConsoleAgentImpl.h" |
| 40 #include "platform/v8_inspector/V8ConsoleMessage.h" | 40 #include "platform/v8_inspector/V8ConsoleMessage.h" |
| 41 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 41 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 42 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 42 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 43 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 43 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 44 #include "platform/v8_inspector/V8InternalValueType.h" |
| 44 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 45 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 45 #include "platform/v8_inspector/V8StackTraceImpl.h" | 46 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 46 #include "platform/v8_inspector/V8StringUtil.h" | 47 #include "platform/v8_inspector/V8StringUtil.h" |
| 47 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 48 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 48 #include <v8-profiler.h> | 49 #include <v8-profiler.h> |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 const char stepIntoV8MethodName[] = "stepIntoStatement"; | 54 const char stepIntoV8MethodName[] = "stepIntoStatement"; |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); | 645 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali
zed).ToLocalChecked(); |
| 645 } | 646 } |
| 646 | 647 |
| 647 v8::MaybeLocal<v8::Value> V8DebuggerImpl::functionScopes(v8::Local<v8::Function>
function) | 648 v8::MaybeLocal<v8::Value> V8DebuggerImpl::functionScopes(v8::Local<v8::Function>
function) |
| 648 { | 649 { |
| 649 if (!enabled()) { | 650 if (!enabled()) { |
| 650 NOTREACHED(); | 651 NOTREACHED(); |
| 651 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); | 652 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); |
| 652 } | 653 } |
| 653 v8::Local<v8::Value> argv[] = { function }; | 654 v8::Local<v8::Value> argv[] = { function }; |
| 654 return callDebuggerMethod("getFunctionScopes", 1, argv); | 655 v8::Local<v8::Value> scopesValue; |
| 656 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue)
|| !scopesValue->IsArray()) |
| 657 return v8::MaybeLocal<v8::Value>(); |
| 658 v8::Local<v8::Array> scopes = scopesValue.As<v8::Array>(); |
| 659 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); |
| 660 if (!markAsInternal(context, scopes, V8InternalValueType::kScopeList)) |
| 661 return v8::MaybeLocal<v8::Value>(); |
| 662 if (!markArrayEntriesAsInternal(context, scopes, V8InternalValueType::kScope
)) |
| 663 return v8::MaybeLocal<v8::Value>(); |
| 664 if (!scopes->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 665 return v8::Undefined(m_isolate); |
| 666 return scopes; |
| 655 } | 667 } |
| 656 | 668 |
| 657 v8::MaybeLocal<v8::Array> V8DebuggerImpl::internalProperties(v8::Local<v8::Conte
xt> context, v8::Local<v8::Value> value) | 669 v8::MaybeLocal<v8::Array> V8DebuggerImpl::internalProperties(v8::Local<v8::Conte
xt> context, v8::Local<v8::Value> value) |
| 658 { | 670 { |
| 659 v8::Local<v8::Array> properties; | 671 v8::Local<v8::Array> properties; |
| 660 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) | 672 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)
) |
| 661 return v8::MaybeLocal<v8::Array>(); | 673 return v8::MaybeLocal<v8::Array>(); |
| 674 if (value->IsFunction()) { |
| 675 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 676 v8::Local<v8::Value> location = functionLocation(context, function); |
| 677 if (location->IsObject()) { |
| 678 properties->Set(properties->Length(), v8InternalizedString("[[Functi
onLocation]]")); |
| 679 properties->Set(properties->Length(), location); |
| 680 } |
| 681 if (function->IsGeneratorFunction()) { |
| 682 properties->Set(properties->Length(), v8InternalizedString("[[IsGene
rator]]")); |
| 683 properties->Set(properties->Length(), v8::True(m_isolate)); |
| 684 } |
| 685 } |
| 662 if (!enabled()) | 686 if (!enabled()) |
| 663 return properties; | 687 return properties; |
| 664 if (value->IsMap() || value->IsWeakMap() || value->IsSet() || value->IsWeakS
et() || value->IsSetIterator() || value->IsMapIterator()) { | 688 if (value->IsMap() || value->IsWeakMap() || value->IsSet() || value->IsWeakS
et() || value->IsSetIterator() || value->IsMapIterator()) { |
| 665 v8::Local<v8::Value> entries = collectionEntries(context, v8::Local<v8::
Object>::Cast(value)); | 689 v8::Local<v8::Value> entries = collectionEntries(context, v8::Local<v8::
Object>::Cast(value)); |
| 666 if (entries->IsArray()) { | 690 if (entries->IsArray()) { |
| 667 properties->Set(properties->Length(), v8InternalizedString("[[Entrie
s]]")); | 691 properties->Set(properties->Length(), v8InternalizedString("[[Entrie
s]]")); |
| 668 properties->Set(properties->Length(), entries); | 692 properties->Set(properties->Length(), entries); |
| 669 } | 693 } |
| 670 } | 694 } |
| 671 if (value->IsGeneratorObject()) { | 695 if (value->IsGeneratorObject()) { |
| 672 v8::Local<v8::Value> location = generatorObjectLocation(v8::Local<v8::Ob
ject>::Cast(value)); | 696 v8::Local<v8::Value> location = generatorObjectLocation(v8::Local<v8::Ob
ject>::Cast(value)); |
| 673 if (location->IsObject()) { | 697 if (location->IsObject()) { |
| 674 properties->Set(properties->Length(), v8InternalizedString("[[Genera
torLocation]]")); | 698 properties->Set(properties->Length(), v8InternalizedString("[[Genera
torLocation]]")); |
| 675 properties->Set(properties->Length(), location); | 699 properties->Set(properties->Length(), location); |
| 676 } | 700 } |
| 677 } | 701 } |
| 702 if (value->IsFunction()) { |
| 703 v8::Local<v8::Function> function = value.As<v8::Function>(); |
| 704 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); |
| 705 v8::Local<v8::Value> scopes; |
| 706 if (boundFunction->IsUndefined() && functionScopes(function).ToLocal(&sc
opes)) { |
| 707 properties->Set(properties->Length(), v8InternalizedString("[[Scopes
]]")); |
| 708 properties->Set(properties->Length(), scopes); |
| 709 } |
| 710 } |
| 678 return properties; | 711 return properties; |
| 679 } | 712 } |
| 680 | 713 |
| 681 v8::Local<v8::Value> V8DebuggerImpl::collectionEntries(v8::Local<v8::Context> co
ntext, v8::Local<v8::Object> object) | 714 v8::Local<v8::Value> V8DebuggerImpl::collectionEntries(v8::Local<v8::Context> co
ntext, v8::Local<v8::Object> object) |
| 682 { | 715 { |
| 683 if (!enabled()) { | 716 if (!enabled()) { |
| 684 NOTREACHED(); | 717 NOTREACHED(); |
| 685 return v8::Undefined(m_isolate); | 718 return v8::Undefined(m_isolate); |
| 686 } | 719 } |
| 687 v8::Local<v8::Value> argv[] = { object }; | 720 v8::Local<v8::Value> argv[] = { object }; |
| 688 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); | 721 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries
", 1, argv).ToLocalChecked(); |
| 689 if (!entriesValue->IsArray()) | 722 if (!entriesValue->IsArray()) |
| 690 return v8::Undefined(m_isolate); | 723 return v8::Undefined(m_isolate); |
| 691 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); | 724 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); |
| 692 for (size_t i = 0; i < entries->Length(); ++i) { | 725 if (!markArrayEntriesAsInternal(context, entries, V8InternalValueType::kEntr
y)) |
| 693 v8::Local<v8::Value> entry; | 726 return v8::Undefined(m_isolate); |
| 694 if (!entries->Get(context, i).ToLocal(&entry) || !entry->IsObject()) | |
| 695 continue; | |
| 696 if (!entry.As<v8::Object>()->SetPrivate(context, V8InjectedScriptHost::i
nternalEntryPrivate(m_isolate), v8::True(m_isolate)).FromMaybe(false)) | |
| 697 continue; | |
| 698 } | |
| 699 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | 727 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) |
| 700 return v8::Undefined(m_isolate); | 728 return v8::Undefined(m_isolate); |
| 701 return entries; | 729 return entries; |
| 702 } | 730 } |
| 703 | 731 |
| 704 v8::Local<v8::Value> V8DebuggerImpl::generatorObjectLocation(v8::Local<v8::Objec
t> object) | 732 v8::Local<v8::Value> V8DebuggerImpl::generatorObjectLocation(v8::Local<v8::Objec
t> object) |
| 705 { | 733 { |
| 706 if (!enabled()) { | 734 if (!enabled()) { |
| 707 NOTREACHED(); | 735 NOTREACHED(); |
| 708 return v8::Null(m_isolate); | 736 return v8::Null(m_isolate); |
| 709 } | 737 } |
| 710 v8::Local<v8::Value> argv[] = { object }; | 738 v8::Local<v8::Value> argv[] = { object }; |
| 711 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); | 739 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati
on", 1, argv).ToLocalChecked(); |
| 712 if (!location->IsObject()) | 740 if (!location->IsObject()) |
| 713 return v8::Null(m_isolate); | 741 return v8::Null(m_isolate); |
| 714 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); | 742 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); |
| 715 if (!location.As<v8::Object>()->SetPrivate(context, V8InjectedScriptHost::in
ternalLocationPrivate(m_isolate), v8::True(m_isolate)).FromMaybe(false)) | 743 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(location), V8Intern
alValueType::kLocation)) |
| 716 return v8::Null(m_isolate); | 744 return v8::Null(m_isolate); |
| 717 return location; | 745 return location; |
| 718 } | 746 } |
| 747 |
| 748 v8::Local<v8::Value> V8DebuggerImpl::functionLocation(v8::Local<v8::Context> con
text, v8::Local<v8::Function> function) |
| 749 { |
| 750 int scriptId = function->ScriptId(); |
| 751 if (scriptId == v8::UnboundScript::kNoScriptId) |
| 752 return v8::Null(m_isolate); |
| 753 int lineNumber = function->GetScriptLineNumber(); |
| 754 int columnNumber = function->GetScriptColumnNumber(); |
| 755 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F
unction::kLineOffsetNotFound) |
| 756 return v8::Null(m_isolate); |
| 757 v8::Local<v8::Object> location = v8::Object::New(m_isolate); |
| 758 if (!location->Set(context, v8InternalizedString("scriptId"), toV8String(m_i
solate, String16::number(scriptId))).FromMaybe(false)) |
| 759 return v8::Null(m_isolate); |
| 760 if (!location->Set(context, v8InternalizedString("lineNumber"), v8::Integer:
:New(m_isolate, lineNumber)).FromMaybe(false)) |
| 761 return v8::Null(m_isolate); |
| 762 if (!location->Set(context, v8InternalizedString("columnNumber"), v8::Intege
r::New(m_isolate, columnNumber)).FromMaybe(false)) |
| 763 return v8::Null(m_isolate); |
| 764 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) |
| 765 return v8::Null(m_isolate); |
| 766 return location; |
| 767 } |
| 719 | 768 |
| 720 bool V8DebuggerImpl::isPaused() | 769 bool V8DebuggerImpl::isPaused() |
| 721 { | 770 { |
| 722 return !m_pausedContext.IsEmpty(); | 771 return !m_pausedContext.IsEmpty(); |
| 723 } | 772 } |
| 724 | 773 |
| 725 v8::MaybeLocal<v8::Value> V8DebuggerImpl::runCompiledScript(v8::Local<v8::Contex
t> context, v8::Local<v8::Script> script) | 774 v8::MaybeLocal<v8::Value> V8DebuggerImpl::runCompiledScript(v8::Local<v8::Contex
t> context, v8::Local<v8::Script> script) |
| 726 { | 775 { |
| 727 // TODO(dgozman): get rid of this check. | 776 // TODO(dgozman): get rid of this check. |
| 728 if (!m_client->isExecutionAllowed()) | 777 if (!m_client->isExecutionAllowed()) |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 | 1178 |
| 1130 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI
d) | 1179 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI
d) |
| 1131 { | 1180 { |
| 1132 if (!contextGroupId) | 1181 if (!contextGroupId) |
| 1133 return nullptr; | 1182 return nullptr; |
| 1134 SessionMap::iterator iter = m_sessions.find(contextGroupId); | 1183 SessionMap::iterator iter = m_sessions.find(contextGroupId); |
| 1135 return iter == m_sessions.end() ? nullptr : iter->second; | 1184 return iter == m_sessions.end() ? nullptr : iter->second; |
| 1136 } | 1185 } |
| 1137 | 1186 |
| 1138 } // namespace blink | 1187 } // namespace blink |
| OLD | NEW |