Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js b/third_party/WebKit/Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js |
| index fa951dc6c85b4eee15efd7646ca313cf9a31f2d3..499776329353d935dc27dedb081660dd435b58ac 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/bindings/DebuggerWorkspaceBinding.js |
| @@ -5,26 +5,33 @@ |
| * @unrestricted |
| * @implements {SDK.SDKModelObserver<!SDK.DebuggerModel>} |
| */ |
| -Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| +Bindings.DebuggerWorkspaceBinding = class { |
| /** |
| * @param {!SDK.TargetManager} targetManager |
| * @param {!Workspace.Workspace} workspace |
| */ |
| constructor(targetManager, workspace) { |
| - super(); |
| this._workspace = workspace; |
| + /** @type {!Array<!Bindings.DebuggerSourceMapping>} */ |
| + this._sourceMappings = []; |
| + |
| /** @type {!Map.<!SDK.DebuggerModel, !Bindings.DebuggerWorkspaceBinding.ModelData>} */ |
| this._debuggerModelToData = new Map(); |
| targetManager.addModelListener( |
| SDK.DebuggerModel, SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, this); |
| targetManager.addModelListener( |
| SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this); |
| - workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRemoved, this._onUISourceCodeRemoved, this); |
| - workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved, this._projectRemoved, this); |
| targetManager.observeModels(SDK.DebuggerModel, this); |
| } |
| + /** |
| + * @param {!Bindings.DebuggerSourceMapping} sourceMapping |
| + */ |
| + addSourceMapping(sourceMapping) { |
| + this._sourceMappings.push(sourceMapping); |
| + } |
| + |
| /** |
| * @override |
| * @param {!SDK.DebuggerModel} debuggerModel |
| @@ -43,64 +50,6 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| this._debuggerModelToData.remove(debuggerModel); |
| } |
| - /** |
| - * @param {!Common.Event} event |
| - */ |
| - _onUISourceCodeRemoved(event) { |
| - var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| - this._uiSourceCodeRemoved(uiSourceCode); |
| - } |
| - |
| - /** |
| - * @param {!Common.Event} event |
| - */ |
| - _projectRemoved(event) { |
| - var project = /** @type {!Workspace.Project} */ (event.data); |
| - var uiSourceCodes = project.uiSourceCodes(); |
| - for (var uiSourceCode of uiSourceCodes) |
| - this._uiSourceCodeRemoved(uiSourceCode); |
| - } |
| - |
| - /** |
| - * @param {!SDK.Script} script |
| - * @param {!Bindings.DebuggerSourceMapping} sourceMapping |
| - */ |
| - pushSourceMapping(script, sourceMapping) { |
| - var info = this._ensureInfoForScript(script); |
| - info._pushSourceMapping(sourceMapping); |
| - } |
| - |
| - /** |
| - * @param {!SDK.Script} script |
| - * @return {!Bindings.DebuggerSourceMapping} |
| - */ |
| - popSourceMapping(script) { |
| - var info = this._infoForScript(script); |
| - console.assert(info); |
| - return info._popSourceMapping(); |
| - } |
| - |
| - /** |
| - * @param {!SDK.DebuggerModel} debuggerModel |
| - * @param {!Workspace.UISourceCode} uiSourceCode |
| - * @param {?Bindings.DebuggerSourceMapping} sourceMapping |
| - */ |
| - setSourceMapping(debuggerModel, uiSourceCode, sourceMapping) { |
| - if (uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol] === sourceMapping) |
| - return; |
| - |
| - if (sourceMapping) |
| - uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol] = sourceMapping; |
| - else |
| - delete uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol]; |
| - |
| - this.dispatchEventToListeners(Bindings.DebuggerWorkspaceBinding.Events.SourceMappingChanged, { |
| - uiSourceCode: uiSourceCode, |
| - debuggerModel: debuggerModel, |
| - isIdentity: sourceMapping ? sourceMapping.isIdentity() : false |
| - }); |
| - } |
| - |
| /** |
| * @param {!SDK.Script} script |
| */ |
| @@ -117,8 +66,9 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| * @return {!Bindings.DebuggerWorkspaceBinding.Location} |
| */ |
| createLiveLocation(rawLocation, updateDelegate, locationPool) { |
| - var info = this._infoForScript(rawLocation.script()); |
| - console.assert(info); |
| + var script = /** @type {!SDK.Script} */ (rawLocation.script()); |
| + console.assert(script); |
| + var info = this._ensureInfoForScript(script); |
| var location = |
| new Bindings.DebuggerWorkspaceBinding.Location(info._script, rawLocation, this, updateDelegate, locationPool); |
| info._addLocation(location); |
| @@ -161,9 +111,14 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| * @return {!Workspace.UILocation} |
| */ |
| rawLocationToUILocation(rawLocation) { |
| - var info = this._infoForScript(rawLocation.script()); |
| - console.assert(info); |
| - return info._rawLocationToUILocation(rawLocation); |
| + for (var i = 0; i < this._sourceMappings.length; ++i) { |
| + var uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLocation); |
| + if (uiLocation) |
| + return uiLocation; |
| + } |
| + var modelData = this._debuggerModelToData.get(rawLocation.debuggerModel); |
| + console.assert(modelData); |
|
dgozman
2017/06/08 19:12:00
Remove assert.
lushnikov
2017/06/08 21:14:34
Done.
|
| + return modelData._rawLocationToUILocation(rawLocation); |
| } |
| /** |
| @@ -185,8 +140,18 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| * @return {?SDK.DebuggerModel.Location} |
| */ |
| uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| - var sourceMapping = uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol]; |
| - return sourceMapping && sourceMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + for (var i = 0; i < this._sourceMappings.length; ++i) { |
| + var rawLocation = this._sourceMappings[i].uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + if (rawLocation) |
| + return rawLocation; |
| + } |
| + |
| + for (var modelData of this._debuggerModelToData.values()) { |
| + var rawLocation = modelData._uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + if (rawLocation) |
| + return rawLocation; |
| + } |
| + return null; |
| } |
| /** |
| @@ -201,23 +166,6 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| return uiLocation; |
| } |
| - /** |
| - * @param {!Workspace.UISourceCode} uiSourceCode |
| - * @param {number} lineNumber |
| - * @return {boolean} |
| - */ |
| - uiLineHasMapping(uiSourceCode, lineNumber) { |
| - var sourceMapping = uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol]; |
| - return sourceMapping ? sourceMapping.uiLineHasMapping(uiSourceCode, lineNumber) : true; |
| - } |
| - |
| - /** |
| - * @param {!Workspace.UISourceCode} uiSourceCode |
| - */ |
| - _uiSourceCodeRemoved(uiSourceCode) { |
| - delete uiSourceCode[Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol]; |
| - } |
| - |
| /** |
| * @param {!Workspace.UISourceCode} uiSourceCode |
| * @param {!SDK.DebuggerModel} debuggerModel |
| @@ -317,7 +265,6 @@ Bindings.DebuggerWorkspaceBinding = class extends Common.Object { |
| }; |
| Bindings.DebuggerWorkspaceBinding._scriptInfoSymbol = Symbol('scriptDataMap'); |
| -Bindings.DebuggerWorkspaceBinding._sourceMappingSymbol = Symbol('sourceMapping'); |
| /** |
| * @unrestricted |
| @@ -350,6 +297,34 @@ Bindings.DebuggerWorkspaceBinding.ModelData = class { |
| ]; |
| } |
| + /** |
| + * @param {!SDK.DebuggerModel.Location} rawLocation |
| + * @return {!Workspace.UILocation} |
| + */ |
| + _rawLocationToUILocation(rawLocation) { |
| + var uiLocation = null; |
| + uiLocation = uiLocation || this._compilerMapping.rawLocationToUILocation(rawLocation); |
| + uiLocation = uiLocation || this._resourceMapping.rawLocationToUILocation(rawLocation); |
| + uiLocation = uiLocation || this._defaultMapping.rawLocationToUILocation(rawLocation); |
| + // DefaultMapping ensures uiLocation for every rawLocation. |
| + console.assert(uiLocation); |
| + return /** @type {!Workspace.UILocation} */ (uiLocation); |
| + } |
| + |
| + /** |
| + * @param {!Workspace.UISourceCode} uiSourceCode |
| + * @param {number} lineNumber |
| + * @param {number} columnNumber |
| + * @return {?SDK.DebuggerModel.Location} |
| + */ |
| + _uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| + var rawLocation = null; |
| + rawLocation = rawLocation || this._compilerMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + rawLocation = rawLocation || this._resourceMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + rawLocation = rawLocation || this._defaultMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); |
| + return rawLocation; |
| + } |
| + |
| /** |
| * @param {!SDK.DebuggerPausedDetails} debuggerPausedDetails |
| * @return {boolean} |
| @@ -384,12 +359,6 @@ Bindings.DebuggerWorkspaceBinding.ModelData = class { |
| } |
| }; |
| -/** @enum {symbol} */ |
| -Bindings.DebuggerWorkspaceBinding.Events = { |
| - SourceMappingChanged: Symbol('SourceMappingChanged'), |
| -}; |
| - |
| - |
| /** |
| * @unrestricted |
| */ |
| @@ -402,31 +371,6 @@ Bindings.DebuggerWorkspaceBinding.ScriptInfo = class { |
| // We create a lot of these, do not add arrays/collections/expensive data structures. |
| } |
| - /** |
| - * @param {!Bindings.DebuggerSourceMapping} sourceMapping |
| - */ |
| - _pushSourceMapping(sourceMapping) { |
| - if (this._sourceMapping) { |
| - if (!this._backupMappings) { |
| - /** @type {!Array.<!Bindings.DebuggerSourceMapping>} */ |
| - this._backupMappings = []; |
| - } |
| - this._backupMappings.push(this._sourceMapping); |
| - } |
| - this._sourceMapping = sourceMapping; |
| - this._updateLocations(); |
| - } |
| - |
| - /** |
| - * @return {!Bindings.DebuggerSourceMapping} |
| - */ |
| - _popSourceMapping() { |
| - var sourceMapping = this._sourceMapping; |
| - this._sourceMapping = this._backupMappings ? this._backupMappings.pop() : undefined; |
| - this._updateLocations(); |
| - return sourceMapping; |
| - } |
| - |
| /** |
| * @param {!Bindings.LiveLocation} location |
| */ |
| @@ -454,20 +398,6 @@ Bindings.DebuggerWorkspaceBinding.ScriptInfo = class { |
| for (var location of this._locations) |
| location.update(); |
| } |
| - |
| - /** |
| - * @param {!SDK.DebuggerModel.Location} rawLocation |
| - * @return {!Workspace.UILocation} |
| - */ |
| - _rawLocationToUILocation(rawLocation) { |
| - var uiLocation = this._sourceMapping ? this._sourceMapping.rawLocationToUILocation(rawLocation) : null; |
| - if (!uiLocation && this._backupMappings) { |
| - for (var i = this._backupMappings.length - 1; !uiLocation && i >= 0; --i) |
| - uiLocation = this._backupMappings[i].rawLocationToUILocation(rawLocation); |
| - } |
| - console.assert(uiLocation, 'Script raw location cannot be mapped to any UI location.'); |
| - return /** @type {!Workspace.UILocation} */ (uiLocation); |
| - } |
| }; |
| /** |
| @@ -599,18 +529,6 @@ Bindings.DebuggerSourceMapping.prototype = { |
| * @return {?SDK.DebuggerModel.Location} |
| */ |
| uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {}, |
| - |
| - /** |
| - * @return {boolean} |
| - */ |
| - isIdentity() {}, |
| - |
| - /** |
| - * @param {!Workspace.UISourceCode} uiSourceCode |
| - * @param {number} lineNumber |
| - * @return {boolean} |
| - */ |
| - uiLineHasMapping(uiSourceCode, lineNumber) {} |
| }; |
| /** |