OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-debugger.h" | 5 #include "src/inspector/v8-debugger.h" |
6 | 6 |
7 #include "src/inspector/debugger-script.h" | 7 #include "src/inspector/debugger-script.h" |
8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
10 #include "src/inspector/script-breakpoint.h" | 10 #include "src/inspector/script-breakpoint.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 createDataProperty(context, wrappedEntries, wrappedEntries->Length(), | 73 createDataProperty(context, wrappedEntries, wrappedEntries->Length(), |
74 wrapper); | 74 wrapper); |
75 } | 75 } |
76 if (!markArrayEntriesAsInternal(context, wrappedEntries, | 76 if (!markArrayEntriesAsInternal(context, wrappedEntries, |
77 V8InternalValueType::kEntry)) { | 77 V8InternalValueType::kEntry)) { |
78 return v8::MaybeLocal<v8::Array>(); | 78 return v8::MaybeLocal<v8::Array>(); |
79 } | 79 } |
80 return wrappedEntries; | 80 return wrappedEntries; |
81 } | 81 } |
82 | 82 |
| 83 v8::MaybeLocal<v8::Object> buildLocation(v8::Local<v8::Context> context, |
| 84 int scriptId, int lineNumber, |
| 85 int columnNumber) { |
| 86 if (scriptId == v8::UnboundScript::kNoScriptId) |
| 87 return v8::MaybeLocal<v8::Object>(); |
| 88 if (lineNumber == v8::Function::kLineOffsetNotFound || |
| 89 columnNumber == v8::Function::kLineOffsetNotFound) { |
| 90 return v8::MaybeLocal<v8::Object>(); |
| 91 } |
| 92 v8::Isolate* isolate = context->GetIsolate(); |
| 93 v8::Local<v8::Object> location = v8::Object::New(isolate); |
| 94 if (!location->SetPrototype(context, v8::Null(isolate)).FromMaybe(false)) { |
| 95 return v8::MaybeLocal<v8::Object>(); |
| 96 } |
| 97 if (!createDataProperty(context, location, |
| 98 toV8StringInternalized(isolate, "scriptId"), |
| 99 toV8String(isolate, String16::fromInteger(scriptId))) |
| 100 .FromMaybe(false)) { |
| 101 return v8::MaybeLocal<v8::Object>(); |
| 102 } |
| 103 if (!createDataProperty(context, location, |
| 104 toV8StringInternalized(isolate, "lineNumber"), |
| 105 v8::Integer::New(isolate, lineNumber)) |
| 106 .FromMaybe(false)) { |
| 107 return v8::MaybeLocal<v8::Object>(); |
| 108 } |
| 109 if (!createDataProperty(context, location, |
| 110 toV8StringInternalized(isolate, "columnNumber"), |
| 111 v8::Integer::New(isolate, columnNumber)) |
| 112 .FromMaybe(false)) { |
| 113 return v8::MaybeLocal<v8::Object>(); |
| 114 } |
| 115 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) { |
| 116 return v8::MaybeLocal<v8::Object>(); |
| 117 } |
| 118 return location; |
| 119 } |
| 120 |
| 121 v8::MaybeLocal<v8::Object> generatorObjectLocation( |
| 122 v8::Local<v8::Context> context, v8::Local<v8::Value> value) { |
| 123 if (!value->IsGeneratorObject()) return v8::MaybeLocal<v8::Object>(); |
| 124 v8::Local<v8::debug::GeneratorObject> generatorObject = |
| 125 v8::debug::GeneratorObject::Cast(value); |
| 126 if (!generatorObject->IsSuspended()) { |
| 127 v8::Local<v8::Function> func = generatorObject->Function(); |
| 128 return buildLocation(context, func->ScriptId(), func->GetScriptLineNumber(), |
| 129 func->GetScriptColumnNumber()); |
| 130 } |
| 131 v8::Local<v8::debug::Script> script; |
| 132 if (!generatorObject->Script().ToLocal(&script)) |
| 133 return v8::MaybeLocal<v8::Object>(); |
| 134 v8::debug::Location suspendedLocation = generatorObject->SuspendedLocation(); |
| 135 return buildLocation(context, script->Id(), suspendedLocation.GetLineNumber(), |
| 136 suspendedLocation.GetColumnNumber()); |
| 137 } |
| 138 |
83 } // namespace | 139 } // namespace |
84 | 140 |
85 static bool inLiveEditScope = false; | 141 static bool inLiveEditScope = false; |
86 | 142 |
87 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( | 143 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( |
88 const char* functionName, int argc, v8::Local<v8::Value> argv[], | 144 const char* functionName, int argc, v8::Local<v8::Value> argv[], |
89 bool catchExceptions) { | 145 bool catchExceptions) { |
90 v8::MicrotasksScope microtasks(m_isolate, | 146 v8::MicrotasksScope microtasks(m_isolate, |
91 v8::MicrotasksScope::kDoNotRunMicrotasks); | 147 v8::MicrotasksScope::kDoNotRunMicrotasks); |
92 DCHECK(m_isolate->InContext()); | 148 DCHECK(m_isolate->InContext()); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 return getTargetScopes(context, generator, GENERATOR); | 756 return getTargetScopes(context, generator, GENERATOR); |
701 } | 757 } |
702 | 758 |
703 v8::MaybeLocal<v8::Array> V8Debugger::internalProperties( | 759 v8::MaybeLocal<v8::Array> V8Debugger::internalProperties( |
704 v8::Local<v8::Context> context, v8::Local<v8::Value> value) { | 760 v8::Local<v8::Context> context, v8::Local<v8::Value> value) { |
705 v8::Local<v8::Array> properties; | 761 v8::Local<v8::Array> properties; |
706 if (!v8::debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)) | 762 if (!v8::debug::GetInternalProperties(m_isolate, value).ToLocal(&properties)) |
707 return v8::MaybeLocal<v8::Array>(); | 763 return v8::MaybeLocal<v8::Array>(); |
708 if (value->IsFunction()) { | 764 if (value->IsFunction()) { |
709 v8::Local<v8::Function> function = value.As<v8::Function>(); | 765 v8::Local<v8::Function> function = value.As<v8::Function>(); |
710 v8::Local<v8::Value> location = functionLocation(context, function); | 766 v8::Local<v8::Object> location; |
711 if (location->IsObject()) { | 767 if (buildLocation(context, function->ScriptId(), |
| 768 function->GetScriptLineNumber(), |
| 769 function->GetScriptColumnNumber()) |
| 770 .ToLocal(&location)) { |
712 createDataProperty( | 771 createDataProperty( |
713 context, properties, properties->Length(), | 772 context, properties, properties->Length(), |
714 toV8StringInternalized(m_isolate, "[[FunctionLocation]]")); | 773 toV8StringInternalized(m_isolate, "[[FunctionLocation]]")); |
715 createDataProperty(context, properties, properties->Length(), location); | 774 createDataProperty(context, properties, properties->Length(), location); |
716 } | 775 } |
717 if (function->IsGeneratorFunction()) { | 776 if (function->IsGeneratorFunction()) { |
718 createDataProperty(context, properties, properties->Length(), | 777 createDataProperty(context, properties, properties->Length(), |
719 toV8StringInternalized(m_isolate, "[[IsGenerator]]")); | 778 toV8StringInternalized(m_isolate, "[[IsGenerator]]")); |
720 createDataProperty(context, properties, properties->Length(), | 779 createDataProperty(context, properties, properties->Length(), |
721 v8::True(m_isolate)); | 780 v8::True(m_isolate)); |
722 } | 781 } |
723 } | 782 } |
724 v8::Local<v8::Array> entries; | 783 v8::Local<v8::Array> entries; |
725 if (collectionsEntries(context, value).ToLocal(&entries)) { | 784 if (collectionsEntries(context, value).ToLocal(&entries)) { |
726 createDataProperty(context, properties, properties->Length(), | 785 createDataProperty(context, properties, properties->Length(), |
727 toV8StringInternalized(m_isolate, "[[Entries]]")); | 786 toV8StringInternalized(m_isolate, "[[Entries]]")); |
728 createDataProperty(context, properties, properties->Length(), entries); | 787 createDataProperty(context, properties, properties->Length(), entries); |
729 } | 788 } |
730 if (!enabled()) return properties; | |
731 if (value->IsGeneratorObject()) { | 789 if (value->IsGeneratorObject()) { |
732 v8::Local<v8::Value> location = | 790 v8::Local<v8::Object> location; |
733 generatorObjectLocation(context, v8::Local<v8::Object>::Cast(value)); | 791 if (generatorObjectLocation(context, value).ToLocal(&location)) { |
734 if (location->IsObject()) { | |
735 createDataProperty( | 792 createDataProperty( |
736 context, properties, properties->Length(), | 793 context, properties, properties->Length(), |
737 toV8StringInternalized(m_isolate, "[[GeneratorLocation]]")); | 794 toV8StringInternalized(m_isolate, "[[GeneratorLocation]]")); |
738 createDataProperty(context, properties, properties->Length(), location); | 795 createDataProperty(context, properties, properties->Length(), location); |
739 } | 796 } |
| 797 if (!enabled()) return properties; |
740 v8::Local<v8::Value> scopes; | 798 v8::Local<v8::Value> scopes; |
741 if (generatorScopes(context, value).ToLocal(&scopes)) { | 799 if (generatorScopes(context, value).ToLocal(&scopes)) { |
742 createDataProperty(context, properties, properties->Length(), | 800 createDataProperty(context, properties, properties->Length(), |
743 toV8StringInternalized(m_isolate, "[[Scopes]]")); | 801 toV8StringInternalized(m_isolate, "[[Scopes]]")); |
744 createDataProperty(context, properties, properties->Length(), scopes); | 802 createDataProperty(context, properties, properties->Length(), scopes); |
745 } | 803 } |
746 } | 804 } |
| 805 if (!enabled()) return properties; |
747 if (value->IsFunction()) { | 806 if (value->IsFunction()) { |
748 v8::Local<v8::Function> function = value.As<v8::Function>(); | 807 v8::Local<v8::Function> function = value.As<v8::Function>(); |
749 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); | 808 v8::Local<v8::Value> boundFunction = function->GetBoundFunction(); |
750 v8::Local<v8::Value> scopes; | 809 v8::Local<v8::Value> scopes; |
751 if (boundFunction->IsUndefined() && | 810 if (boundFunction->IsUndefined() && |
752 functionScopes(context, function).ToLocal(&scopes)) { | 811 functionScopes(context, function).ToLocal(&scopes)) { |
753 createDataProperty(context, properties, properties->Length(), | 812 createDataProperty(context, properties, properties->Length(), |
754 toV8StringInternalized(m_isolate, "[[Scopes]]")); | 813 toV8StringInternalized(m_isolate, "[[Scopes]]")); |
755 createDataProperty(context, properties, properties->Length(), scopes); | 814 createDataProperty(context, properties, properties->Length(), scopes); |
756 } | 815 } |
757 } | 816 } |
758 return properties; | 817 return properties; |
759 } | 818 } |
760 | 819 |
761 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( | |
762 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { | |
763 if (!enabled()) { | |
764 UNREACHABLE(); | |
765 return v8::Null(m_isolate); | |
766 } | |
767 v8::Local<v8::Value> argv[] = {object}; | |
768 v8::Local<v8::Value> location; | |
769 v8::Local<v8::Value> copied; | |
770 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv, true) | |
771 .ToLocal(&location) || | |
772 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, | |
773 location) | |
774 .ToLocal(&copied) || | |
775 !copied->IsObject()) | |
776 return v8::Null(m_isolate); | |
777 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), | |
778 V8InternalValueType::kLocation)) | |
779 return v8::Null(m_isolate); | |
780 return copied; | |
781 } | |
782 | |
783 v8::Local<v8::Value> V8Debugger::functionLocation( | |
784 v8::Local<v8::Context> context, v8::Local<v8::Function> function) { | |
785 int scriptId = function->ScriptId(); | |
786 if (scriptId == v8::UnboundScript::kNoScriptId) return v8::Null(m_isolate); | |
787 int lineNumber = function->GetScriptLineNumber(); | |
788 int columnNumber = function->GetScriptColumnNumber(); | |
789 if (lineNumber == v8::Function::kLineOffsetNotFound || | |
790 columnNumber == v8::Function::kLineOffsetNotFound) | |
791 return v8::Null(m_isolate); | |
792 v8::Local<v8::Object> location = v8::Object::New(m_isolate); | |
793 if (!location->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) | |
794 return v8::Null(m_isolate); | |
795 if (!createDataProperty( | |
796 context, location, toV8StringInternalized(m_isolate, "scriptId"), | |
797 toV8String(m_isolate, String16::fromInteger(scriptId))) | |
798 .FromMaybe(false)) | |
799 return v8::Null(m_isolate); | |
800 if (!createDataProperty(context, location, | |
801 toV8StringInternalized(m_isolate, "lineNumber"), | |
802 v8::Integer::New(m_isolate, lineNumber)) | |
803 .FromMaybe(false)) | |
804 return v8::Null(m_isolate); | |
805 if (!createDataProperty(context, location, | |
806 toV8StringInternalized(m_isolate, "columnNumber"), | |
807 v8::Integer::New(m_isolate, columnNumber)) | |
808 .FromMaybe(false)) | |
809 return v8::Null(m_isolate); | |
810 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) | |
811 return v8::Null(m_isolate); | |
812 return location; | |
813 } | |
814 | |
815 std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace( | 820 std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace( |
816 v8::Local<v8::StackTrace> stackTrace) { | 821 v8::Local<v8::StackTrace> stackTrace) { |
817 int contextGroupId = | 822 int contextGroupId = |
818 m_isolate->InContext() | 823 m_isolate->InContext() |
819 ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) | 824 ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) |
820 : 0; | 825 : 0; |
821 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, | 826 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, |
822 V8StackTraceImpl::maxCallStackSizeToCapture); | 827 V8StackTraceImpl::maxCallStackSizeToCapture); |
823 } | 828 } |
824 | 829 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 | 977 |
973 size_t stackSize = | 978 size_t stackSize = |
974 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 979 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
975 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 980 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
976 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 981 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
977 | 982 |
978 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 983 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
979 } | 984 } |
980 | 985 |
981 } // namespace v8_inspector | 986 } // namespace v8_inspector |
OLD | NEW |