Skip to content

Commit

Permalink
[DevTools] Report console API calls through Runtime.
Browse files Browse the repository at this point in the history
Follow the scheme of Runtime.exceptionThrown, but also send a copy of the message (with a string representation of the first argument) via Console.messageAdded. This makes the change backwards-compatible.

BUG=613882

Review-Url: https://codereview.chromium.org/2139543002
Cr-Commit-Position: refs/heads/master@{#405679}
  • Loading branch information
dgozman authored and Commit bot committed Jul 15, 2016
1 parent d3fea98 commit 7043980
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
14 changes: 13 additions & 1 deletion front_end/console/ConsoleViewMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ WebInspector.ConsoleViewMessage.prototype = {
if (consoleMessage.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI) {
switch (consoleMessage.type) {
case WebInspector.ConsoleMessage.MessageType.Trace:
this._messageElement = this._format(consoleMessage.parameters || ["console.trace()"]);
this._messageElement = this._format(consoleMessage.parameters || ["console.trace"]);
break;
case WebInspector.ConsoleMessage.MessageType.Clear:
this._messageElement = createTextNode(WebInspector.UIString("Console was cleared"));
Expand Down Expand Up @@ -1114,6 +1114,18 @@ WebInspector.ConsoleViewMessage.prototype = {
case WebInspector.ConsoleMessage.MessageType.Log:
typeString = "Log";
break;
case WebInspector.ConsoleMessage.MessageType.Debug:
typeString = "Debug";
break;
case WebInspector.ConsoleMessage.MessageType.Info:
typeString = "Info";
break;
case WebInspector.ConsoleMessage.MessageType.Error:
typeString = "Error";
break;
case WebInspector.ConsoleMessage.MessageType.Warning:
typeString = "Warning";
break;
case WebInspector.ConsoleMessage.MessageType.Dir:
typeString = "Dir";
break;
Expand Down
6 changes: 6 additions & 0 deletions front_end/sdk/ConsoleModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ WebInspector.ConsoleMessage.MessageSource = {
*/
WebInspector.ConsoleMessage.MessageType = {
Log: "log",
Debug: "debug",
Info: "info",
Error: "error",
Warning: "warning",
Dir: "dir",
DirXML: "dirxml",
Table: "table",
Expand Down Expand Up @@ -534,6 +538,8 @@ WebInspector.ConsoleDispatcher.prototype = {
*/
messageAdded: function(payload)
{
if (payload.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI)
return;
var consoleMessage = new WebInspector.ConsoleMessage(
this._console.target(),
payload.source,
Expand Down
43 changes: 43 additions & 0 deletions front_end/sdk/RuntimeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,49 @@ WebInspector.RuntimeDispatcher.prototype = {
this._runtimeModel.target().consoleModel.addMessage(consoleMessage);
},

/**
* @override
* @param {string} type
* @param {!Array.<!RuntimeAgent.RemoteObject>} args
* @param {number} executionContextId
* @param {number} timestamp
* @param {!RuntimeAgent.StackTrace=} stackTrace
*/
consoleAPICalled: function(type, args, executionContextId, timestamp, stackTrace)
{
var level = WebInspector.ConsoleMessage.MessageLevel.Log;
if (type === WebInspector.ConsoleMessage.MessageType.Debug)
level = WebInspector.ConsoleMessage.MessageLevel.Debug;
if (type === WebInspector.ConsoleMessage.MessageType.Error || type === WebInspector.ConsoleMessage.MessageType.Assert)
level = WebInspector.ConsoleMessage.MessageLevel.Error;
if (type === WebInspector.ConsoleMessage.MessageType.Warning)
level = WebInspector.ConsoleMessage.MessageLevel.Warning;
if (type === WebInspector.ConsoleMessage.MessageType.Info)
level = WebInspector.ConsoleMessage.MessageLevel.Info;
var message = "";
if (args.length && typeof args[0].value === "string")
message = args[0].value;
else if (args.length && args[0].description)
message = args[0].description;
var callFrame = stackTrace && stackTrace.callFrames.length ? stackTrace.callFrames[0] : null;
var consoleMessage = new WebInspector.ConsoleMessage(
this._runtimeModel.target(),
WebInspector.ConsoleMessage.MessageSource.ConsoleAPI,
level,
/** @type {string} */ (message),
type,
callFrame ? callFrame.url : undefined,
callFrame ? callFrame.lineNumber + 1 : undefined,
callFrame ? callFrame.columnNumber + 1 : undefined,
undefined,
args,
stackTrace,
timestamp,
executionContextId,
undefined);
this._runtimeModel.target().consoleModel.addMessage(consoleMessage);
},

/**
* @override
* @param {!RuntimeAgent.RemoteObject} payload
Expand Down

0 comments on commit 7043980

Please sign in to comment.