| 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/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/v8_inspector/InspectedContext.h" | 8 #include "platform/v8_inspector/InspectedContext.h" |
| 9 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" |
| 9 #include "platform/v8_inspector/V8DebuggerImpl.h" | 10 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 10 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 11 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
| 11 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" | 12 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
| 12 #include "platform/v8_inspector/V8StackTraceImpl.h" | 13 #include "platform/v8_inspector/V8StackTraceImpl.h" |
| 13 #include "platform/v8_inspector/V8StringUtil.h" | 14 #include "platform/v8_inspector/V8StringUtil.h" |
| 14 #include "platform/v8_inspector/public/ConsoleAPITypes.h" | 15 #include "platform/v8_inspector/public/ConsoleAPITypes.h" |
| 15 #include "platform/v8_inspector/public/ConsoleTypes.h" | 16 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 16 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 17 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 166 |
| 166 void setDoubleOnMap(v8::Local<v8::Map> map, const String16& key, double valu
e) | 167 void setDoubleOnMap(v8::Local<v8::Map> map, const String16& key, double valu
e) |
| 167 { | 168 { |
| 168 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); | 169 v8::Local<v8::String> v8Key = toV8String(m_isolate, key); |
| 169 if (!map->Set(m_context, v8Key, v8::Number::New(m_isolate, value)).ToLoc
al(&map)) | 170 if (!map->Set(m_context, v8Key, v8::Number::New(m_isolate, value)).ToLoc
al(&map)) |
| 170 return; | 171 return; |
| 171 } | 172 } |
| 172 | 173 |
| 173 V8ProfilerAgentImpl* profilerAgent() | 174 V8ProfilerAgentImpl* profilerAgent() |
| 174 { | 175 { |
| 175 InspectedContext* inspectedContext = ensureInspectedContext(); | 176 if (V8InspectorSessionImpl* session = currentSession()) { |
| 176 if (!inspectedContext) | 177 if (session && session->profilerAgentImpl()->enabled()) |
| 177 return nullptr; | 178 return session->profilerAgentImpl(); |
| 178 V8InspectorSessionImpl* session = inspectedContext->debugger()->sessionF
orContextGroup(inspectedContext->contextGroupId()); | 179 } |
| 179 if (session && session->profilerAgentImpl()->enabled()) | 180 return nullptr; |
| 180 return session->profilerAgentImpl(); | 181 } |
| 182 |
| 183 V8DebuggerAgentImpl* debuggerAgent() |
| 184 { |
| 185 if (V8InspectorSessionImpl* session = currentSession()) { |
| 186 if (session && session->debuggerAgentImpl()->enabled()) |
| 187 return session->debuggerAgentImpl(); |
| 188 } |
| 181 return nullptr; | 189 return nullptr; |
| 182 } | 190 } |
| 183 private: | 191 private: |
| 184 const v8::FunctionCallbackInfo<v8::Value>& m_info; | 192 const v8::FunctionCallbackInfo<v8::Value>& m_info; |
| 185 v8::Isolate* m_isolate; | 193 v8::Isolate* m_isolate; |
| 186 v8::Local<v8::Context> m_context; | 194 v8::Local<v8::Context> m_context; |
| 187 v8::Local<v8::Object> m_console; | 195 v8::Local<v8::Object> m_console; |
| 188 InspectedContext* m_inspectedContext; | 196 InspectedContext* m_inspectedContext; |
| 189 V8DebuggerClient* m_debuggerClient; | 197 V8DebuggerClient* m_debuggerClient; |
| 190 | 198 |
| 191 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue) | 199 bool checkAndSetPrivateFlagOnConsole(const char* name, bool defaultValue) |
| 192 { | 200 { |
| 193 v8::Local<v8::Object> console = ensureConsole(); | 201 v8::Local<v8::Object> console = ensureConsole(); |
| 194 v8::Local<v8::Private> key = v8::Private::ForApi(m_isolate, toV8StringIn
ternalized(m_isolate, name)); | 202 v8::Local<v8::Private> key = v8::Private::ForApi(m_isolate, toV8StringIn
ternalized(m_isolate, name)); |
| 195 v8::Local<v8::Value> flagValue; | 203 v8::Local<v8::Value> flagValue; |
| 196 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue)) | 204 if (!console->GetPrivate(m_context, key).ToLocal(&flagValue)) |
| 197 return defaultValue; | 205 return defaultValue; |
| 198 ASSERT(flagValue->IsUndefined() || flagValue->IsBoolean()); | 206 ASSERT(flagValue->IsUndefined() || flagValue->IsBoolean()); |
| 199 if (flagValue->IsBoolean()) { | 207 if (flagValue->IsBoolean()) { |
| 200 ASSERT(flagValue.As<v8::Boolean>()->Value()); | 208 ASSERT(flagValue.As<v8::Boolean>()->Value()); |
| 201 return true; | 209 return true; |
| 202 } | 210 } |
| 203 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe(
false)) | 211 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe(
false)) |
| 204 return defaultValue; | 212 return defaultValue; |
| 205 return false; | 213 return false; |
| 206 } | 214 } |
| 215 |
| 216 V8InspectorSessionImpl* currentSession() |
| 217 { |
| 218 InspectedContext* inspectedContext = ensureInspectedContext(); |
| 219 if (!inspectedContext) |
| 220 return nullptr; |
| 221 return inspectedContext->debugger()->sessionForContextGroup(inspectedCon
text->contextGroupId()); |
| 222 } |
| 207 }; | 223 }; |
| 208 | 224 |
| 209 v8::MaybeLocal<v8::Object> createObjectWithClassName(V8DebuggerImpl* debugger, v
8::Local<v8::Context> context, const char* className) | 225 v8::MaybeLocal<v8::Object> createObjectWithClassName(V8DebuggerImpl* debugger, v
8::Local<v8::Context> context, const char* className) |
| 210 { | 226 { |
| 211 v8::Isolate* isolate = debugger->isolate(); | 227 v8::Isolate* isolate = debugger->isolate(); |
| 212 v8::Local<v8::FunctionTemplate> functionTemplate; | 228 v8::Local<v8::FunctionTemplate> functionTemplate; |
| 213 String16 functionTemplateName = String16("V8Console#") + className; | 229 String16 functionTemplateName = String16("V8Console#") + className; |
| 214 if (!debugger->functionTemplate(functionTemplateName).ToLocal(&functionTempl
ate)) { | 230 if (!debugger->functionTemplate(functionTemplateName).ToLocal(&functionTempl
ate)) { |
| 215 functionTemplate = v8::FunctionTemplate::New(isolate); | 231 functionTemplate = v8::FunctionTemplate::New(isolate); |
| 216 functionTemplate->SetClassName(toV8StringInternalized(isolate, className
)); | 232 functionTemplate->SetClassName(toV8StringInternalized(isolate, className
)); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 helper.setIntOnMap(countMap, identifier, count); | 337 helper.setIntOnMap(countMap, identifier, count); |
| 322 helper.addMessage(CountMessageType, DebugMessageLevel, title + ": " + String
16::number(count)); | 338 helper.addMessage(CountMessageType, DebugMessageLevel, title + ": " + String
16::number(count)); |
| 323 } | 339 } |
| 324 | 340 |
| 325 void V8Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) | 341 void V8Console::assertCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 326 { | 342 { |
| 327 ConsoleHelper helper(info); | 343 ConsoleHelper helper(info); |
| 328 if (helper.firstArgToBoolean(false)) | 344 if (helper.firstArgToBoolean(false)) |
| 329 return; | 345 return; |
| 330 helper.addMessage(AssertMessageType, ErrorMessageLevel, true, 1); | 346 helper.addMessage(AssertMessageType, ErrorMessageLevel, true, 1); |
| 347 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) |
| 348 debuggerAgent->breakProgramOnException(protocol::Debugger::Paused::Reaso
nEnum::Assert, nullptr); |
| 331 } | 349 } |
| 332 | 350 |
| 333 void V8Console::markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>&
info) | 351 void V8Console::markTimelineCallback(const v8::FunctionCallbackInfo<v8::Value>&
info) |
| 334 { | 352 { |
| 335 ConsoleHelper(info).addDeprecationMessage("V8Console#markTimelineDeprecated"
, "'console.markTimeline' is deprecated. Please use 'console.timeStamp' instead.
"); | 353 ConsoleHelper(info).addDeprecationMessage("V8Console#markTimelineDeprecated"
, "'console.markTimeline' is deprecated. Please use 'console.timeStamp' instead.
"); |
| 336 timeStampCallback(info); | 354 timeStampCallback(info); |
| 337 } | 355 } |
| 338 | 356 |
| 339 void V8Console::profileCallback(const v8::FunctionCallbackInfo<v8::Value>& info) | 357 void V8Console::profileCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 340 { | 358 { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 return v8::MaybeLocal<v8::Object>(); | 491 return v8::MaybeLocal<v8::Object>(); |
| 474 | 492 |
| 475 if (hasMemoryAttribute) | 493 if (hasMemoryAttribute) |
| 476 console->SetAccessorProperty(toV8StringInternalized(isolate, "memory"),
v8::Function::New(isolate, V8Console::memoryGetterCallback, console), v8::Functi
on::New(isolate, V8Console::memorySetterCallback), static_cast<v8::PropertyAttri
bute>(v8::None), v8::DEFAULT); | 494 console->SetAccessorProperty(toV8StringInternalized(isolate, "memory"),
v8::Function::New(isolate, V8Console::memoryGetterCallback, console), v8::Functi
on::New(isolate, V8Console::memorySetterCallback), static_cast<v8::PropertyAttri
bute>(v8::None), v8::DEFAULT); |
| 477 | 495 |
| 478 console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::Extern
al::New(isolate, inspectedContext)); | 496 console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::Extern
al::New(isolate, inspectedContext)); |
| 479 return console; | 497 return console; |
| 480 } | 498 } |
| 481 | 499 |
| 482 } // namespace blink | 500 } // namespace blink |
| OLD | NEW |