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

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

Issue 1916023002: [DevTools] Move last inspected objects to V8InspectorSessionImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-part-command-line-api-to-native
Patch Set: Created 4 years, 7 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 // 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/V8Console.h" 5 #include "platform/v8_inspector/V8Console.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/v8_inspector/InjectedScript.h" 8 #include "platform/v8_inspector/InjectedScript.h"
9 #include "platform/v8_inspector/InspectedContext.h" 9 #include "platform/v8_inspector/InspectedContext.h"
10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
11 #include "platform/v8_inspector/V8DebuggerImpl.h" 11 #include "platform/v8_inspector/V8DebuggerImpl.h"
12 #include "platform/v8_inspector/V8InspectorSessionImpl.h" 12 #include "platform/v8_inspector/V8InspectorSessionImpl.h"
13 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" 13 #include "platform/v8_inspector/V8ProfilerAgentImpl.h"
14 #include "platform/v8_inspector/V8RuntimeAgentImpl.h"
14 #include "platform/v8_inspector/V8StackTraceImpl.h" 15 #include "platform/v8_inspector/V8StackTraceImpl.h"
15 #include "platform/v8_inspector/V8StringUtil.h" 16 #include "platform/v8_inspector/V8StringUtil.h"
16 #include "platform/v8_inspector/public/ConsoleAPITypes.h" 17 #include "platform/v8_inspector/public/ConsoleAPITypes.h"
17 #include "platform/v8_inspector/public/ConsoleTypes.h" 18 #include "platform/v8_inspector/public/ConsoleTypes.h"
18 #include "platform/v8_inspector/public/V8DebuggerClient.h" 19 #include "platform/v8_inspector/public/V8DebuggerClient.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 namespace { 23 namespace {
23 24
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 197 }
197 198
198 V8DebuggerAgentImpl* debuggerAgent() 199 V8DebuggerAgentImpl* debuggerAgent()
199 { 200 {
200 if (V8InspectorSessionImpl* session = currentSession()) { 201 if (V8InspectorSessionImpl* session = currentSession()) {
201 if (session && session->debuggerAgentImpl()->enabled()) 202 if (session && session->debuggerAgentImpl()->enabled())
202 return session->debuggerAgentImpl(); 203 return session->debuggerAgentImpl();
203 } 204 }
204 return nullptr; 205 return nullptr;
205 } 206 }
207
208 V8InspectorSessionImpl* currentSession()
209 {
210 InspectedContext* inspectedContext = ensureInspectedContext();
211 if (!inspectedContext)
212 return nullptr;
213 return inspectedContext->debugger()->sessionForContextGroup(inspectedCon text->contextGroupId());
214 }
215
206 private: 216 private:
207 const v8::FunctionCallbackInfo<v8::Value>& m_info; 217 const v8::FunctionCallbackInfo<v8::Value>& m_info;
208 v8::Isolate* m_isolate; 218 v8::Isolate* m_isolate;
209 v8::Local<v8::Context> m_context; 219 v8::Local<v8::Context> m_context;
210 v8::Local<v8::Object> m_console; 220 v8::Local<v8::Object> m_console;
211 InspectedContext* m_inspectedContext; 221 InspectedContext* m_inspectedContext;
212 V8DebuggerClient* m_debuggerClient; 222 V8DebuggerClient* m_debuggerClient;
213 223
214 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue) 224 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue)
215 { 225 {
216 v8::Local<v8::Object> console = ensureConsole(); 226 v8::Local<v8::Object> console = ensureConsole();
217 v8::Local<v8::Private> key = v8::Private::ForApi(m_isolate, toV8StringIn ternalized(m_isolate, name)); 227 v8::Local<v8::Private> key = v8::Private::ForApi(m_isolate, toV8StringIn ternalized(m_isolate, name));
218 v8::Local<v8::Value> flagValue; 228 v8::Local<v8::Value> flagValue;
219 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue)) 229 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue))
220 return defaultValue; 230 return defaultValue;
221 ASSERT(flagValue->IsUndefined() || flagValue->IsBoolean()); 231 ASSERT(flagValue->IsUndefined() || flagValue->IsBoolean());
222 if (flagValue->IsBoolean()) { 232 if (flagValue->IsBoolean()) {
223 ASSERT(flagValue.As<v8::Boolean>()->Value()); 233 ASSERT(flagValue.As<v8::Boolean>()->Value());
224 return true; 234 return true;
225 } 235 }
226 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe( false)) 236 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe( false))
227 return defaultValue; 237 return defaultValue;
228 return false; 238 return false;
229 } 239 }
230
231 V8InspectorSessionImpl* currentSession()
232 {
233 InspectedContext* inspectedContext = ensureInspectedContext();
234 if (!inspectedContext)
235 return nullptr;
236 return inspectedContext->debugger()->sessionForContextGroup(inspectedCon text->contextGroupId());
237 }
238 }; 240 };
239 241
240 v8::MaybeLocal<v8::Object> createObjectWithClassName(V8DebuggerImpl* debugger, v 8::Local<v8::Context> context, const char* className) 242 v8::MaybeLocal<v8::Object> createObjectWithClassName(V8DebuggerImpl* debugger, v 8::Local<v8::Context> context, const char* className)
241 { 243 {
242 v8::Isolate* isolate = debugger->isolate(); 244 v8::Isolate* isolate = debugger->isolate();
243 v8::Local<v8::FunctionTemplate> functionTemplate; 245 v8::Local<v8::FunctionTemplate> functionTemplate;
244 String16 functionTemplateName = String16("V8Console#") + className; 246 String16 functionTemplateName = String16("V8Console#") + className;
245 if (!debugger->functionTemplate(functionTemplateName).ToLocal(&functionTempl ate)) { 247 if (!debugger->functionTemplate(functionTemplateName).ToLocal(&functionTempl ate)) {
246 functionTemplate = v8::FunctionTemplate::New(isolate); 248 functionTemplate = v8::FunctionTemplate::New(isolate);
247 functionTemplate->SetClassName(toV8StringInternalized(isolate, className )); 249 functionTemplate->SetClassName(toV8StringInternalized(isolate, className ));
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 void V8Console::lastEvaluationResultCallback(const v8::FunctionCallbackInfo<v8:: Value>& info) 575 void V8Console::lastEvaluationResultCallback(const v8::FunctionCallbackInfo<v8:: Value>& info)
574 { 576 {
575 ConsoleHelper helper(info); 577 ConsoleHelper helper(info);
576 InspectedContext* context = helper.ensureInspectedContext(); 578 InspectedContext* context = helper.ensureInspectedContext();
577 if (!context) 579 if (!context)
578 return; 580 return;
579 if (InjectedScript* injectedScript = context->getInjectedScript()) 581 if (InjectedScript* injectedScript = context->getInjectedScript())
580 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); 582 info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
581 } 583 }
582 584
585 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, unsigned num)
586 {
587 ASSERT(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
588 ConsoleHelper helper(info);
589 if (V8InspectorSessionImpl* session = helper.currentSession()) {
590 V8RuntimeAgent::Inspectable* object = session->inspectedObject(num);
591 v8::Isolate* isolate = info.GetIsolate();
592 if (object)
593 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())) ;
594 else
595 info.GetReturnValue().Set(v8::Undefined(isolate));
596 }
597 }
598
583 v8::MaybeLocal<v8::Object> V8Console::createConsole(InspectedContext* inspectedC ontext, bool hasMemoryAttribute) 599 v8::MaybeLocal<v8::Object> V8Console::createConsole(InspectedContext* inspectedC ontext, bool hasMemoryAttribute)
584 { 600 {
585 v8::Local<v8::Context> context = inspectedContext->context(); 601 v8::Local<v8::Context> context = inspectedContext->context();
586 v8::Isolate* isolate = context->GetIsolate(); 602 v8::Isolate* isolate = context->GetIsolate();
587 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks); 603 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
588 604
589 v8::Local<v8::Object> console; 605 v8::Local<v8::Object> console;
590 if (!createObjectWithClassName(inspectedContext->debugger(), context, "Conso le").ToLocal(&console)) 606 if (!createObjectWithClassName(inspectedContext->debugger(), context, "Conso le").ToLocal(&console))
591 return v8::MaybeLocal<v8::Object>(); 607 return v8::MaybeLocal<v8::Object>();
592 608
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "clear" , V8Console::clearCallback); 659 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "clear" , V8Console::clearCallback);
644 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "table" , V8Console::tableCallback); 660 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "table" , V8Console::tableCallback);
645 661
646 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "keys", V8Console::keysCallback); 662 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "keys", V8Console::keysCallback);
647 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "values ", V8Console::valuesCallback); 663 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "values ", V8Console::valuesCallback);
648 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "debug" , V8Console::debugFunctionCallback); 664 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "debug" , V8Console::debugFunctionCallback);
649 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "undebu g", V8Console::undebugFunctionCallback); 665 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "undebu g", V8Console::undebugFunctionCallback);
650 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "monito r", V8Console::monitorFunctionCallback); 666 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "monito r", V8Console::monitorFunctionCallback);
651 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "unmoni tor", V8Console::unmonitorFunctionCallback); 667 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "unmoni tor", V8Console::unmonitorFunctionCallback);
652 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$_", V 8Console::lastEvaluationResultCallback); 668 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$_", V 8Console::lastEvaluationResultCallback);
669 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$0", V 8Console::inspectedObject0);
670 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$1", V 8Console::inspectedObject1);
671 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$2", V 8Console::inspectedObject2);
672 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$3", V 8Console::inspectedObject3);
673 createBoundFunctionProperty(context, commandLineAPI, commandLineAPI, "$4", V 8Console::inspectedObject4);
653 674
654 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate), v8: :External::New(isolate, inspectedContext)); 675 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate), v8: :External::New(isolate, inspectedContext));
655 return commandLineAPI; 676 return commandLineAPI;
656 } 677 }
657 678
658 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, v8 ::Local<v8::Object> console) 679 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, v8 ::Local<v8::Object> console)
659 { 680 {
660 v8::Isolate* isolate = context->GetIsolate(); 681 v8::Isolate* isolate = context->GetIsolate();
661 console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::Extern al::New(isolate, nullptr)); 682 console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::Extern al::New(isolate, nullptr));
662 } 683 }
(...skipping 16 matching lines...) Expand all
679 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ()); 700 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ());
680 if (getters.size() == 0) { 701 if (getters.size() == 0) {
681 const char* members[] = { "$0", "$1", "$2", "$3", "$4", "$_" }; 702 const char* members[] = { "$0", "$1", "$2", "$3", "$4", "$_" };
682 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i) 703 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i)
683 getters.add(members[i]); 704 getters.add(members[i]);
684 } 705 }
685 return getters.find(name) != getters.end(); 706 return getters.find(name) != getters.end();
686 } 707 }
687 708
688 } // namespace blink 709 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698