Commit 897ee2fb authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[DevTools] Better locations for snippets

- highlight errors in snippet source;
- fix location of Syntax Errors in console messge;
- fix location of Snippet result in console message

BUG=479712
R=lushnikov@chromium.org

Review-Url: https://codereview.chromium.org/2173233002
Cr-Commit-Position: refs/heads/master@{#407706}
parent 5f911460
...@@ -368,6 +368,14 @@ InspectorTest.waitUntilMessageReceived = function(callback) ...@@ -368,6 +368,14 @@ InspectorTest.waitUntilMessageReceived = function(callback)
InspectorTest.addSniffer(InspectorTest.consoleModel, "addMessage", callback, false); InspectorTest.addSniffer(InspectorTest.consoleModel, "addMessage", callback, false);
} }
InspectorTest.waitUntilMessageReceivedPromise = function()
{
var callback;
var promise = new Promise((fullfill) => callback = fullfill);
InspectorTest.waitUntilMessageReceived(callback);
return promise;
}
InspectorTest.waitUntilNthMessageReceived = function(count, callback) InspectorTest.waitUntilNthMessageReceived = function(count, callback)
{ {
function override() function override()
...@@ -380,6 +388,14 @@ InspectorTest.waitUntilNthMessageReceived = function(count, callback) ...@@ -380,6 +388,14 @@ InspectorTest.waitUntilNthMessageReceived = function(count, callback)
InspectorTest.addSniffer(InspectorTest.consoleModel, "addMessage", override, false); InspectorTest.addSniffer(InspectorTest.consoleModel, "addMessage", override, false);
} }
InspectorTest.waitUntilNthMessageReceivedPromise = function(count)
{
var callback;
var promise = new Promise((fullfill) => callback = fullfill);
InspectorTest.waitUntilNthMessageReceived(count, callback);
return promise;
}
InspectorTest.changeExecutionContext = function(namePrefix) InspectorTest.changeExecutionContext = function(namePrefix)
{ {
var selector = WebInspector.ConsoleView.instance()._executionContextModel._selectElement; var selector = WebInspector.ConsoleView.instance()._executionContextModel._selectElement;
......
CONSOLE MESSAGE: line 1: 239
CONSOLE ERROR: line 2: 42
Test that link to snippet works.
Running: testConsoleLogAndReturnMessageLocation
name1:1 239
name1:1 42
Running: testSnippetSyntaxError
Line Message was added: name2 Error 'Uncaught SyntaxError: Unexpected token }':1:1
name2:2 Uncaught SyntaxError: Unexpected token }
Running: testConsoleErrorHighlight
Line Message was added: name3 Error '42':1:10
name3:2 42(anonymous function) @ name3:2
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/sources-test.js"></script>
<script src="../../http/tests/inspector/console-test.js"></script>
<script>
function test()
{
InspectorTest.addSniffer(WebInspector.UISourceCode.prototype, "addLineMessage", dumpLineMessage, true);
InspectorTest.runTestSuite([
function testConsoleLogAndReturnMessageLocation(next)
{
InspectorTest.waitUntilNthMessageReceivedPromise(2)
.then(() => InspectorTest.dumpConsoleMessages())
.then(() => WebInspector.ConsoleView.clearConsole())
.then(() => next());
createSnippetPromise("console.log(239);42")
.then(uiSourceCode => selectSourceCode(uiSourceCode))
.then(uiSourceCode => renameSourceCodePromise("name1", uiSourceCode))
.then(() => runSelectedSnippet());
},
function testSnippetSyntaxError(next)
{
InspectorTest.waitUntilNthMessageReceivedPromise(1)
.then(() => InspectorTest.dumpConsoleMessages())
.then(() => WebInspector.ConsoleView.clearConsole())
.then(() => next());
createSnippetPromise("\n }")
.then(uiSourceCode => selectSourceCode(uiSourceCode))
.then(uiSourceCode => renameSourceCodePromise("name2", uiSourceCode))
.then(() => runSelectedSnippet());
},
function testConsoleErrorHighlight(next)
{
InspectorTest.waitUntilNthMessageReceivedPromise(1)
.then(() => InspectorTest.dumpConsoleMessages())
.then(() => WebInspector.ConsoleView.clearConsole())
.then(() => next());
createSnippetPromise("\n console.error(42);")
.then(uiSourceCode => selectSourceCode(uiSourceCode))
.then(uiSourceCode => renameSourceCodePromise("name3", uiSourceCode))
.then(() => runSelectedSnippet());
}
]);
function createSnippetPromise(content)
{
var callback;
var promise = new Promise(fullfill => callback = fullfill);
WebInspector.scriptSnippetModel._project.createFile("", null, content, callback);
return promise;
}
function renameSourceCodePromise(newName, uiSourceCode)
{
var callback;
var promise = new Promise(fullfill => callback = fullfill);
uiSourceCode.rename(newName, () => callback(uiSourceCode));
return promise;
}
function selectSourceCode(uiSourceCode)
{
WebInspector.SourcesPanel.instance()._sourceSelected({ data: { uiSourceCode: uiSourceCode }});
return uiSourceCode;
}
function dumpLineMessage(level, text, lineNumber, columnNumber)
{
InspectorTest.addResult(`Line Message was added: ${this.url()} ${level} '${text}':${lineNumber}:${columnNumber}`);
}
function runSelectedSnippet()
{
WebInspector.SourcesPanel.instance()._runSnippet();
}
}
</script>
</head>
<body onload="runTest()">
<p>Test that link to snippet works.</p>
</body>
</html>
...@@ -67,7 +67,7 @@ WebInspector.PresentationConsoleMessageHelper.prototype = { ...@@ -67,7 +67,7 @@ WebInspector.PresentationConsoleMessageHelper.prototype = {
*/ */
_consoleMessageAdded: function(message) _consoleMessageAdded: function(message)
{ {
if (!message.url || !message.isErrorOrWarning()) if (!message.isErrorOrWarning())
return; return;
var rawLocation = this._rawLocation(message); var rawLocation = this._rawLocation(message);
...@@ -86,14 +86,14 @@ WebInspector.PresentationConsoleMessageHelper.prototype = { ...@@ -86,14 +86,14 @@ WebInspector.PresentationConsoleMessageHelper.prototype = {
var debuggerModel = WebInspector.DebuggerModel.fromTarget(message.target()); var debuggerModel = WebInspector.DebuggerModel.fromTarget(message.target());
if (!debuggerModel) if (!debuggerModel)
return null; return null;
if (message.scriptId)
return debuggerModel.createRawLocationByScriptId(message.scriptId, message.line, message.column);
var callFrame = message.stackTrace && message.stackTrace.callFrames ? message.stackTrace.callFrames[0] : null; var callFrame = message.stackTrace && message.stackTrace.callFrames ? message.stackTrace.callFrames[0] : null;
var lineNumber = callFrame ? callFrame.lineNumber : message.line;
var columnNumber = callFrame ? callFrame.columnNumber : message.column;
if (callFrame) if (callFrame)
columnNumber = callFrame.columnNumber; return debuggerModel.createRawLocationByScriptId(callFrame.scriptId, callFrame.lineNumber, callFrame.columnNumber);
if (message.scriptId) if (message.url)
return debuggerModel.createRawLocationByScriptId(message.scriptId, lineNumber, columnNumber); return debuggerModel.createRawLocationByURL(message.url, message.line, message.column);
return debuggerModel.createRawLocationByURL(message.url || "", lineNumber, columnNumber); return null;
}, },
/** /**
......
...@@ -225,9 +225,17 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -225,9 +225,17 @@ WebInspector.ScriptSnippetModel.prototype = {
var mapping = this._mappingForTarget.get(target); var mapping = this._mappingForTarget.get(target);
mapping._setEvaluationIndex(evaluationIndex, uiSourceCode); mapping._setEvaluationIndex(evaluationIndex, uiSourceCode);
var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode); var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode);
var expression = uiSourceCode.workingCopy(); uiSourceCode.requestContent().then(compileSnippet.bind(this));
WebInspector.console.show();
runtimeModel.compileScript(expression, "", true, executionContext.id, compileCallback.bind(this)); /**
* @this {WebInspector.ScriptSnippetModel}
*/
function compileSnippet()
{
var expression = uiSourceCode.workingCopy();
WebInspector.console.show();
runtimeModel.compileScript(expression, "", true, executionContext.id, compileCallback.bind(this));
}
/** /**
* @param {!RuntimeAgent.ScriptId=} scriptId * @param {!RuntimeAgent.ScriptId=} scriptId
...@@ -240,12 +248,12 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -240,12 +248,12 @@ WebInspector.ScriptSnippetModel.prototype = {
if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex) if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex)
return; return;
mapping._addScript(executionContext.debuggerModel.scriptForId(scriptId || exceptionDetails.scriptId), uiSourceCode);
if (!scriptId) { if (!scriptId) {
this._printRunOrCompileScriptResultFailure(target, exceptionDetails, evaluationUrl); this._printRunOrCompileScriptResultFailure(target, exceptionDetails, evaluationUrl);
return; return;
} }
mapping._addScript(executionContext.debuggerModel.scriptForId(scriptId), uiSourceCode);
var breakpointLocations = this._removeBreakpoints(uiSourceCode); var breakpointLocations = this._removeBreakpoints(uiSourceCode);
this._restoreBreakpoints(uiSourceCode, breakpointLocations); this._restoreBreakpoints(uiSourceCode, breakpointLocations);
...@@ -272,7 +280,7 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -272,7 +280,7 @@ WebInspector.ScriptSnippetModel.prototype = {
function runCallback(target, result, exceptionDetails) function runCallback(target, result, exceptionDetails)
{ {
if (!exceptionDetails) if (!exceptionDetails)
this._printRunScriptResult(target, result, sourceURL); this._printRunScriptResult(target, result, scriptId, sourceURL);
else else
this._printRunOrCompileScriptResultFailure(target, exceptionDetails, sourceURL); this._printRunOrCompileScriptResultFailure(target, exceptionDetails, sourceURL);
} }
...@@ -281,9 +289,10 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -281,9 +289,10 @@ WebInspector.ScriptSnippetModel.prototype = {
/** /**
* @param {!WebInspector.Target} target * @param {!WebInspector.Target} target
* @param {?RuntimeAgent.RemoteObject} result * @param {?RuntimeAgent.RemoteObject} result
* @param {!RuntimeAgent.ScriptId} scriptId
* @param {?string=} sourceURL * @param {?string=} sourceURL
*/ */
_printRunScriptResult: function(target, result, sourceURL) _printRunScriptResult: function(target, result, scriptId, sourceURL)
{ {
var consoleMessage = new WebInspector.ConsoleMessage( var consoleMessage = new WebInspector.ConsoleMessage(
target, target,
...@@ -296,7 +305,10 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -296,7 +305,10 @@ WebInspector.ScriptSnippetModel.prototype = {
undefined, undefined,
undefined, undefined,
[result], [result],
undefined); undefined,
undefined,
undefined,
scriptId);
target.consoleModel.addMessage(consoleMessage); target.consoleModel.addMessage(consoleMessage);
}, },
...@@ -318,7 +330,10 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -318,7 +330,10 @@ WebInspector.ScriptSnippetModel.prototype = {
exceptionDetails.columnNumber, exceptionDetails.columnNumber,
undefined, undefined,
undefined, undefined,
exceptionDetails.stackTrace); exceptionDetails.stackTrace,
undefined,
undefined,
exceptionDetails.stackTrace ? undefined : exceptionDetails.scriptId);
target.consoleModel.addMessage(consoleMessage); target.consoleModel.addMessage(consoleMessage);
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment