Commit a2c7947c authored by caseq's avatar caseq Committed by Commit bot

DevTools coverage: get script/stylesheet size directly, do not request content

This utilizes length of scripts and stylesheets recently exposed in the protocolto avoid requesting content in CoverageModel.

Review-Url: https://codereview.chromium.org/2735133004
Cr-Commit-Position: refs/heads/master@{#455761}
parent 3c1769f9
......@@ -592,7 +592,7 @@ InspectorTest.createScriptMock = function(url, startLine, startColumn, isContent
var endLine = startLine + lineCount - 1;
var endColumn = lineCount === 1 ? startColumn + source.length : source.length - source.computeLineEndings()[lineCount - 2];
var hasSourceURL = !!source.match(/\/\/#\ssourceURL=\s*(\S*?)\s*$/m) || !!source.match(/\/\/@\ssourceURL=\s*(\S*?)\s*$/m);
var script = new SDK.Script(debuggerModel, scriptId, url, startLine, startColumn, endLine, endColumn, 0, "", isContentScript, false, undefined, hasSourceURL);
var script = new SDK.Script(debuggerModel, scriptId, url, startLine, startColumn, endLine, endColumn, 0, "", isContentScript, false, undefined, hasSourceURL, source.length);
script.requestContent = function()
{
var trimmedSource = SDK.Script._trimSourceURLComment(source);
......
......@@ -7,9 +7,9 @@ Coverage.RangeUseCount;
/** @typedef {{
* contentProvider: !Common.ContentProvider,
* size: (number|undefined),
* unusedSize: (number|undefined),
* usedSize: (number|undefined),
* size: number,
* unusedSize: number,
* usedSize: number,
* type: !Coverage.CoverageType,
* lineOffset: number,
* columnOffset: number,
......@@ -99,10 +99,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
/**
* @param {!SDK.DebuggerModel} debuggerModel
* @param {!Array<!Protocol.Profiler.ScriptCoverage>} scriptsCoverage
* @return {!Promise<!Array<!Coverage.CoverageInfo>>}
* @return {!Array<!Coverage.CoverageInfo>}
*/
static async _processJSCoverage(debuggerModel, scriptsCoverage) {
var promises = [];
static _processJSCoverage(debuggerModel, scriptsCoverage) {
var result = [];
for (var entry of scriptsCoverage) {
var script = debuggerModel.scriptForId(entry.scriptId);
if (!script)
......@@ -112,10 +112,10 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
for (var range of func.ranges)
ranges.push({startOffset: range.startOffset, endOffset: range.endOffset, count: range.count});
}
promises.push(
Coverage.CoverageModel._coverageInfoForText(script, script.lineOffset, script.columnOffset, ranges));
result.push(Coverage.CoverageModel._buildCoverageInfo(
script, script.contentLength, script.lineOffset, script.columnOffset, ranges));
}
return Promise.all(promises);
return result;
}
/**
......@@ -133,9 +133,9 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
/**
* @param {!SDK.CSSModel} cssModel
* @param {!Array<!Protocol.CSS.RuleUsage>} ruleUsageList
* @return {!Promise<!Array<!Coverage.CoverageInfo>>}
* @return {!Array<!Coverage.CoverageInfo>}
*/
static async _processCSSCoverage(cssModel, ruleUsageList) {
static _processCSSCoverage(cssModel, ruleUsageList) {
/** @type {!Map<?SDK.CSSStyleSheetHeader, !Array<!Coverage.RangeUseCount>>} */
var rulesByStyleSheet = new Map();
for (var rule of ruleUsageList) {
......@@ -147,20 +147,22 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
}
ranges.push({startOffset: rule.startOffset, endOffset: rule.endOffset, count: Number(rule.used)});
}
return Promise.all(Array.from(
return Array.from(
rulesByStyleSheet.entries(),
entry =>
Coverage.CoverageModel._coverageInfoForText(entry[0], entry[0].startLine, entry[0].startColumn, entry[1])));
entry => Coverage.CoverageModel._buildCoverageInfo(
entry[0], entry[0].contentLength, entry[0].startLine, entry[0].startColumn, entry[1]));
}
/**
* @param {!Common.ContentProvider} contentProvider
* @param {number} contentLength
* @param {number} startLine
* @param {number} startColumn
* @param {!Array<!Coverage.RangeUseCount>} ranges
* @return {!Promise<?Coverage.CoverageInfo>}
* @return {!Coverage.CoverageInfo}
*/
static async _coverageInfoForText(contentProvider, startLine, startColumn, ranges) {
static _buildCoverageInfo(contentProvider, contentLength, startLine, startColumn, ranges) {
/** @type Coverage.CoverageType */
var coverageType;
var url = contentProvider.contentURL();
if (contentProvider.contentType().isScript())
......@@ -197,16 +199,11 @@ Coverage.CoverageModel = class extends SDK.SDKModel {
unusedSize += entry.ownSize;
}
// FIXME: get rid of this when we get the size upfront.
var content = await contentProvider.requestContent();
if (typeof content !== 'string')
return null;
var coverageInfo = {
contentProvider: contentProvider,
ranges: ranges,
type: coverageType,
size: content.length,
size: contentLength,
usedSize: usedSize,
unusedSize: unusedSize,
lineOffset: startLine,
......
......@@ -22,6 +22,7 @@ SDK.CSSStyleSheetHeader = class {
this.isInline = payload.isInline;
this.startLine = payload.startLine;
this.startColumn = payload.startColumn;
this.contentLength = payload.length;
if (payload.ownerNode)
this.ownerNode = new SDK.DeferredDOMNode(cssModel.target(), payload.ownerNode);
this.setSourceMapURL(payload.sourceMapURL);
......
......@@ -458,25 +458,15 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
* @param {string} hash
* @param {*|undefined} executionContextAuxData
* @param {boolean} isLiveEdit
* @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL
* @param {boolean=} hasSyntaxError
* @param {string|undefined} sourceMapURL
* @param {boolean} hasSourceURL
* @param {boolean} hasSyntaxError
* @param {number} length
* @return {!SDK.Script}
*/
_parsedScriptSource(
scriptId,
sourceURL,
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
isLiveEdit,
sourceMapURL,
hasSourceURL,
hasSyntaxError) {
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, isLiveEdit, sourceMapURL, hasSourceURL, hasSyntaxError, length) {
var isContentScript = false;
if (executionContextAuxData && ('isDefault' in executionContextAuxData))
isContentScript = !executionContextAuxData['isDefault'];
......@@ -491,7 +481,7 @@ SDK.DebuggerModel = class extends SDK.SDKModel {
}
var script = new SDK.Script(
this, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId,
this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, hasSourceURL);
this._internString(hash), isContentScript, isLiveEdit, sourceMapURL, hasSourceURL, length);
this._registerScript(script);
if (!hasSyntaxError)
this.dispatchEventToListeners(SDK.DebuggerModel.Events.ParsedScriptSource, script);
......@@ -933,23 +923,15 @@ SDK.DebuggerDispatcher = class {
* @param {boolean=} isLiveEdit
* @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL
* @param {boolean=} isModule
* @param {number=} length
*/
scriptParsed(
scriptId,
sourceURL,
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
isLiveEdit,
sourceMapURL,
hasSourceURL) {
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, isLiveEdit, sourceMapURL, hasSourceURL, isModule, length) {
this._debuggerModel._parsedScriptSource(
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, !!isLiveEdit, sourceMapURL, hasSourceURL, false);
executionContextAuxData, !!isLiveEdit, sourceMapURL, !!hasSourceURL, false, length || 0);
}
/**
......@@ -965,22 +947,15 @@ SDK.DebuggerDispatcher = class {
* @param {*=} executionContextAuxData
* @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL
* @param {boolean=} isModule
* @param {number=} length
*/
scriptFailedToParse(
scriptId,
sourceURL,
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
executionContextAuxData,
sourceMapURL,
hasSourceURL) {
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, sourceMapURL, hasSourceURL, isModule, length) {
this._debuggerModel._parsedScriptSource(
scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
executionContextAuxData, false, sourceMapURL, hasSourceURL, true);
executionContextAuxData, false, sourceMapURL, !!hasSourceURL, true, length || 0);
}
/**
......
......@@ -40,23 +40,13 @@ SDK.Script = class {
* @param {string} hash
* @param {boolean} isContentScript
* @param {boolean} isLiveEdit
* @param {string=} sourceMapURL
* @param {boolean=} hasSourceURL
* @param {string|undefined} sourceMapURL
* @param {boolean} hasSourceURL
* @param {number} length
*/
constructor(
debuggerModel,
scriptId,
sourceURL,
startLine,
startColumn,
endLine,
endColumn,
executionContextId,
hash,
isContentScript,
isLiveEdit,
sourceMapURL,
hasSourceURL) {
debuggerModel, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash,
isContentScript, isLiveEdit, sourceMapURL, hasSourceURL, length) {
this.debuggerModel = debuggerModel;
this.scriptId = scriptId;
this.sourceURL = sourceURL;
......@@ -71,6 +61,7 @@ SDK.Script = class {
this._isLiveEdit = isLiveEdit;
this.sourceMapURL = sourceMapURL;
this.hasSourceURL = hasSourceURL;
this.contentLength = length;
this._originalContentProvider = null;
this._originalSource = null;
}
......
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