Skip to content

Commit

Permalink
[DevTools] Per debugger model state storage in BlackboxManager
Browse files Browse the repository at this point in the history
BUG=583193
[email protected]

Review URL: https://codereview.chromium.org/1734853003

Cr-Commit-Position: refs/heads/master@{#377701}
  • Loading branch information
alexkozy authored and Commit bot committed Feb 25, 2016
1 parent abd1fba commit 1e5a8f6
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions front_end/bindings/BlackboxManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ WebInspector.BlackboxManager = function(debuggerWorkspaceBinding, networkMapping
WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this._patternChanged.bind(this));
WebInspector.moduleSetting("skipContentScripts").addChangeListener(this._patternChanged.bind(this));

/** @type {!Map<string, !Array<!DebuggerAgent.ScriptPosition>>} */
this._scriptIdToPositions = new Map();
/** @type {!Map<!WebInspector.DebuggerModel, !Map<string, !Array<!DebuggerAgent.ScriptPosition>>>} */
this._debuggerModelData = new Map();
/** @type {!Map<string, boolean>} */
this._isBlackboxedURLCache = new Map();
}
Expand Down Expand Up @@ -48,9 +48,9 @@ WebInspector.BlackboxManager.prototype = {
*/
isBlackboxedRawLocation: function(location)
{
if (!this._scriptIdToPositions.has(location.scriptId))
var positions = this._scriptPositions(location.script());
if (!positions)
return this._isBlackboxedScript(location.script());
var positions = this._scriptIdToPositions.get(location.scriptId);
var index = positions.lowerBound(location, comparator);
return !!(index % 2);

Expand Down Expand Up @@ -108,13 +108,13 @@ WebInspector.BlackboxManager.prototype = {
{
if (!sourceMap)
return Promise.resolve();
if (!this._scriptIdToPositions.has(script.scriptId))
var previousScriptState = this._scriptPositions(script);
if (!previousScriptState)
return Promise.resolve();

var mappings = sourceMap.mappings().slice();
mappings.sort(mappingComparator);

var previousScriptState = this._scriptIdToPositions.get(script.scriptId);
if (!mappings.length) {
if (previousScriptState.length > 0)
return this._setScriptState(script, []).then(this._sourceMapLoadedForTest);
Expand Down Expand Up @@ -246,9 +246,13 @@ WebInspector.BlackboxManager.prototype = {
// This method is sniffed in tests.
},

_globalObjectCleared: function()
/**
* @param {!WebInspector.Event} event
*/
_globalObjectCleared: function(event)
{
this._scriptIdToPositions.clear();
var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target);
this._debuggerModelData.delete(debuggerModel);
this._isBlackboxedURLCache.clear();
},

Expand Down Expand Up @@ -280,16 +284,39 @@ WebInspector.BlackboxManager.prototype = {
return this.isBlackboxedURL(script.sourceURL, script.isContentScript());
},

/**
* @param {!WebInspector.Script} script
* @return {?Array<!DebuggerAgent.ScriptPosition>}
*/
_scriptPositions: function(script)
{
if (this._debuggerModelData.has(script.debuggerModel))
return this._debuggerModelData.get(script.debuggerModel).get(script.scriptId) || null;
return null;
},

/**
* @param {!WebInspector.Script} script
* @param {!Array<!DebuggerAgent.ScriptPosition>} positions
*/
_setScriptPositions: function(script, positions)
{
var debuggerModel = script.debuggerModel;
if (!this._debuggerModelData.has(debuggerModel))
this._debuggerModelData.set(debuggerModel, new Map());
this._debuggerModelData.get(debuggerModel).set(script.scriptId, positions);
},

/**
* @param {!WebInspector.Script} script
* @param {!Array<!DebuggerAgent.ScriptPosition>} positions
* @return {!Promise<undefined>}
*/
_setScriptState: function(script, positions)
{
if (this._scriptIdToPositions.has(script.scriptId)) {
var previousScriptState = this._scriptPositions(script);
if (previousScriptState) {
var hasChanged = false;
var previousScriptState = this._scriptIdToPositions.get(script.scriptId);
hasChanged = previousScriptState.length !== positions.length;
for (var i = 0; !hasChanged && i < positions.length; ++i)
hasChanged = positions[i].line !== previousScriptState[i].line || positions[i].column !== previousScriptState[i].column;
Expand All @@ -309,13 +336,15 @@ WebInspector.BlackboxManager.prototype = {
function updateState(success)
{
if (success) {
this._scriptIdToPositions.set(script.scriptId, positions);
this._setScriptPositions(script, positions);
this._debuggerWorkspaceBinding.updateLocations(script);
var isBlackboxed = positions.length !== 0;
if (!isBlackboxed && script.sourceMapURL)
this._debuggerWorkspaceBinding.maybeLoadSourceMap(script);
} else if (!this._scriptIdToPositions.has(script.scriptId)) {
this._scriptIdToPositions.set(script.scriptId, []);
} else {
var hasPositions = !!this._scriptPositions(script);
if (!hasPositions)
this._setScriptPositions(script, []);
}
}
},
Expand Down

0 comments on commit 1e5a8f6

Please sign in to comment.