Commit 3e1e90de authored by allada's avatar allada Committed by Commit bot

[Devtools] Add stacktrace to protocol for scriptParsed event

Stacktrace data is now passed when scriptParsed event is triggered.

R=kozyatinskiy@chromium.org,dgozman
BUG=chromium:646849

Review-Url: https://codereview.chromium.org/2755863002
Cr-Commit-Position: refs/heads/master@{#43879}
parent 82b5c8c9
...@@ -713,7 +713,8 @@ ...@@ -713,7 +713,8 @@
{ "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." }, { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." },
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true }, { "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true },
{ "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true }, { "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true },
{ "name": "length", "type": "integer", "optional": true, "description": "This script length.", "experimental": true } { "name": "length", "type": "integer", "optional": true, "description": "This script length.", "experimental": true },
{ "name": "stackTrace", "$ref": "Runtime.StackTrace", "optional": true, "description": "JavaScript top stack frame of where the script parsed event was triggered if available.", "experimental": true }
], ],
"description": "Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger." "description": "Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger."
}, },
...@@ -732,7 +733,8 @@ ...@@ -732,7 +733,8 @@
{ "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." }, { "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." },
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true }, { "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true },
{ "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true }, { "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true },
{ "name": "length", "type": "integer", "optional": true, "description": "This script length.", "experimental": true } { "name": "length", "type": "integer", "optional": true, "description": "This script length.", "experimental": true },
{ "name": "stackTrace", "$ref": "Runtime.StackTrace", "optional": true, "description": "JavaScript top stack frame of where the script parsed event was triggered if available.", "experimental": true }
], ],
"description": "Fired when virtual machine fails to parse the script." "description": "Fired when virtual machine fails to parse the script."
}, },
......
...@@ -1135,20 +1135,25 @@ void V8DebuggerAgentImpl::didParseSource( ...@@ -1135,20 +1135,25 @@ void V8DebuggerAgentImpl::didParseSource(
const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr; const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr; const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
const bool* isModuleParam = isModule ? &isModule : nullptr; const bool* isModuleParam = isModule ? &isModule : nullptr;
if (success) std::unique_ptr<V8StackTraceImpl> stack =
V8StackTraceImpl::capture(m_inspector->debugger(), contextGroupId, 1);
std::unique_ptr<protocol::Runtime::StackTrace> stackTrace =
stack && !stack->isEmpty() ? stack->buildInspectorObjectImpl() : nullptr;
if (success) {
m_frontend.scriptParsed( m_frontend.scriptParsed(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(), contextId, scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(), std::move(executionContextAuxDataParam), scriptRef->hash(), std::move(executionContextAuxDataParam),
isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam, isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam,
isModuleParam, scriptRef->source().length()); isModuleParam, scriptRef->source().length(), std::move(stackTrace));
else } else {
m_frontend.scriptFailedToParse( m_frontend.scriptFailedToParse(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(), scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(), contextId, scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(), std::move(executionContextAuxDataParam), scriptRef->hash(), std::move(executionContextAuxDataParam),
std::move(sourceMapURLParam), hasSourceURLParam, isModuleParam, std::move(sourceMapURLParam), hasSourceURLParam, isModuleParam,
scriptRef->source().length()); scriptRef->source().length(), std::move(stackTrace));
}
if (scriptURL.isEmpty() || !success) return; if (scriptURL.isEmpty() || !success) return;
......
...@@ -65,29 +65,9 @@ function requestSourceAndDump(scriptParsedMessage, scriptParsed) { ...@@ -65,29 +65,9 @@ function requestSourceAndDump(scriptParsedMessage, scriptParsed) {
} }
function dumpScriptParsed(scriptParsedMessage, sourceMessage, scriptParsed) { function dumpScriptParsed(scriptParsedMessage, sourceMessage, scriptParsed) {
var params = scriptParsedMessage.params;
var re = /[A-Z0-9]{40,40}/;
if (!params.hash || !matchExact(re, params.hash))
params.hash = "Invalid hash: " + params.hash;
else
params.hash = "<hash>";
if (params.executionContextId <= 0)
params.executionContextId = "Invalid executionContextId: " + params.executionContextId;
else
params.executionContextId = "<executionContextId>";
if (params.scriptId * 1 <= 0)
params.scriptId = "Invalid scriptId: " + params.scriptId;
else
params.scriptId = "<scriptId>";
var sourceResult = sourceMessage.result; var sourceResult = sourceMessage.result;
sourceResult.scriptSource = sourceResult.scriptSource.replace(/\n/g, "<nl>"); sourceResult.scriptSource = sourceResult.scriptSource.replace(/\n/g, "<nl>");
InspectorTest.log(scriptParsed ? "scriptParsed" : "scriptFailedToParse"); InspectorTest.log(scriptParsed ? "scriptParsed" : "scriptFailedToParse");
InspectorTest.logObject(sourceResult); InspectorTest.logObject(sourceResult);
InspectorTest.logObject(params); InspectorTest.logMessage(scriptParsedMessage.params);
}
function matchExact(re, str) {
var match = str.match(re);
return match !== null && str === match[0];
} }
Checks that inspector reports script compiled in Runtime.evaluate,Runtime.callFunctionOn and Runtime.compileScript Checks that inspector reports script compiled in Runtime.evaluate, Runtime.callFunctionOn and Runtime.compileScript
Runtime.evaluate with valid expression Runtime.evaluate with valid expression
{ {
method : Debugger.scriptParsed method : Debugger.scriptParsed
...@@ -111,3 +111,156 @@ Runtime.compileScript with syntax error ...@@ -111,3 +111,156 @@ Runtime.compileScript with syntax error
} }
} }
Runtime.compileScript persistScript: false (should be no script events) Runtime.compileScript persistScript: false (should be no script events)
Runtime.evaluate compiled script with stack trace
{
method : Debugger.scriptParsed
params : {
endColumn : 8
endLine : 0
executionContextId : <executionContextId>
hasSourceURL : false
hash : A2185340E4E4F1BA4CB5762843D429DC872EBA18
isLiveEdit : false
isModule : false
length : 8
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url :
}
}
{
method : Debugger.scriptParsed
params : {
endColumn : 39
endLine : 4
executionContextId : <executionContextId>
hasSourceURL : true
hash : 6AF4ED72C355E471C4E94D74464A25541932A242
isLiveEdit : false
isModule : false
length : 86
scriptId : <scriptId>
sourceMapURL :
stackTrace : {
callFrames : [
[0] : {
columnNumber : 2
functionName : fooTop
lineNumber : 10
scriptId : <scriptId>
url : top-frame.js
}
]
}
startColumn : 0
startLine : 0
url : second-frame.js
}
}
{
method : Debugger.scriptParsed
params : {
endColumn : 4
endLine : 0
executionContextId : <executionContextId>
hasSourceURL : false
hash : 9D04F733E4E4F1BA4CB5762843D429DC872EBA18
isLiveEdit : false
isModule : false
length : 4
scriptId : <scriptId>
sourceMapURL :
stackTrace : {
callFrames : [
[0] : {
columnNumber : 6
functionName : foo
lineNumber : 2
scriptId : <scriptId>
url : second-frame.js
}
]
}
startColumn : 0
startLine : 0
url :
}
}
Runtime.evaluate compile script error with stack trace
{
method : Debugger.scriptParsed
params : {
endColumn : 12
endLine : 0
executionContextId : <executionContextId>
hasSourceURL : false
hash : A218534034AA14704CB5762843D429DC872EBA18
isLiveEdit : false
isModule : false
length : 12
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url :
}
}
{
method : Debugger.scriptParsed
params : {
endColumn : 48
endLine : 4
executionContextId : <executionContextId>
hasSourceURL : true
hash : 5FD5C8C38F2D44588A4078148B0BC5635152B0C0
isLiveEdit : false
isModule : false
length : 98
scriptId : <scriptId>
sourceMapURL :
stackTrace : {
callFrames : [
[0] : {
columnNumber : 2
functionName : fooTopFail
lineNumber : 20
scriptId : <scriptId>
url : top-frame-fail.js
}
]
}
startColumn : 0
startLine : 0
url : second-frame-fail.js
}
}
{
method : Debugger.scriptFailedToParse
params : {
endColumn : 3
endLine : 0
executionContextId : <executionContextId>
hasSourceURL : false
hash : 9D04F7336C348CA34CB5762843D429DC872EBA18
isModule : false
length : 3
scriptId : <scriptId>
sourceMapURL :
stackTrace : {
callFrames : [
[0] : {
columnNumber : 6
functionName : fooFail
lineNumber : 2
scriptId : <scriptId>
url : second-frame-fail.js
}
]
}
startColumn : 0
startLine : 0
url :
}
}
...@@ -2,9 +2,29 @@ ...@@ -2,9 +2,29 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
InspectorTest.log("Checks that inspector reports script compiled in Runtime.evaluate," + InspectorTest.log("Checks that inspector reports script compiled in Runtime.evaluate, " +
"Runtime.callFunctionOn and Runtime.compileScript"); "Runtime.callFunctionOn and Runtime.compileScript");
InspectorTest.addScript(`
function fooTop() {
eval(\`
function foo() {
eval("({})")
}
foo() //# sourceURL=second-frame.js\`);
}
//# sourceURL=top-frame.js`, 8, 26);
InspectorTest.addScript(`
function fooTopFail() {
eval(\`
function fooFail() {
eval("({}")
}
fooFail() //# sourceURL=second-frame-fail.js\`);
}
//# sourceURL=top-frame-fail.js`, 18, 26);
Promise.prototype.thenLog = function log(message) { Promise.prototype.thenLog = function log(message) {
return this.then(() => InspectorTest.log(message)); return this.then(() => InspectorTest.log(message));
} }
...@@ -46,4 +66,14 @@ Protocol.Debugger.enable() ...@@ -46,4 +66,14 @@ Protocol.Debugger.enable()
.then(() => Protocol.Runtime.compileScript({ expression: "}", .then(() => Protocol.Runtime.compileScript({ expression: "}",
sourceURL: "compile-script-syntax-error.js", persistScript: false })) sourceURL: "compile-script-syntax-error.js", persistScript: false }))
.thenLog('Runtime.evaluate compiled script with stack trace')
.then(() => Protocol.Runtime.evaluate({
expression: "fooTop()"}))
.then(msg => objectId = msg.result.result.objectId)
.thenLog('Runtime.evaluate compile script error with stack trace')
.then(() => Protocol.Runtime.evaluate({
expression: "fooTopFail()"}))
.then(msg => objectId = msg.result.result.objectId)
.then(InspectorTest.completeTest); .then(InspectorTest.completeTest);
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