Changeset 115064 in webkit
- Timestamp:
- Apr 24, 2012 8:46:35 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r115062 r115064 1 2012-04-24 Pavel Feldman <pfeldman@chromium.org> 2 3 Web Inspector: encapsulate live location into the Script. 4 https://bugs.webkit.org/show_bug.cgi?id=84722 5 6 Reviewed by Yury Semikhatsky. 7 8 * http/tests/inspector/debugger-test.js: 9 (initialize_DebuggerTest): 10 * inspector/debugger/linkifier.html: 11 1 12 2012-04-24 Mikhail Naganov <mnaganov@chromium.org> 2 13 -
trunk/LayoutTests/http/tests/inspector/debugger-test.js
r115032 r115064 106 106 for (var i = 0; i < callFrames.length; i++) { 107 107 var frame = callFrames[i]; 108 var script = WebInspector.debuggerModel.scriptFor SourceID(frame.location.scriptId);108 var script = WebInspector.debuggerModel.scriptForId(frame.location.scriptId); 109 109 var url; 110 110 var lineNumber; -
trunk/LayoutTests/inspector/debugger/linkifier.html
r110434 r115064 11 11 var linkifier; 12 12 var link; 13 var script; 13 14 14 15 function waitForScripts() … … 20 21 return; 21 22 22 varscript = event.data;23 script = event.data; 23 24 if (script.sourceURL === WebInspector.inspectedPageURL) { 24 25 continued = true; … … 68 69 function liveLocationsCount() 69 70 { 70 var locations = WebInspector.debuggerPresentationModel._scriptMapping._liveLocationsForScriptId; 71 var count = 0; 72 for (id in locations) 73 count += locations[id].length; 74 return count; 71 return script._locations.length; 75 72 } 76 73 } -
trunk/Source/WebCore/ChangeLog
r115063 r115064 1 2012-04-24 Pavel Feldman <pfeldman@chromium.org> 2 3 Web Inspector: encapsulate live location into the Script. 4 https://bugs.webkit.org/show_bug.cgi?id=84722 5 6 Reviewed by Yury Semikhatsky. 7 8 Live location is just a location on the script. The way it is implemented today involves too many indirections. 9 10 * inspector/front-end/CompilerScriptMapping.js: 11 * inspector/front-end/DebuggerModel.js: 12 (WebInspector.DebuggerModel.prototype.setBreakpointByScriptLocation): 13 (WebInspector.DebuggerModel.prototype.scriptForId): 14 * inspector/front-end/DebuggerPresentationModel.js: 15 (WebInspector.DebuggerPresentationModel.prototype.createLiveLocation): 16 (WebInspector.DebuggerPresentationModel.prototype._addConsoleMessageToScript): 17 (WebInspector.DebuggerPresentationModel.prototype._debuggerPaused): 18 (WebInspector.DebuggerPresentationModel.prototype.set selectedCallFrame): 19 (WebInspector.PresentationCallFrame.prototype.uiLocation): 20 (WebInspector.DebuggerPresentationModel.CallFramePlacard): 21 (WebInspector.DebuggerPresentationModel.Linkifier.prototype.linkifyRawLocation): 22 * inspector/front-end/RawSourceCode.js: 23 * inspector/front-end/ResourceScriptMapping.js: 24 (WebInspector.ResourceScriptMapping.prototype.addScript): 25 (WebInspector.ResourceScriptMapping.prototype._uiSourceCodeChanged): 26 (WebInspector.ResourceScriptMapping.prototype._bindScriptToRawSourceCode): 27 * inspector/front-end/Script.js: 28 (WebInspector.Script): 29 (WebInspector.Script.prototype.isInlineScript): 30 (WebInspector.Script.prototype.setSourceMapping): 31 (WebInspector.Script.prototype.createLocation): 32 (WebInspector.Script.Location): 33 (WebInspector.Script.Location.prototype.dispose): 34 (WebInspector.Script.Location.prototype._update): 35 * inspector/front-end/ScriptMapping.js: 36 (WebInspector.UILocation): 37 (WebInspector.SourceMapping): 38 (WebInspector.SourceMapping.prototype.rawLocationToUILocation): 39 (WebInspector.SourceMapping.prototype.uiLocationToRawLocation): 40 (WebInspector.MainScriptMapping): 41 (WebInspector.MainScriptMapping.prototype.addScript): 42 (WebInspector.MainScriptMapping.prototype.reset): 43 * inspector/front-end/SnippetsModel.js: 44 (WebInspector.SnippetsScriptMapping.prototype._createUISourceCodeForScript): 45 1 46 2012-04-24 Yury Semikhatsky <yurys@chromium.org> 2 47 -
trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js
r114892 r115064 101 101 this._sourceMapForScriptId[script.scriptId] = sourceMap; 102 102 var uiSourceCodes = this._uiSourceCodesForSourceMap(sourceMap); 103 var data = { scriptId: script.scriptId, uiSourceCodes: uiSourceCodes }; 104 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data); 103 script.setSourceMapping(this); 105 104 return; 106 105 } … … 130 129 var data = { removedItems: [], addedItems: uiSourceCodeList }; 131 130 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data); 132 data = { scriptId: script.scriptId, uiSourceCodes: uiSourceCodeList }; 133 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data); 131 script.setSourceMapping(this); 134 132 }, 135 133 -
trunk/Source/WebCore/inspector/front-end/DebuggerModel.js
r115032 r115064 140 140 setBreakpointByScriptLocation: function(location, condition, callback) 141 141 { 142 var script = this.scriptFor SourceID(location.scriptId);142 var script = this.scriptForId(location.scriptId); 143 143 if (script.sourceURL) 144 144 this.setBreakpoint(script.sourceURL, location.lineNumber, location.columnNumber, condition, callback); … … 239 239 * @return {WebInspector.Script} 240 240 */ 241 scriptFor SourceID: function(scriptId)241 scriptForId: function(scriptId) 242 242 { 243 243 return this._scripts[scriptId] || null; -
trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js
r115032 r115064 116 116 /** 117 117 * @param {DebuggerAgent.Location} rawLocation 118 * @param {function(WebInspector.UILocation) } updateDelegate119 * @return {WebInspector. LiveLocation}118 * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate 119 * @return {WebInspector.Script.Location} 120 120 */ 121 121 createLiveLocation: function(rawLocation, updateDelegate) 122 122 { 123 return this._scriptMapping.createLiveLocation(rawLocation, updateDelegate); 123 var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId); 124 return script.createLocation(rawLocation, updateDelegate); 124 125 }, 125 126 … … 192 193 { 193 194 var rawLocation = this.uiLocationToRawLocation(uiSourceCode, 0, 0); 194 var script = WebInspector.debuggerModel.scriptFor SourceID(rawLocation.scriptId);195 var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId); 195 196 196 197 /** … … 253 254 } 254 255 var liveLocation = this.createLiveLocation(rawLocation, updateLocation.bind(this)); 255 liveLocation.init();256 256 this._consoleMessageLiveLocations.push(liveLocation); 257 257 }, … … 324 324 for (var i = 0; i < callFrames.length; ++i) { 325 325 var callFrame = callFrames[i]; 326 if (WebInspector.debuggerModel.scriptFor SourceID(callFrame.location.scriptId))326 if (WebInspector.debuggerModel.scriptForId(callFrame.location.scriptId)) 327 327 this._presentationCallFrames.push(new WebInspector.PresentationCallFrame(callFrame, i, this)); 328 328 } … … 357 357 } 358 358 this._executionLineLiveLocation = this.createLiveLocation(callFrame._callFrame.location, updateExecutionLine.bind(this)); 359 this._executionLineLiveLocation.init();360 359 }, 361 360 … … 554 553 { 555 554 callback(uiLocation); 556 liveLocation.dispose(); 557 } 558 var liveLocation = this._model.createLiveLocation(this._callFrame.location, locationUpdated.bind(this)); 559 liveLocation.init(); 555 return true; 556 } 557 this._model.createLiveLocation(this._callFrame.location, locationUpdated.bind(this)); 560 558 } 561 559 } … … 571 569 WebInspector.Placard.call(this, callFrame._callFrame.functionName || WebInspector.UIString("(anonymous function)"), ""); 572 570 this._liveLocation = model.createLiveLocation(callFrame._callFrame.location, this._update.bind(this)); 573 this._liveLocation.init();574 571 } 575 572 … … 746 743 linkifyRawLocation: function(rawLocation, classes) 747 744 { 748 if (!WebInspector.debuggerModel.scriptFor SourceID(rawLocation.scriptId))745 if (!WebInspector.debuggerModel.scriptForId(rawLocation.scriptId)) 749 746 return null; 750 747 var anchor = WebInspector.linkifyURLAsNode("", "", classes, false); 751 748 var liveLocation = this._model.createLiveLocation(rawLocation, this._updateAnchor.bind(this, anchor)); 752 liveLocation.init();753 749 this._liveLocations.push(liveLocation); 754 750 return anchor; -
trunk/Source/WebCore/inspector/front-end/RawSourceCode.js
r114892 r115064 240 240 /** 241 241 * @interface 242 * @extends {WebInspector.SourceMapping} 242 243 */ 243 244 WebInspector.RawSourceCode.SourceMapping = function() … … 246 247 247 248 WebInspector.RawSourceCode.SourceMapping.prototype = { 248 /**249 * @param {DebuggerAgent.Location} rawLocation250 * @return {WebInspector.UILocation}251 */252 rawLocationToUILocation: function(rawLocation) { },253 254 /**255 * @param {WebInspector.UISourceCode} uiSourceCode256 * @param {number} lineNumber257 * @param {number} columnNumber258 * @return {DebuggerAgent.Location}259 */260 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) { },261 262 249 /** 263 250 * @return {WebInspector.UISourceCode} … … 354 341 } 355 342 } 356 357 /**358 * @constructor359 * @param {WebInspector.UISourceCode} uiSourceCode360 * @param {number} lineNumber361 * @param {number} columnNumber362 */363 WebInspector.UILocation = function(uiSourceCode, lineNumber, columnNumber)364 {365 this.uiSourceCode = uiSourceCode;366 this.lineNumber = lineNumber;367 this.columnNumber = columnNumber;368 } -
trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js
r114135 r115064 118 118 this._rawSourceCodes.push(rawSourceCode); 119 119 this._bindScriptToRawSourceCode(script, rawSourceCode); 120 121 120 if (isInlineScript) 122 121 this._rawSourceCodeForDocumentURL[script.sourceURL] = rawSourceCode; … … 150 149 151 150 var scriptIds = []; 152 for (var i = 0; i < rawSourceCode._scripts.length; ++i) 151 for (var i = 0; i < rawSourceCode._scripts.length; ++i) { 153 152 scriptIds.push(rawSourceCode._scripts[i].scriptId); 153 rawSourceCode._scripts[i].setSourceMapping(this); 154 } 154 155 var removedItems = removedItem ? [removedItem] : []; 155 156 var addedItems = addedItem ? [addedItem] : []; 156 157 157 if (removedItem) {158 for (var i = 0; i < scriptIds.length; ++i) {159 var data = { scriptId: scriptIds[i], uiSourceCodes: [removedItem] };160 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptUnbound, data);161 }162 }163 164 158 var data = { removedItems: removedItems, addedItems: addedItems }; 165 159 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data); 166 167 if (addedItem) {168 for (var i = 0; i < scriptIds.length; ++i) {169 data = { scriptId: scriptIds[i], uiSourceCodes: [addedItem] };170 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);171 }172 }173 160 }, 174 161 … … 181 168 this._rawSourceCodeForScriptId[script.scriptId] = rawSourceCode; 182 169 this._rawSourceCodeForURL[script.sourceURL] = rawSourceCode; 170 script.setSourceMapping(this); 183 171 }, 184 172 -
trunk/Source/WebCore/inspector/front-end/Script.js
r113707 r115064 45 45 this.isContentScript = isContentScript; 46 46 this.sourceMapURL = sourceMapURL; 47 this._locations = []; 47 48 } 48 49 … … 138 139 { 139 140 return !!this.sourceURL && this.lineOffset !== 0 && this.columnOffset !== 0; 141 }, 142 143 144 /** 145 * @param {WebInspector.SourceMapping} sourceMapping 146 */ 147 setSourceMapping: function(sourceMapping) 148 { 149 this._sourceMapping = sourceMapping; 150 for (var i = 0; i < this._locations.length; ++i) 151 this._locations[i]._update(); 152 }, 153 154 /** 155 * @param {DebuggerAgent.Location} rawLocation 156 * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate 157 * @return {WebInspector.Script.Location} 158 */ 159 createLocation: function(rawLocation, updateDelegate) 160 { 161 var location = new WebInspector.Script.Location(this, rawLocation, updateDelegate); 162 this._locations.push(location); 163 location._update(); 164 return location; 140 165 } 141 166 } 167 168 /** 169 * @constructor 170 * @param {WebInspector.Script} script 171 * @param {DebuggerAgent.Location} rawLocation 172 * @param {function(WebInspector.UILocation):(boolean|undefined)} updateDelegate 173 */ 174 WebInspector.Script.Location = function(script, rawLocation, updateDelegate) 175 { 176 this._script = script; 177 this._rawLocation = rawLocation; 178 this._updateDelegate = updateDelegate; 179 } 180 181 WebInspector.Script.Location.prototype = { 182 dispose: function() 183 { 184 this._script._locations.remove(this); 185 }, 186 187 _update: function() 188 { 189 if (!this._script._sourceMapping) 190 return; 191 var uiLocation = this._script._sourceMapping.rawLocationToUILocation(this._rawLocation); 192 if (uiLocation) { 193 var oneTime = this._updateDelegate(uiLocation); 194 if (oneTime) 195 this.dispose(); 196 } 197 } 198 } -
trunk/Source/WebCore/inspector/front-end/ScriptMapping.js
r111694 r115064 31 31 /** 32 32 * @constructor 33 * @param {WebInspector.UISourceCode} uiSourceCode 34 * @param {number} lineNumber 35 * @param {number} columnNumber 36 */ 37 WebInspector.UILocation = function(uiSourceCode, lineNumber, columnNumber) 38 { 39 this.uiSourceCode = uiSourceCode; 40 this.lineNumber = lineNumber; 41 this.columnNumber = columnNumber; 42 } 43 44 /** 45 * @interface 46 */ 47 WebInspector.SourceMapping = function() 48 { 49 } 50 51 WebInspector.SourceMapping.prototype = { 52 /** 53 * @param {DebuggerAgent.Location} rawLocation 54 * @return {WebInspector.UILocation} 55 */ 56 rawLocationToUILocation: function(rawLocation) { }, 57 58 /** 59 * @param {WebInspector.UISourceCode} uiSourceCode 60 * @param {number} lineNumber 61 * @param {number} columnNumber 62 * @return {DebuggerAgent.Location} 63 */ 64 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) { } 65 } 66 67 /** 68 * @constructor 33 69 * @extends {WebInspector.Object} 70 * @implements {WebInspector.SourceMapping} 34 71 */ 35 72 WebInspector.ScriptMapping = function() … … 38 75 39 76 WebInspector.ScriptMapping.Events = { 40 UISourceCodeListChanged: "ui-source-code-list-changed", 41 ScriptBound: "script-bound", 42 ScriptUnbound: "script-unbound", 77 UISourceCodeListChanged: "ui-source-code-list-changed" 43 78 } 44 79 … … 81 116 this._mappings.push(this._snippetsMapping); 82 117 83 for (var i = 0; i < this._mappings.length; ++i) {118 for (var i = 0; i < this._mappings.length; ++i) 84 119 this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this); 85 this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.ScriptBound, this._handleScriptBound, this);86 this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.ScriptUnbound, this._handleScriptUnbound, this);87 }88 120 89 121 this._mappingForScriptId = {}; 90 122 this._mappingForUISourceCode = new Map(); 91 this._liveLocationsForScriptId = {};92 123 } 93 124 … … 115 146 { 116 147 return this._mappingForUISourceCode.get(uiSourceCode).uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber); 117 },118 119 /**120 * @param {DebuggerAgent.Location} rawLocation121 * @param {function(WebInspector.UILocation)} updateDelegate122 * @return {WebInspector.LiveLocation}123 */124 createLiveLocation: function(rawLocation, updateDelegate)125 {126 return new WebInspector.LiveLocation(this, rawLocation, updateDelegate);127 },128 129 _registerLiveLocation: function(scriptId, liveLocation)130 {131 this._liveLocationsForScriptId[scriptId].push(liveLocation)132 liveLocation._update();133 },134 135 _unregisterLiveLocation: function(scriptId, liveLocation)136 {137 if (this._liveLocationsForScriptId[scriptId])138 this._liveLocationsForScriptId[scriptId].remove(liveLocation);139 },140 141 _updateLiveLocation: function(scriptId)142 {143 var liveLocations = this._liveLocationsForScriptId[scriptId];144 for (var j = 0; j < liveLocations.length; ++j)145 liveLocations[j]._update();146 148 }, 147 149 … … 165 167 addScript: function(script) 166 168 { 167 this._liveLocationsForScriptId[script.scriptId] = [];168 169 169 var mapping = this._mappingForScript(script); 170 170 this._mappingForScriptId[script.scriptId] = mapping; … … 208 208 209 209 /** 210 * @param {WebInspector.Event} event211 */212 _handleScriptBound: function(event)213 {214 var scriptId = /** @type {number} */ event.data.scriptId;215 this._updateLiveLocation(scriptId);216 },217 218 /**219 * @param {WebInspector.Event} event220 */221 _handleScriptUnbound: function(event)222 {223 var scriptId = /** @type {number} */ event.data.scriptId;224 this._updateLiveLocation(scriptId);225 },226 227 228 /**229 210 * @param {boolean} formatSource 230 211 */ … … 249 230 this._mappingForScriptId = {}; 250 231 this._mappingForUISourceCode = new Map(); 251 this._liveLocationsForScriptId = {};252 232 } 253 233 } 254 234 255 235 WebInspector.MainScriptMapping.prototype.__proto__ = WebInspector.Object.prototype; 256 257 /**258 * @constructor259 * @param {WebInspector.MainScriptMapping} scriptMapping260 * @param {DebuggerAgent.Location} rawLocation261 * @param {function(WebInspector.UILocation)} updateDelegate262 */263 WebInspector.LiveLocation = function(scriptMapping, rawLocation, updateDelegate)264 {265 this._scriptMapping = scriptMapping;266 this._rawLocation = rawLocation;267 this._updateDelegate = updateDelegate;268 }269 270 WebInspector.LiveLocation.prototype = {271 init: function()272 {273 this._scriptMapping._registerLiveLocation(this._rawLocation.scriptId, this);274 },275 276 dispose: function()277 {278 this._scriptMapping._unregisterLiveLocation(this._rawLocation.scriptId, this);279 },280 281 _update: function()282 {283 var uiLocation = this._scriptMapping.rawLocationToUILocation(this._rawLocation);284 if (uiLocation)285 this._updateDelegate(uiLocation);286 }287 } -
trunk/Source/WebCore/inspector/front-end/SnippetsModel.js
r114892 r115064 375 375 this._snippetForScriptId[script.scriptId] = snippet; 376 376 this._scriptForUISourceCode.put(uiSourceCode, script); 377 var data = { scriptId: script.scriptId, uiSourceCodes: [uiSourceCode] }; 378 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data); 377 script.setSourceMapping(this); 379 378 }, 380 379 … … 423 422 this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode; 424 423 this._scriptForUISourceCode.put(uiSourceCode, script); 425 var data = { scriptId: script.scriptId, uiSourceCodes: [oldUISourceCode] }; 426 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptUnbound, data); 427 data = { removedItems: [], addedItems: [uiSourceCode] }; 424 var data = { removedItems: [], addedItems: [uiSourceCode] }; 428 425 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data); 429 data = { scriptId: script.scriptId, uiSourceCodes: [uiSourceCode] }; 430 this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data); 426 script.setSourceMapping(this); 431 427 }, 432 428
Note: See TracChangeset
for help on using the changeset viewer.