| 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/V8Console.h" | 5 #include "platform/v8_inspector/V8Console.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/Platform.h" | 7 #include "platform/inspector_protocol/Platform.h" |
| 8 #include "platform/inspector_protocol/String16.h" | 8 #include "platform/inspector_protocol/String16.h" |
| 9 #include "platform/v8_inspector/InjectedScript.h" | 9 #include "platform/v8_inspector/InjectedScript.h" |
| 10 #include "platform/v8_inspector/InspectedContext.h" | 10 #include "platform/v8_inspector/InspectedContext.h" |
| 11 #include "platform/v8_inspector/V8Compat.h" | 11 #include "platform/v8_inspector/V8Compat.h" |
| 12 #include "platform/v8_inspector/V8ConsoleMessage.h" |
| 12 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" | 13 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 13 #include "platform/v8_inspector/V8DebuggerImpl.h" | 14 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 14 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 15 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 15 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" | 16 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
| 16 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" | 17 #include "platform/v8_inspector/V8RuntimeAgentImpl.h" |
| 17 #include "platform/v8_inspector/V8StackTraceImpl.h" | 18 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 18 #include "platform/v8_inspector/V8StringUtil.h" | 19 #include "platform/v8_inspector/V8StringUtil.h" |
| 19 #include "platform/v8_inspector/public/ConsoleAPITypes.h" | |
| 20 #include "platform/v8_inspector/public/ConsoleTypes.h" | |
| 21 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 20 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 22 | 21 |
| 23 namespace blink { | 22 namespace blink { |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) | 26 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) |
| 28 { | 27 { |
| 29 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Conso
le#InspectedContext")); | 28 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Conso
le#InspectedContext")); |
| 30 } | 29 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 { | 69 { |
| 71 if (m_debuggerClient) | 70 if (m_debuggerClient) |
| 72 return m_debuggerClient; | 71 return m_debuggerClient; |
| 73 InspectedContext* inspectedContext = ensureInspectedContext(); | 72 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 74 if (!inspectedContext) | 73 if (!inspectedContext) |
| 75 return nullptr; | 74 return nullptr; |
| 76 m_debuggerClient = inspectedContext->debugger()->client(); | 75 m_debuggerClient = inspectedContext->debugger()->client(); |
| 77 return m_debuggerClient; | 76 return m_debuggerClient; |
| 78 } | 77 } |
| 79 | 78 |
| 79 void reportMessageToConsole(v8::Local<v8::Context> context, MessageType type
, MessageLevel level, const String16& message, const v8::FunctionCallbackInfo<v8
::Value>* arguments, unsigned skipArgumentCount) |
| 80 { |
| 81 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 82 if (!inspectedContext) |
| 83 return; |
| 84 V8DebuggerImpl* debugger = inspectedContext->debugger(); |
| 85 |
| 86 std::unique_ptr<V8ConsoleMessage> consoleMessage = nullptr; |
| 87 if (arguments) { |
| 88 std::vector<v8::Local<v8::Value>> messageArguments; |
| 89 for (int i = skipArgumentCount; i < arguments->Length(); ++i) |
| 90 messageArguments.push_back((*arguments)[i]); |
| 91 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli
ent()->currentTimeMS(), type, level, message, &messageArguments, debugger->captu
reStackTrace(false), inspectedContext); |
| 92 } else { |
| 93 consoleMessage = V8ConsoleMessage::createForConsoleAPI(debugger->cli
ent()->currentTimeMS(), type, level, message, nullptr, debugger->captureStackTra
ce(false), inspectedContext); |
| 94 } |
| 95 debugger->ensureConsoleMessageStorage(inspectedContext->contextGroupId()
)->addMessage(std::move(consoleMessage)); |
| 96 } |
| 97 |
| 80 void addMessage(MessageType type, MessageLevel level, String16 emptyText, in
t skipArgumentCount) | 98 void addMessage(MessageType type, MessageLevel level, String16 emptyText, in
t skipArgumentCount) |
| 81 { | 99 { |
| 82 if (emptyText.isEmpty() && !m_info.Length()) | 100 if (emptyText.isEmpty() && !m_info.Length()) |
| 83 return; | 101 return; |
| 84 if (V8DebuggerClient* debuggerClient = ensureDebuggerClient()) | 102 reportMessageToConsole(m_context, type, level, m_info.Length() <= skipAr
gumentCount ? emptyText : String16(), &m_info, skipArgumentCount); |
| 85 debuggerClient->reportMessageToConsole(m_context, type, level, m_inf
o.Length() <= skipArgumentCount ? emptyText : String16(), &m_info, skipArgumentC
ount); | |
| 86 } | 103 } |
| 87 | 104 |
| 88 void addMessage(MessageType type, MessageLevel level, const String16& messag
e) | 105 void addMessage(MessageType type, MessageLevel level, const String16& messag
e) |
| 89 { | 106 { |
| 90 if (V8DebuggerClient* debuggerClient = ensureDebuggerClient()) | 107 reportMessageToConsole(m_context, type, level, message, nullptr, 0 /* sk
ipArgumentsCount */); |
| 91 debuggerClient->reportMessageToConsole(m_context, type, level, messa
ge, nullptr, 0 /* skipArgumentsCount */); | |
| 92 } | 108 } |
| 93 | 109 |
| 94 void addDeprecationMessage(const char* id, const String16& message) | 110 void addDeprecationMessage(const char* id, const String16& message) |
| 95 { | 111 { |
| 96 if (checkAndSetPrivateFlagOnConsole(id, false)) | 112 if (checkAndSetPrivateFlagOnConsole(id, false)) |
| 97 return; | 113 return; |
| 98 if (V8DebuggerClient* debuggerClient = ensureDebuggerClient()) | 114 reportMessageToConsole(m_context, LogMessageType, WarningMessageLevel, m
essage, nullptr, 0 /* skipArgumentsCount */); |
| 99 debuggerClient->reportMessageToConsole(m_context, LogMessageType, Wa
rningMessageLevel, message, nullptr, 0 /* skipArgumentsCount */); | |
| 100 } | 115 } |
| 101 | 116 |
| 102 bool firstArgToBoolean(bool defaultValue) | 117 bool firstArgToBoolean(bool defaultValue) |
| 103 { | 118 { |
| 104 if (m_info.Length() < 1) | 119 if (m_info.Length() < 1) |
| 105 return defaultValue; | 120 return defaultValue; |
| 106 if (m_info[0]->IsBoolean()) | 121 if (m_info[0]->IsBoolean()) |
| 107 return m_info[0].As<v8::Boolean>()->Value(); | 122 return m_info[0].As<v8::Boolean>()->Value(); |
| 108 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); | 123 return m_info[0]->BooleanValue(m_context).FromMaybe(defaultValue); |
| 109 } | 124 } |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 continue; | 809 continue; |
| 795 if (name->IsString()) { | 810 if (name->IsString()) { |
| 796 v8::Local<v8::Value> descriptor; | 811 v8::Local<v8::Value> descriptor; |
| 797 bool success = m_global->GetOwnPropertyDescriptor(m_context, v8::Loc
al<v8::String>::Cast(name)).ToLocal(&descriptor); | 812 bool success = m_global->GetOwnPropertyDescriptor(m_context, v8::Loc
al<v8::String>::Cast(name)).ToLocal(&descriptor); |
| 798 DCHECK(success); | 813 DCHECK(success); |
| 799 } | 814 } |
| 800 } | 815 } |
| 801 } | 816 } |
| 802 | 817 |
| 803 } // namespace blink | 818 } // namespace blink |
| OLD | NEW |