Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerImpl.cpp

Issue 2122423002: [DevTools] Remove functionDetails from protocol.json (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-generator-details-from-protocol
Patch Set: a Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 { 637 {
638 DCHECK(!m_debuggerContext.IsEmpty()); 638 DCHECK(!m_debuggerContext.IsEmpty());
639 return m_debuggerContext.Get(m_isolate); 639 return m_debuggerContext.Get(m_isolate);
640 } 640 }
641 641
642 v8::Local<v8::String> V8DebuggerImpl::v8InternalizedString(const char* str) cons t 642 v8::Local<v8::String> V8DebuggerImpl::v8InternalizedString(const char* str) cons t
643 { 643 {
644 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked(); 644 return v8::String::NewFromUtf8(m_isolate, str, v8::NewStringType::kInternali zed).ToLocalChecked();
645 } 645 }
646 646
647 static bool markArrayWithPrivate(v8::Local<v8::Context> context, v8::Local<v8::A rray> array, v8::Local<v8::Private> privateValue)
648 {
649 v8::Isolate* isolate = context->GetIsolate();
650 for (size_t i = 0; i < array->Length(); ++i) {
651 v8::Local<v8::Value> entry;
652 if (!array->Get(context, i).ToLocal(&entry) || !entry->IsObject())
653 return false;
654 if (!entry.As<v8::Object>()->SetPrivate(context, privateValue, v8::True( isolate)).FromMaybe(false))
655 return false;
656 }
657 return true;
658 }
659
647 v8::MaybeLocal<v8::Value> V8DebuggerImpl::functionScopes(v8::Local<v8::Function> function) 660 v8::MaybeLocal<v8::Value> V8DebuggerImpl::functionScopes(v8::Local<v8::Function> function)
648 { 661 {
649 if (!enabled()) { 662 if (!enabled()) {
650 NOTREACHED(); 663 NOTREACHED();
651 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate)); 664 return v8::Local<v8::Value>::New(m_isolate, v8::Undefined(m_isolate));
652 } 665 }
653 v8::Local<v8::Value> argv[] = { function }; 666 v8::Local<v8::Value> argv[] = { function };
654 return callDebuggerMethod("getFunctionScopes", 1, argv); 667 v8::Local<v8::Value> scopesValue;
668 if (!callDebuggerMethod("getFunctionScopes", 1, argv).ToLocal(&scopesValue) || !scopesValue->IsArray())
669 return v8::MaybeLocal<v8::Value>();
670 v8::Local<v8::Array> scopes = scopesValue.As<v8::Array>();
671 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate);
672 if (!scopes->SetPrivate(context, V8InjectedScriptHost::internalScopesPrivate (m_isolate), v8::True(m_isolate)).FromMaybe(false))
dgozman 2016/07/07 19:59:24 I think we need an enum now, and helper functions:
kozy 2016/07/07 22:59:08 I'm not sure. What are advantages over current app
dgozman 2016/07/08 20:37:29 It brings some order to this system.
673 return v8::MaybeLocal<v8::Value>();
674 if (!markArrayWithPrivate(context, scopes, V8InjectedScriptHost::internalSco pePrivate(m_isolate)))
675 return v8::MaybeLocal<v8::Value>();
676 if (!scopes->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false))
677 return v8::Undefined(m_isolate);
678 return scopes;
655 } 679 }
656 680
657 v8::MaybeLocal<v8::Array> V8DebuggerImpl::internalProperties(v8::Local<v8::Conte xt> context, v8::Local<v8::Value> value) 681 v8::MaybeLocal<v8::Array> V8DebuggerImpl::internalProperties(v8::Local<v8::Conte xt> context, v8::Local<v8::Value> value)
658 { 682 {
659 v8::Local<v8::Array> properties; 683 v8::Local<v8::Array> properties;
660 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties) ) 684 if (!v8::Debug::GetInternalProperties(m_isolate, value).ToLocal(&properties) )
661 return v8::MaybeLocal<v8::Array>(); 685 return v8::MaybeLocal<v8::Array>();
686 if (value->IsFunction()) {
687 v8::Local<v8::Function> function = value.As<v8::Function>();
688 v8::Local<v8::Value> location = functionLocation(context, function);
689 if (location->IsObject()) {
690 properties->Set(properties->Length(), v8InternalizedString("[[Functi onLocation]]"));
691 properties->Set(properties->Length(), location);
692 }
693 v8::Local<v8::Value> functionName = function->GetDebugName();
694 if (functionName->IsString()) {
695 properties->Set(properties->Length(), v8InternalizedString("[[Functi onName]]"));
696 properties->Set(properties->Length(), functionName);
697 }
698 }
662 if (!enabled()) 699 if (!enabled())
663 return properties; 700 return properties;
664 if (value->IsMap() || value->IsWeakMap() || value->IsSet() || value->IsWeakS et() || value->IsSetIterator() || value->IsMapIterator()) { 701 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)); 702 v8::Local<v8::Value> entries = collectionEntries(context, v8::Local<v8:: Object>::Cast(value));
666 if (entries->IsArray()) { 703 if (entries->IsArray()) {
667 properties->Set(properties->Length(), v8InternalizedString("[[Entrie s]]")); 704 properties->Set(properties->Length(), v8InternalizedString("[[Entrie s]]"));
668 properties->Set(properties->Length(), entries); 705 properties->Set(properties->Length(), entries);
669 } 706 }
670 } 707 }
671 if (value->IsGeneratorObject()) { 708 if (value->IsGeneratorObject()) {
672 v8::Local<v8::Value> location = generatorObjectLocation(v8::Local<v8::Ob ject>::Cast(value)); 709 v8::Local<v8::Value> location = generatorObjectLocation(v8::Local<v8::Ob ject>::Cast(value));
673 if (location->IsObject()) { 710 if (location->IsObject()) {
674 properties->Set(properties->Length(), v8InternalizedString("[[Genera torLocation]]")); 711 properties->Set(properties->Length(), v8InternalizedString("[[Genera torLocation]]"));
675 properties->Set(properties->Length(), location); 712 properties->Set(properties->Length(), location);
676 } 713 }
677 } 714 }
715 if (value->IsFunction()) {
716 v8::Local<v8::Function> function = value.As<v8::Function>();
717 v8::Local<v8::Value> boundFunction = function->GetBoundFunction();
718 v8::Local<v8::Value> scopes;
719 if (!boundFunction->IsFunction() && functionScopes(function).ToLocal(&sc opes)) {
dgozman 2016/07/07 19:59:24 Why do we check boundFunction _not_ being a functi
kozy 2016/07/07 22:59:08 Changed to IsUndefined check.
720 properties->Set(properties->Length(), v8InternalizedString("[[Scopes ]]"));
721 properties->Set(properties->Length(), scopes);
722 }
723 properties->Set(properties->Length(), v8InternalizedString("[[IsGenerato r]]"));
724 properties->Set(properties->Length(), v8::Boolean::New(m_isolate, functi on->IsGeneratorFunction()));
dgozman 2016/07/07 19:59:24 This one we can do when disabled.
kozy 2016/07/07 22:59:08 Done.
725 }
678 return properties; 726 return properties;
679 } 727 }
680 728
681 v8::Local<v8::Value> V8DebuggerImpl::collectionEntries(v8::Local<v8::Context> co ntext, v8::Local<v8::Object> object) 729 v8::Local<v8::Value> V8DebuggerImpl::collectionEntries(v8::Local<v8::Context> co ntext, v8::Local<v8::Object> object)
682 { 730 {
683 if (!enabled()) { 731 if (!enabled()) {
684 NOTREACHED(); 732 NOTREACHED();
685 return v8::Undefined(m_isolate); 733 return v8::Undefined(m_isolate);
686 } 734 }
687 v8::Local<v8::Value> argv[] = { object }; 735 v8::Local<v8::Value> argv[] = { object };
688 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries ", 1, argv).ToLocalChecked(); 736 v8::Local<v8::Value> entriesValue = callDebuggerMethod("getCollectionEntries ", 1, argv).ToLocalChecked();
689 if (!entriesValue->IsArray()) 737 if (!entriesValue->IsArray())
690 return v8::Undefined(m_isolate); 738 return v8::Undefined(m_isolate);
691 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); 739 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>();
692 for (size_t i = 0; i < entries->Length(); ++i) { 740 if (!markArrayWithPrivate(context, entries, V8InjectedScriptHost::internalEn tryPrivate(m_isolate)))
693 v8::Local<v8::Value> entry; 741 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)) 742 if (!entries->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false))
700 return v8::Undefined(m_isolate); 743 return v8::Undefined(m_isolate);
701 return entries; 744 return entries;
702 } 745 }
703 746
704 v8::Local<v8::Value> V8DebuggerImpl::generatorObjectLocation(v8::Local<v8::Objec t> object) 747 v8::Local<v8::Value> V8DebuggerImpl::generatorObjectLocation(v8::Local<v8::Objec t> object)
705 { 748 {
706 if (!enabled()) { 749 if (!enabled()) {
707 NOTREACHED(); 750 NOTREACHED();
708 return v8::Null(m_isolate); 751 return v8::Null(m_isolate);
709 } 752 }
710 v8::Local<v8::Value> argv[] = { object }; 753 v8::Local<v8::Value> argv[] = { object };
711 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati on", 1, argv).ToLocalChecked(); 754 v8::Local<v8::Value> location = callDebuggerMethod("getGeneratorObjectLocati on", 1, argv).ToLocalChecked();
712 if (!location->IsObject()) 755 if (!location->IsObject())
713 return v8::Null(m_isolate); 756 return v8::Null(m_isolate);
714 v8::Local<v8::Context> context = m_debuggerContext.Get(m_isolate); 757 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)) 758 if (!location.As<v8::Object>()->SetPrivate(context, V8InjectedScriptHost::in ternalLocationPrivate(m_isolate), v8::True(m_isolate)).FromMaybe(false))
716 return v8::Null(m_isolate); 759 return v8::Null(m_isolate);
717 return location; 760 return location;
718 } 761 }
719 762
763 v8::Local<v8::Value> V8DebuggerImpl::functionLocation(v8::Local<v8::Context> con text, v8::Local<v8::Function> function)
764 {
765 int scriptId = function->ScriptId();
766 if (scriptId == v8::UnboundScript::kNoScriptId)
767 return v8::Null(m_isolate);
768 int lineNumber = function->GetScriptLineNumber();
769 int columnNumber = function->GetScriptColumnNumber();
770 if (lineNumber == v8::Function::kLineOffsetNotFound || columnNumber == v8::F unction::kLineOffsetNotFound)
771 return v8::Null(m_isolate);
772 v8::Local<v8::Object> location = v8::Object::New(m_isolate);
773 if (!location->Set(context, v8InternalizedString("scriptId"), toV8String(m_i solate, String16::number(scriptId))).FromMaybe(false))
774 return v8::Null(m_isolate);
775 if (!location->Set(context, v8InternalizedString("lineNumber"), v8::Integer: :New(m_isolate, lineNumber)).FromMaybe(false))
776 return v8::Null(m_isolate);
777 if (!location->Set(context, v8InternalizedString("columnNumber"), v8::Intege r::New(m_isolate, columnNumber)).FromMaybe(false))
778 return v8::Null(m_isolate);
779 if (!location.As<v8::Object>()->SetPrivate(context, V8InjectedScriptHost::in ternalLocationPrivate(m_isolate), v8::True(m_isolate)).FromMaybe(false))
780 return v8::Null(m_isolate);
781 return location;
782 }
783
720 bool V8DebuggerImpl::isPaused() 784 bool V8DebuggerImpl::isPaused()
721 { 785 {
722 return !m_pausedContext.IsEmpty(); 786 return !m_pausedContext.IsEmpty();
723 } 787 }
724 788
725 v8::MaybeLocal<v8::Value> V8DebuggerImpl::runCompiledScript(v8::Local<v8::Contex t> context, v8::Local<v8::Script> script) 789 v8::MaybeLocal<v8::Value> V8DebuggerImpl::runCompiledScript(v8::Local<v8::Contex t> context, v8::Local<v8::Script> script)
726 { 790 {
727 // TODO(dgozman): get rid of this check. 791 // TODO(dgozman): get rid of this check.
728 if (!m_client->isExecutionAllowed()) 792 if (!m_client->isExecutionAllowed())
729 return v8::MaybeLocal<v8::Value>(); 793 return v8::MaybeLocal<v8::Value>();
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1193
1130 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d) 1194 V8InspectorSessionImpl* V8DebuggerImpl::sessionForContextGroup(int contextGroupI d)
1131 { 1195 {
1132 if (!contextGroupId) 1196 if (!contextGroupId)
1133 return nullptr; 1197 return nullptr;
1134 SessionMap::iterator iter = m_sessions.find(contextGroupId); 1198 SessionMap::iterator iter = m_sessions.find(contextGroupId);
1135 return iter == m_sessions.end() ? nullptr : iter->second; 1199 return iter == m_sessions.end() ? nullptr : iter->second;
1136 } 1200 }
1137 1201
1138 } // namespace blink 1202 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698