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

Side by Side Diff: src/inspector/v8-console.cc

Issue 2785293002: [inspector] move console to builtins (Closed)
Patch Set: removed unused variable Created 3 years, 8 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
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-inspector-impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-console.h" 5 #include "src/inspector/v8-console.h"
6 6
7 #include "src/base/macros.h" 7 #include "src/base/macros.h"
8 #include "src/inspector/injected-script.h" 8 #include "src/inspector/injected-script.h"
9 #include "src/inspector/inspected-context.h" 9 #include "src/inspector/inspected-context.h"
10 #include "src/inspector/string-util.h" 10 #include "src/inspector/string-util.h"
11 #include "src/inspector/v8-console-message.h" 11 #include "src/inspector/v8-console-message.h"
12 #include "src/inspector/v8-debugger-agent-impl.h" 12 #include "src/inspector/v8-debugger-agent-impl.h"
13 #include "src/inspector/v8-inspector-impl.h" 13 #include "src/inspector/v8-inspector-impl.h"
14 #include "src/inspector/v8-inspector-session-impl.h" 14 #include "src/inspector/v8-inspector-session-impl.h"
15 #include "src/inspector/v8-profiler-agent-impl.h" 15 #include "src/inspector/v8-profiler-agent-impl.h"
16 #include "src/inspector/v8-runtime-agent-impl.h" 16 #include "src/inspector/v8-runtime-agent-impl.h"
17 #include "src/inspector/v8-stack-trace-impl.h" 17 #include "src/inspector/v8-stack-trace-impl.h"
18 #include "src/inspector/v8-value-copier.h" 18 #include "src/inspector/v8-value-copier.h"
19 19
20 #include "include/v8-inspector.h" 20 #include "include/v8-inspector.h"
21 21
22 namespace v8_inspector { 22 namespace v8_inspector {
23 23
24 namespace { 24 namespace {
25 25
26 class ConsoleHelper { 26 class ConsoleHelper {
27 public: 27 public:
28 explicit ConsoleHelper(const v8::FunctionCallbackInfo<v8::Value>& info, 28 ConsoleHelper(const v8::debug::ConsoleCallArguments& info,
29 V8InspectorImpl* inspector) 29 V8InspectorImpl* inspector)
30 : m_info(info), 30 : m_info(info),
31 m_isolate(info.GetIsolate()), 31 m_isolate(inspector->isolate()),
32 m_context(info.GetIsolate()->GetCurrentContext()), 32 m_context(m_isolate->GetCurrentContext()),
33 m_inspector(inspector), 33 m_inspector(inspector),
34 m_contextId(InspectedContext::contextId(m_context)), 34 m_contextId(InspectedContext::contextId(m_context)),
35 m_groupId(m_inspector->contextGroupId(m_contextId)) {} 35 m_groupId(m_inspector->contextGroupId(m_contextId)) {}
36 36
37 int contextId() const { return m_contextId; } 37 int contextId() const { return m_contextId; }
38 int groupId() const { return m_groupId; } 38 int groupId() const { return m_groupId; }
39 39
40 InjectedScript* injectedScript() { 40 InjectedScript* injectedScript() {
41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId); 41 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
42 if (!context) return nullptr; 42 if (!context) return nullptr;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return session->debuggerAgent(); 138 return session->debuggerAgent();
139 } 139 }
140 return nullptr; 140 return nullptr;
141 } 141 }
142 142
143 V8InspectorSessionImpl* currentSession() { 143 V8InspectorSessionImpl* currentSession() {
144 return m_inspector->sessionForContextGroup(m_groupId); 144 return m_inspector->sessionForContextGroup(m_groupId);
145 } 145 }
146 146
147 private: 147 private:
148 const v8::FunctionCallbackInfo<v8::Value>& m_info; 148 const v8::debug::ConsoleCallArguments& m_info;
149 v8::Isolate* m_isolate; 149 v8::Isolate* m_isolate;
150 v8::Local<v8::Context> m_context; 150 v8::Local<v8::Context> m_context;
151 V8InspectorImpl* m_inspector = nullptr; 151 V8InspectorImpl* m_inspector = nullptr;
152 int m_contextId; 152 int m_contextId;
153 int m_groupId; 153 int m_groupId;
154 154
155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper); 155 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper);
156 }; 156 };
157 157
158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 158 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
(...skipping 24 matching lines...) Expand all
183 context->GetIsolate(), "toString"), 183 context->GetIsolate(), "toString"),
184 toStringFunction); 184 toStringFunction);
185 } 185 }
186 createDataProperty(context, console, funcName, func); 186 createDataProperty(context, console, funcName, func);
187 } 187 }
188 188
189 } // namespace 189 } // namespace
190 190
191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {} 191 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
192 192
193 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 193 void V8Console::Debug(const v8::debug::ConsoleCallArguments& info) {
194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug); 194 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDebug);
195 } 195 }
196 196
197 void V8Console::errorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 197 void V8Console::Error(const v8::debug::ConsoleCallArguments& info) {
198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError); 198 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kError);
199 } 199 }
200 200
201 void V8Console::infoCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 201 void V8Console::Info(const v8::debug::ConsoleCallArguments& info) {
202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo); 202 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kInfo);
203 } 203 }
204 204
205 void V8Console::logCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 205 void V8Console::Log(const v8::debug::ConsoleCallArguments& info) {
206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog); 206 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kLog);
207 } 207 }
208 208
209 void V8Console::warnCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 209 void V8Console::Warn(const v8::debug::ConsoleCallArguments& info) {
210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning); 210 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kWarning);
211 } 211 }
212 212
213 void V8Console::dirCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 213 void V8Console::Dir(const v8::debug::ConsoleCallArguments& info) {
214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir); 214 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDir);
215 } 215 }
216 216
217 void V8Console::dirxmlCallback( 217 void V8Console::DirXml(const v8::debug::ConsoleCallArguments& info) {
218 const v8::FunctionCallbackInfo<v8::Value>& info) {
219 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML); 218 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kDirXML);
220 } 219 }
221 220
222 void V8Console::tableCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 221 void V8Console::Table(const v8::debug::ConsoleCallArguments& info) {
223 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable); 222 ConsoleHelper(info, m_inspector).reportCall(ConsoleAPIType::kTable);
224 } 223 }
225 224
226 void V8Console::traceCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 225 void V8Console::Trace(const v8::debug::ConsoleCallArguments& info) {
227 ConsoleHelper(info, m_inspector) 226 ConsoleHelper(info, m_inspector)
228 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace, 227 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
229 String16("console.trace")); 228 String16("console.trace"));
230 } 229 }
231 230
232 void V8Console::groupCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 231 void V8Console::Group(const v8::debug::ConsoleCallArguments& info) {
233 ConsoleHelper(info, m_inspector) 232 ConsoleHelper(info, m_inspector)
234 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup, 233 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
235 String16("console.group")); 234 String16("console.group"));
236 } 235 }
237 236
238 void V8Console::groupCollapsedCallback( 237 void V8Console::GroupCollapsed(const v8::debug::ConsoleCallArguments& info) {
239 const v8::FunctionCallbackInfo<v8::Value>& info) {
240 ConsoleHelper(info, m_inspector) 238 ConsoleHelper(info, m_inspector)
241 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed, 239 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
242 String16("console.groupCollapsed")); 240 String16("console.groupCollapsed"));
243 } 241 }
244 242
245 void V8Console::groupEndCallback( 243 void V8Console::GroupEnd(const v8::debug::ConsoleCallArguments& info) {
246 const v8::FunctionCallbackInfo<v8::Value>& info) {
247 ConsoleHelper(info, m_inspector) 244 ConsoleHelper(info, m_inspector)
248 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup, 245 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
249 String16("console.groupEnd")); 246 String16("console.groupEnd"));
250 } 247 }
251 248
252 void V8Console::clearCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 249 void V8Console::Clear(const v8::debug::ConsoleCallArguments& info) {
253 ConsoleHelper helper(info, m_inspector); 250 ConsoleHelper helper(info, m_inspector);
254 if (!helper.groupId()) return; 251 if (!helper.groupId()) return;
255 m_inspector->client()->consoleClear(helper.groupId()); 252 m_inspector->client()->consoleClear(helper.groupId());
256 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear, 253 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
257 String16("console.clear")); 254 String16("console.clear"));
258 } 255 }
259 256
260 void V8Console::countCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 257 void V8Console::Count(const v8::debug::ConsoleCallArguments& info) {
261 ConsoleHelper helper(info, m_inspector); 258 ConsoleHelper helper(info, m_inspector);
262 String16 title = helper.firstArgToString(String16()); 259 String16 title = helper.firstArgToString(String16());
263 String16 identifier; 260 String16 identifier;
264 if (title.isEmpty()) { 261 if (title.isEmpty()) {
265 std::unique_ptr<V8StackTraceImpl> stackTrace = 262 std::unique_ptr<V8StackTraceImpl> stackTrace =
266 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1); 263 V8StackTraceImpl::capture(m_inspector->debugger(), 0, 1);
267 if (stackTrace && !stackTrace->isEmpty()) { 264 if (stackTrace && !stackTrace->isEmpty()) {
268 identifier = toString16(stackTrace->topSourceURL()) + ":" + 265 identifier = toString16(stackTrace->topSourceURL()) + ":" +
269 String16::fromInteger(stackTrace->topLineNumber()); 266 String16::fromInteger(stackTrace->topLineNumber());
270 } 267 }
271 } else { 268 } else {
272 identifier = title + "@"; 269 identifier = title + "@";
273 } 270 }
274 271
275 int count = 272 int count =
276 helper.consoleMessageStorage()->count(helper.contextId(), identifier); 273 helper.consoleMessageStorage()->count(helper.contextId(), identifier);
277 String16 countString = String16::fromInteger(count); 274 String16 countString = String16::fromInteger(count);
278 helper.reportCallWithArgument( 275 helper.reportCallWithArgument(
279 ConsoleAPIType::kCount, 276 ConsoleAPIType::kCount,
280 title.isEmpty() ? countString : (title + ": " + countString)); 277 title.isEmpty() ? countString : (title + ": " + countString));
281 } 278 }
282 279
283 void V8Console::assertCallback( 280 void V8Console::Assert(const v8::debug::ConsoleCallArguments& info) {
284 const v8::FunctionCallbackInfo<v8::Value>& info) {
285 ConsoleHelper helper(info, m_inspector); 281 ConsoleHelper helper(info, m_inspector);
286 if (helper.firstArgToBoolean(false)) return; 282 if (helper.firstArgToBoolean(false)) return;
287 283
288 std::vector<v8::Local<v8::Value>> arguments; 284 std::vector<v8::Local<v8::Value>> arguments;
289 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]); 285 for (int i = 1; i < info.Length(); ++i) arguments.push_back(info[i]);
290 if (info.Length() < 2) 286 if (info.Length() < 2)
291 arguments.push_back( 287 arguments.push_back(
292 toV8String(info.GetIsolate(), String16("console.assert"))); 288 toV8String(m_inspector->isolate(), String16("console.assert")));
293 helper.reportCall(ConsoleAPIType::kAssert, arguments); 289 helper.reportCall(ConsoleAPIType::kAssert, arguments);
294 290
295 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent()) 291 if (V8DebuggerAgentImpl* debuggerAgent = helper.debuggerAgent())
296 debuggerAgent->breakProgramOnException( 292 debuggerAgent->breakProgramOnException(
297 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr); 293 protocol::Debugger::Paused::ReasonEnum::Assert, nullptr);
298 } 294 }
299 295
300 void V8Console::markTimelineCallback( 296 void V8Console::MarkTimeline(const v8::debug::ConsoleCallArguments& info) {
301 const v8::FunctionCallbackInfo<v8::Value>& info) {
302 ConsoleHelper(info, m_inspector) 297 ConsoleHelper(info, m_inspector)
303 .reportDeprecatedCall("V8Console#markTimelineDeprecated", 298 .reportDeprecatedCall("V8Console#markTimelineDeprecated",
304 "'console.markTimeline' is " 299 "'console.markTimeline' is "
305 "deprecated. Please use " 300 "deprecated. Please use "
306 "'console.timeStamp' instead."); 301 "'console.timeStamp' instead.");
307 timeStampCallback(info); 302 TimeStamp(info);
308 } 303 }
309 304
310 void V8Console::profileCallback( 305 void V8Console::Profile(const v8::debug::ConsoleCallArguments& info) {
311 const v8::FunctionCallbackInfo<v8::Value>& info) {
312 ConsoleHelper helper(info, m_inspector); 306 ConsoleHelper helper(info, m_inspector);
313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) 307 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
314 profilerAgent->consoleProfile(helper.firstArgToString(String16())); 308 profilerAgent->consoleProfile(helper.firstArgToString(String16()));
315 } 309 }
316 310
317 void V8Console::profileEndCallback( 311 void V8Console::ProfileEnd(const v8::debug::ConsoleCallArguments& info) {
318 const v8::FunctionCallbackInfo<v8::Value>& info) {
319 ConsoleHelper helper(info, m_inspector); 312 ConsoleHelper helper(info, m_inspector);
320 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent()) 313 if (V8ProfilerAgentImpl* profilerAgent = helper.profilerAgent())
321 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16())); 314 profilerAgent->consoleProfileEnd(helper.firstArgToString(String16()));
322 } 315 }
323 316
324 static void timeFunction(const v8::FunctionCallbackInfo<v8::Value>& info, 317 static void timeFunction(const v8::debug::ConsoleCallArguments& info,
325 bool timelinePrefix, V8InspectorImpl* inspector) { 318 bool timelinePrefix, V8InspectorImpl* inspector) {
326 ConsoleHelper helper(info, inspector); 319 ConsoleHelper helper(info, inspector);
327 String16 protocolTitle = helper.firstArgToString("default"); 320 String16 protocolTitle = helper.firstArgToString("default");
328 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 321 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
329 inspector->client()->consoleTime(toStringView(protocolTitle)); 322 inspector->client()->consoleTime(toStringView(protocolTitle));
330 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle); 323 helper.consoleMessageStorage()->time(helper.contextId(), protocolTitle);
331 } 324 }
332 325
333 static void timeEndFunction(const v8::FunctionCallbackInfo<v8::Value>& info, 326 static void timeEndFunction(const v8::debug::ConsoleCallArguments& info,
334 bool timelinePrefix, V8InspectorImpl* inspector) { 327 bool timelinePrefix, V8InspectorImpl* inspector) {
335 ConsoleHelper helper(info, inspector); 328 ConsoleHelper helper(info, inspector);
336 String16 protocolTitle = helper.firstArgToString("default"); 329 String16 protocolTitle = helper.firstArgToString("default");
337 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'"; 330 if (timelinePrefix) protocolTitle = "Timeline '" + protocolTitle + "'";
338 inspector->client()->consoleTimeEnd(toStringView(protocolTitle)); 331 inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
339 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(), 332 double elapsed = helper.consoleMessageStorage()->timeEnd(helper.contextId(),
340 protocolTitle); 333 protocolTitle);
341 String16 message = 334 String16 message =
342 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms"; 335 protocolTitle + ": " + String16::fromDouble(elapsed) + "ms";
343 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message); 336 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
344 } 337 }
345 338
346 void V8Console::timelineCallback( 339 void V8Console::Timeline(const v8::debug::ConsoleCallArguments& info) {
347 const v8::FunctionCallbackInfo<v8::Value>& info) {
348 ConsoleHelper(info, m_inspector) 340 ConsoleHelper(info, m_inspector)
349 .reportDeprecatedCall("V8Console#timeline", 341 .reportDeprecatedCall("V8Console#timeline",
350 "'console.timeline' is deprecated. Please use " 342 "'console.timeline' is deprecated. Please use "
351 "'console.time' instead."); 343 "'console.time' instead.");
352 timeFunction(info, true, m_inspector); 344 timeFunction(info, true, m_inspector);
353 } 345 }
354 346
355 void V8Console::timelineEndCallback( 347 void V8Console::TimelineEnd(const v8::debug::ConsoleCallArguments& info) {
356 const v8::FunctionCallbackInfo<v8::Value>& info) {
357 ConsoleHelper(info, m_inspector) 348 ConsoleHelper(info, m_inspector)
358 .reportDeprecatedCall("V8Console#timelineEnd", 349 .reportDeprecatedCall("V8Console#timelineEnd",
359 "'console.timelineEnd' is " 350 "'console.timelineEnd' is "
360 "deprecated. Please use " 351 "deprecated. Please use "
361 "'console.timeEnd' instead."); 352 "'console.timeEnd' instead.");
362 timeEndFunction(info, true, m_inspector); 353 timeEndFunction(info, true, m_inspector);
363 } 354 }
364 355
365 void V8Console::timeCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 356 void V8Console::Time(const v8::debug::ConsoleCallArguments& info) {
366 timeFunction(info, false, m_inspector); 357 timeFunction(info, false, m_inspector);
367 } 358 }
368 359
369 void V8Console::timeEndCallback( 360 void V8Console::TimeEnd(const v8::debug::ConsoleCallArguments& info) {
370 const v8::FunctionCallbackInfo<v8::Value>& info) {
371 timeEndFunction(info, false, m_inspector); 361 timeEndFunction(info, false, m_inspector);
372 } 362 }
373 363
374 void V8Console::timeStampCallback( 364 void V8Console::TimeStamp(const v8::debug::ConsoleCallArguments& info) {
375 const v8::FunctionCallbackInfo<v8::Value>& info) {
376 ConsoleHelper helper(info, m_inspector); 365 ConsoleHelper helper(info, m_inspector);
377 String16 title = helper.firstArgToString(String16()); 366 String16 title = helper.firstArgToString(String16());
378 m_inspector->client()->consoleTimeStamp(toStringView(title)); 367 m_inspector->client()->consoleTimeStamp(toStringView(title));
379 } 368 }
380 369
381 void V8Console::memoryGetterCallback( 370 void V8Console::memoryGetterCallback(
382 const v8::FunctionCallbackInfo<v8::Value>& info) { 371 const v8::FunctionCallbackInfo<v8::Value>& info) {
383 v8::Local<v8::Value> memoryValue; 372 v8::Local<v8::Value> memoryValue;
384 if (!m_inspector->client() 373 if (!m_inspector->client()
385 ->memoryInfo(info.GetIsolate(), 374 ->memoryInfo(info.GetIsolate(),
386 info.GetIsolate()->GetCurrentContext()) 375 info.GetIsolate()->GetCurrentContext())
387 .ToLocal(&memoryValue)) 376 .ToLocal(&memoryValue))
388 return; 377 return;
389 info.GetReturnValue().Set(memoryValue); 378 info.GetReturnValue().Set(memoryValue);
390 } 379 }
391 380
392 void V8Console::memorySetterCallback( 381 void V8Console::memorySetterCallback(
393 const v8::FunctionCallbackInfo<v8::Value>& info) { 382 const v8::FunctionCallbackInfo<v8::Value>& info) {
394 // We can't make the attribute readonly as it breaks existing code that relies 383 // We can't make the attribute readonly as it breaks existing code that relies
395 // on being able to assign to console.memory in strict mode. Instead, the 384 // on being able to assign to console.memory in strict mode. Instead, the
396 // setter just ignores the passed value. http://crbug.com/468611 385 // setter just ignores the passed value. http://crbug.com/468611
397 } 386 }
398 387
399 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 388 void V8Console::keysCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
400 v8::Isolate* isolate = info.GetIsolate(); 389 v8::Isolate* isolate = info.GetIsolate();
401 info.GetReturnValue().Set(v8::Array::New(isolate)); 390 info.GetReturnValue().Set(v8::Array::New(isolate));
402 391
403 ConsoleHelper helper(info, m_inspector); 392 v8::debug::ConsoleCallArguments args(info);
393 ConsoleHelper helper(args, m_inspector);
404 v8::Local<v8::Object> obj; 394 v8::Local<v8::Object> obj;
405 if (!helper.firstArgAsObject().ToLocal(&obj)) return; 395 if (!helper.firstArgAsObject().ToLocal(&obj)) return;
406 v8::Local<v8::Array> names; 396 v8::Local<v8::Array> names;
407 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names)) 397 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names))
408 return; 398 return;
409 info.GetReturnValue().Set(names); 399 info.GetReturnValue().Set(names);
410 } 400 }
411 401
412 void V8Console::valuesCallback( 402 void V8Console::valuesCallback(
413 const v8::FunctionCallbackInfo<v8::Value>& info) { 403 const v8::FunctionCallbackInfo<v8::Value>& info) {
414 v8::Isolate* isolate = info.GetIsolate(); 404 v8::Isolate* isolate = info.GetIsolate();
415 info.GetReturnValue().Set(v8::Array::New(isolate)); 405 info.GetReturnValue().Set(v8::Array::New(isolate));
416 406
417 ConsoleHelper helper(info, m_inspector); 407 v8::debug::ConsoleCallArguments args(info);
408 ConsoleHelper helper(args, m_inspector);
418 v8::Local<v8::Object> obj; 409 v8::Local<v8::Object> obj;
419 if (!helper.firstArgAsObject().ToLocal(&obj)) return; 410 if (!helper.firstArgAsObject().ToLocal(&obj)) return;
420 v8::Local<v8::Array> names; 411 v8::Local<v8::Array> names;
421 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 412 v8::Local<v8::Context> context = isolate->GetCurrentContext();
422 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return; 413 if (!obj->GetOwnPropertyNames(context).ToLocal(&names)) return;
423 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length()); 414 v8::Local<v8::Array> values = v8::Array::New(isolate, names->Length());
424 for (uint32_t i = 0; i < names->Length(); ++i) { 415 for (uint32_t i = 0; i < names->Length(); ++i) {
425 v8::Local<v8::Value> key; 416 v8::Local<v8::Value> key;
426 if (!names->Get(context, i).ToLocal(&key)) continue; 417 if (!names->Get(context, i).ToLocal(&key)) continue;
427 v8::Local<v8::Value> value; 418 v8::Local<v8::Value> value;
(...skipping 18 matching lines...) Expand all
446 if (enable) 437 if (enable)
447 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source, 438 debuggerAgent->setBreakpointAt(scriptId, lineNumber, columnNumber, source,
448 condition); 439 condition);
449 else 440 else
450 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber, 441 debuggerAgent->removeBreakpointAt(scriptId, lineNumber, columnNumber,
451 source); 442 source);
452 } 443 }
453 444
454 void V8Console::debugFunctionCallback( 445 void V8Console::debugFunctionCallback(
455 const v8::FunctionCallbackInfo<v8::Value>& info) { 446 const v8::FunctionCallbackInfo<v8::Value>& info) {
456 ConsoleHelper helper(info, m_inspector); 447 v8::debug::ConsoleCallArguments args(info);
448 ConsoleHelper helper(args, m_inspector);
457 v8::Local<v8::Function> function; 449 v8::Local<v8::Function> function;
458 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 450 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
459 setFunctionBreakpoint(helper, function, 451 setFunctionBreakpoint(helper, function,
460 V8DebuggerAgentImpl::DebugCommandBreakpointSource, 452 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
461 String16(), true); 453 String16(), true);
462 } 454 }
463 455
464 void V8Console::undebugFunctionCallback( 456 void V8Console::undebugFunctionCallback(
465 const v8::FunctionCallbackInfo<v8::Value>& info) { 457 const v8::FunctionCallbackInfo<v8::Value>& info) {
466 ConsoleHelper helper(info, m_inspector); 458 v8::debug::ConsoleCallArguments args(info);
459 ConsoleHelper helper(args, m_inspector);
467 v8::Local<v8::Function> function; 460 v8::Local<v8::Function> function;
468 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 461 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
469 setFunctionBreakpoint(helper, function, 462 setFunctionBreakpoint(helper, function,
470 V8DebuggerAgentImpl::DebugCommandBreakpointSource, 463 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
471 String16(), false); 464 String16(), false);
472 } 465 }
473 466
474 void V8Console::monitorFunctionCallback( 467 void V8Console::monitorFunctionCallback(
475 const v8::FunctionCallbackInfo<v8::Value>& info) { 468 const v8::FunctionCallbackInfo<v8::Value>& info) {
476 ConsoleHelper helper(info, m_inspector); 469 v8::debug::ConsoleCallArguments args(info);
470 ConsoleHelper helper(args, m_inspector);
477 v8::Local<v8::Function> function; 471 v8::Local<v8::Function> function;
478 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 472 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
479 v8::Local<v8::Value> name = function->GetName(); 473 v8::Local<v8::Value> name = function->GetName();
480 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) 474 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
481 name = function->GetInferredName(); 475 name = function->GetInferredName();
482 String16 functionName = toProtocolStringWithTypeCheck(name); 476 String16 functionName = toProtocolStringWithTypeCheck(name);
483 String16Builder builder; 477 String16Builder builder;
484 builder.append("console.log(\"function "); 478 builder.append("console.log(\"function ");
485 if (functionName.isEmpty()) 479 if (functionName.isEmpty())
486 builder.append("(anonymous function)"); 480 builder.append("(anonymous function)");
487 else 481 else
488 builder.append(functionName); 482 builder.append(functionName);
489 builder.append( 483 builder.append(
490 " called\" + (arguments.length > 0 ? \" with arguments: \" + " 484 " called\" + (arguments.length > 0 ? \" with arguments: \" + "
491 "Array.prototype.join.call(arguments, \", \") : \"\")) && false"); 485 "Array.prototype.join.call(arguments, \", \") : \"\")) && false");
492 setFunctionBreakpoint(helper, function, 486 setFunctionBreakpoint(helper, function,
493 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, 487 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
494 builder.toString(), true); 488 builder.toString(), true);
495 } 489 }
496 490
497 void V8Console::unmonitorFunctionCallback( 491 void V8Console::unmonitorFunctionCallback(
498 const v8::FunctionCallbackInfo<v8::Value>& info) { 492 const v8::FunctionCallbackInfo<v8::Value>& info) {
499 ConsoleHelper helper(info, m_inspector); 493 v8::debug::ConsoleCallArguments args(info);
494 ConsoleHelper helper(args, m_inspector);
500 v8::Local<v8::Function> function; 495 v8::Local<v8::Function> function;
501 if (!helper.firstArgAsFunction().ToLocal(&function)) return; 496 if (!helper.firstArgAsFunction().ToLocal(&function)) return;
502 setFunctionBreakpoint(helper, function, 497 setFunctionBreakpoint(helper, function,
503 V8DebuggerAgentImpl::MonitorCommandBreakpointSource, 498 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
504 String16(), false); 499 String16(), false);
505 } 500 }
506 501
507 void V8Console::lastEvaluationResultCallback( 502 void V8Console::lastEvaluationResultCallback(
508 const v8::FunctionCallbackInfo<v8::Value>& info) { 503 const v8::FunctionCallbackInfo<v8::Value>& info) {
509 ConsoleHelper helper(info, m_inspector); 504 v8::debug::ConsoleCallArguments args(info);
505 ConsoleHelper helper(args, m_inspector);
510 InjectedScript* injectedScript = helper.injectedScript(); 506 InjectedScript* injectedScript = helper.injectedScript();
511 if (!injectedScript) return; 507 if (!injectedScript) return;
512 info.GetReturnValue().Set(injectedScript->lastEvaluationResult()); 508 info.GetReturnValue().Set(injectedScript->lastEvaluationResult());
513 } 509 }
514 510
515 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info, 511 static void inspectImpl(const v8::FunctionCallbackInfo<v8::Value>& info,
516 bool copyToClipboard, V8InspectorImpl* inspector) { 512 bool copyToClipboard, V8InspectorImpl* inspector) {
517 if (info.Length() < 1) return; 513 if (info.Length() < 1) return;
518 if (!copyToClipboard) info.GetReturnValue().Set(info[0]); 514 if (!copyToClipboard) info.GetReturnValue().Set(info[0]);
519 515
520 ConsoleHelper helper(info, inspector); 516 v8::debug::ConsoleCallArguments args(info);
517 ConsoleHelper helper(args, inspector);
521 InjectedScript* injectedScript = helper.injectedScript(); 518 InjectedScript* injectedScript = helper.injectedScript();
522 if (!injectedScript) return; 519 if (!injectedScript) return;
523 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject; 520 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
524 protocol::Response response = 521 protocol::Response response =
525 injectedScript->wrapObject(info[0], "", false /** forceValueType */, 522 injectedScript->wrapObject(info[0], "", false /** forceValueType */,
526 false /** generatePreview */, &wrappedObject); 523 false /** generatePreview */, &wrappedObject);
527 if (!response.isSuccess()) return; 524 if (!response.isSuccess()) return;
528 525
529 std::unique_ptr<protocol::DictionaryValue> hints = 526 std::unique_ptr<protocol::DictionaryValue> hints =
530 protocol::DictionaryValue::create(); 527 protocol::DictionaryValue::create();
531 if (copyToClipboard) hints->setBoolean("copyToClipboard", true); 528 if (copyToClipboard) hints->setBoolean("copyToClipboard", true);
532 if (V8InspectorSessionImpl* session = helper.currentSession()) { 529 if (V8InspectorSessionImpl* session = helper.currentSession()) {
533 session->runtimeAgent()->inspect(std::move(wrappedObject), 530 session->runtimeAgent()->inspect(std::move(wrappedObject),
534 std::move(hints)); 531 std::move(hints));
535 } 532 }
536 } 533 }
537 534
538 void V8Console::inspectCallback( 535 void V8Console::inspectCallback(
539 const v8::FunctionCallbackInfo<v8::Value>& info) { 536 const v8::FunctionCallbackInfo<v8::Value>& info) {
540 inspectImpl(info, false, m_inspector); 537 inspectImpl(info, false, m_inspector);
541 } 538 }
542 539
543 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 540 void V8Console::copyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
544 inspectImpl(info, true, m_inspector); 541 inspectImpl(info, true, m_inspector);
545 } 542 }
546 543
547 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info, 544 void V8Console::inspectedObject(const v8::FunctionCallbackInfo<v8::Value>& info,
548 unsigned num) { 545 unsigned num) {
549 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize); 546 DCHECK(num < V8InspectorSessionImpl::kInspectedObjectBufferSize);
550 ConsoleHelper helper(info, m_inspector); 547 v8::debug::ConsoleCallArguments args(info);
548 ConsoleHelper helper(args, m_inspector);
551 if (V8InspectorSessionImpl* session = helper.currentSession()) { 549 if (V8InspectorSessionImpl* session = helper.currentSession()) {
552 V8InspectorSession::Inspectable* object = session->inspectedObject(num); 550 V8InspectorSession::Inspectable* object = session->inspectedObject(num);
553 v8::Isolate* isolate = info.GetIsolate(); 551 v8::Isolate* isolate = info.GetIsolate();
554 if (object) 552 if (object)
555 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext())); 553 info.GetReturnValue().Set(object->get(isolate->GetCurrentContext()));
556 else 554 else
557 info.GetReturnValue().Set(v8::Undefined(isolate)); 555 info.GetReturnValue().Set(v8::Undefined(isolate));
558 } 556 }
559 } 557 }
560 558
561 v8::Local<v8::Object> V8Console::createConsole(v8::Local<v8::Context> context) {
562 v8::Context::Scope contextScope(context);
563 v8::Isolate* isolate = context->GetIsolate();
564 v8::MicrotasksScope microtasksScope(isolate,
565 v8::MicrotasksScope::kDoNotRunMicrotasks);
566
567 v8::Local<v8::Object> console = v8::Object::New(isolate);
568 bool success =
569 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false);
570 DCHECK(success);
571 USE(success);
572
573 v8::Local<v8::External> data = v8::External::New(isolate, this);
574 createBoundFunctionProperty(context, console, data, "debug",
575 &V8Console::call<&V8Console::debugCallback>);
576 createBoundFunctionProperty(context, console, data, "error",
577 &V8Console::call<&V8Console::errorCallback>);
578 createBoundFunctionProperty(context, console, data, "info",
579 &V8Console::call<&V8Console::infoCallback>);
580 createBoundFunctionProperty(context, console, data, "log",
581 &V8Console::call<&V8Console::logCallback>);
582 createBoundFunctionProperty(context, console, data, "warn",
583 &V8Console::call<&V8Console::warnCallback>);
584 createBoundFunctionProperty(context, console, data, "dir",
585 &V8Console::call<&V8Console::dirCallback>);
586 createBoundFunctionProperty(context, console, data, "dirxml",
587 &V8Console::call<&V8Console::dirxmlCallback>);
588 createBoundFunctionProperty(context, console, data, "table",
589 &V8Console::call<&V8Console::tableCallback>);
590 createBoundFunctionProperty(context, console, data, "trace",
591 &V8Console::call<&V8Console::traceCallback>);
592 createBoundFunctionProperty(context, console, data, "group",
593 &V8Console::call<&V8Console::groupCallback>);
594 createBoundFunctionProperty(
595 context, console, data, "groupCollapsed",
596 &V8Console::call<&V8Console::groupCollapsedCallback>);
597 createBoundFunctionProperty(context, console, data, "groupEnd",
598 &V8Console::call<&V8Console::groupEndCallback>);
599 createBoundFunctionProperty(context, console, data, "clear",
600 &V8Console::call<&V8Console::clearCallback>);
601 createBoundFunctionProperty(context, console, data, "count",
602 &V8Console::call<&V8Console::countCallback>);
603 createBoundFunctionProperty(context, console, data, "assert",
604 &V8Console::call<&V8Console::assertCallback>);
605 createBoundFunctionProperty(
606 context, console, data, "markTimeline",
607 &V8Console::call<&V8Console::markTimelineCallback>);
608 createBoundFunctionProperty(context, console, data, "profile",
609 &V8Console::call<&V8Console::profileCallback>);
610 createBoundFunctionProperty(context, console, data, "profileEnd",
611 &V8Console::call<&V8Console::profileEndCallback>);
612 createBoundFunctionProperty(context, console, data, "timeline",
613 &V8Console::call<&V8Console::timelineCallback>);
614 createBoundFunctionProperty(
615 context, console, data, "timelineEnd",
616 &V8Console::call<&V8Console::timelineEndCallback>);
617 createBoundFunctionProperty(context, console, data, "time",
618 &V8Console::call<&V8Console::timeCallback>);
619 createBoundFunctionProperty(context, console, data, "timeEnd",
620 &V8Console::call<&V8Console::timeEndCallback>);
621 createBoundFunctionProperty(context, console, data, "timeStamp",
622 &V8Console::call<&V8Console::timeStampCallback>);
623 return console;
624 }
625
626 void V8Console::installMemoryGetter(v8::Local<v8::Context> context, 559 void V8Console::installMemoryGetter(v8::Local<v8::Context> context,
627 v8::Local<v8::Object> console) { 560 v8::Local<v8::Object> console) {
628 v8::Isolate* isolate = context->GetIsolate(); 561 v8::Isolate* isolate = context->GetIsolate();
629 v8::Local<v8::External> data = v8::External::New(isolate, this); 562 v8::Local<v8::External> data = v8::External::New(isolate, this);
630 console->SetAccessorProperty( 563 console->SetAccessorProperty(
631 toV8StringInternalized(isolate, "memory"), 564 toV8StringInternalized(isolate, "memory"),
632 v8::Function::New(context, 565 v8::Function::New(context,
633 &V8Console::call<&V8Console::memoryGetterCallback>, 566 &V8Console::call<&V8Console::memoryGetterCallback>,
634 data, 0, v8::ConstructorBehavior::kThrow) 567 data, 0, v8::ConstructorBehavior::kThrow)
635 .ToLocalChecked(), 568 .ToLocalChecked(),
(...skipping 11 matching lines...) Expand all
647 v8::MicrotasksScope::kDoNotRunMicrotasks); 580 v8::MicrotasksScope::kDoNotRunMicrotasks);
648 581
649 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); 582 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate);
650 bool success = 583 bool success =
651 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); 584 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false);
652 DCHECK(success); 585 DCHECK(success);
653 USE(success); 586 USE(success);
654 587
655 v8::Local<v8::External> data = v8::External::New(isolate, this); 588 v8::Local<v8::External> data = v8::External::New(isolate, this);
656 createBoundFunctionProperty(context, commandLineAPI, data, "dir", 589 createBoundFunctionProperty(context, commandLineAPI, data, "dir",
657 &V8Console::call<&V8Console::dirCallback>, 590 &V8Console::call<&V8Console::Dir>,
658 "function dir(value) { [Command Line API] }"); 591 "function dir(value) { [Command Line API] }");
659 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml", 592 createBoundFunctionProperty(context, commandLineAPI, data, "dirxml",
660 &V8Console::call<&V8Console::dirxmlCallback>, 593 &V8Console::call<&V8Console::DirXml>,
661 "function dirxml(value) { [Command Line API] }"); 594 "function dirxml(value) { [Command Line API] }");
662 createBoundFunctionProperty(context, commandLineAPI, data, "profile", 595 createBoundFunctionProperty(context, commandLineAPI, data, "profile",
663 &V8Console::call<&V8Console::profileCallback>, 596 &V8Console::call<&V8Console::Profile>,
664 "function profile(title) { [Command Line API] }"); 597 "function profile(title) { [Command Line API] }");
665 createBoundFunctionProperty( 598 createBoundFunctionProperty(
666 context, commandLineAPI, data, "profileEnd", 599 context, commandLineAPI, data, "profileEnd",
667 &V8Console::call<&V8Console::profileEndCallback>, 600 &V8Console::call<&V8Console::ProfileEnd>,
668 "function profileEnd(title) { [Command Line API] }"); 601 "function profileEnd(title) { [Command Line API] }");
669 createBoundFunctionProperty(context, commandLineAPI, data, "clear", 602 createBoundFunctionProperty(context, commandLineAPI, data, "clear",
670 &V8Console::call<&V8Console::clearCallback>, 603 &V8Console::call<&V8Console::Clear>,
671 "function clear() { [Command Line API] }"); 604 "function clear() { [Command Line API] }");
672 createBoundFunctionProperty( 605 createBoundFunctionProperty(
673 context, commandLineAPI, data, "table", 606 context, commandLineAPI, data, "table",
674 &V8Console::call<&V8Console::tableCallback>, 607 &V8Console::call<&V8Console::Table>,
675 "function table(data, [columns]) { [Command Line API] }"); 608 "function table(data, [columns]) { [Command Line API] }");
676 609
677 createBoundFunctionProperty(context, commandLineAPI, data, "keys", 610 createBoundFunctionProperty(context, commandLineAPI, data, "keys",
678 &V8Console::call<&V8Console::keysCallback>, 611 &V8Console::call<&V8Console::keysCallback>,
679 "function keys(object) { [Command Line API] }"); 612 "function keys(object) { [Command Line API] }");
680 createBoundFunctionProperty(context, commandLineAPI, data, "values", 613 createBoundFunctionProperty(context, commandLineAPI, data, "values",
681 &V8Console::call<&V8Console::valuesCallback>, 614 &V8Console::call<&V8Console::valuesCallback>,
682 "function values(object) { [Command Line API] }"); 615 "function values(object) { [Command Line API] }");
683 createBoundFunctionProperty( 616 createBoundFunctionProperty(
684 context, commandLineAPI, data, "debug", 617 context, commandLineAPI, data, "debug",
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 ->GetOwnPropertyDescriptor( 751 ->GetOwnPropertyDescriptor(
819 m_context, v8::Local<v8::String>::Cast(name)) 752 m_context, v8::Local<v8::String>::Cast(name))
820 .ToLocal(&descriptor); 753 .ToLocal(&descriptor);
821 DCHECK(success); 754 DCHECK(success);
822 USE(success); 755 USE(success);
823 } 756 }
824 } 757 }
825 } 758 }
826 759
827 } // namespace v8_inspector 760 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-console.h ('k') | src/inspector/v8-inspector-impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698