| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 /** | 30 /** |
| 31 * @implements {WebInspector.DebuggerSourceMapping} | 31 * @implements {Bindings.DebuggerSourceMapping} |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.ResourceScriptMapping = class { | 34 Bindings.ResourceScriptMapping = class { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.DebuggerModel} debuggerModel | 36 * @param {!SDK.DebuggerModel} debuggerModel |
| 37 * @param {!WebInspector.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 38 * @param {!WebInspector.NetworkMapping} networkMapping | 38 * @param {!Bindings.NetworkMapping} networkMapping |
| 39 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 39 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 40 */ | 40 */ |
| 41 constructor(debuggerModel, workspace, networkMapping, debuggerWorkspaceBinding
) { | 41 constructor(debuggerModel, workspace, networkMapping, debuggerWorkspaceBinding
) { |
| 42 this._target = debuggerModel.target(); | 42 this._target = debuggerModel.target(); |
| 43 this._debuggerModel = debuggerModel; | 43 this._debuggerModel = debuggerModel; |
| 44 this._networkMapping = networkMapping; | 44 this._networkMapping = networkMapping; |
| 45 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | 45 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; |
| 46 /** @type {!Set<!WebInspector.UISourceCode>} */ | 46 /** @type {!Set<!Workspace.UISourceCode>} */ |
| 47 this._boundUISourceCodes = new Set(); | 47 this._boundUISourceCodes = new Set(); |
| 48 | 48 |
| 49 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.ResourceScriptFil
e>} */ | 49 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.ResourceScriptFile>} */ |
| 50 this._uiSourceCodeToScriptFile = new Map(); | 50 this._uiSourceCodeToScriptFile = new Map(); |
| 51 | 51 |
| 52 this._eventListeners = [ | 52 this._eventListeners = [ |
| 53 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObj
ectCleared, this._debuggerReset, this), | 53 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleare
d, this._debuggerReset, this), |
| 54 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded
, this._uiSourceCodeAdded, this), | 54 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, t
his._uiSourceCodeAdded, this), |
| 55 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemov
ed, this._uiSourceCodeRemoved, this) | 55 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRemoved,
this._uiSourceCodeRemoved, this) |
| 56 ]; | 56 ]; |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * @override | 60 * @override |
| 61 * @param {!WebInspector.DebuggerModel.Location} rawLocation | 61 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 62 * @return {?WebInspector.UILocation} | 62 * @return {?Workspace.UILocation} |
| 63 */ | 63 */ |
| 64 rawLocationToUILocation(rawLocation) { | 64 rawLocationToUILocation(rawLocation) { |
| 65 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Location}
*/ (rawLocation); | 65 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); |
| 66 var script = debuggerModelLocation.script(); | 66 var script = debuggerModelLocation.script(); |
| 67 if (!script) | 67 if (!script) |
| 68 return null; | 68 return null; |
| 69 var uiSourceCode = this._workspaceUISourceCodeForScript(script); | 69 var uiSourceCode = this._workspaceUISourceCodeForScript(script); |
| 70 if (!uiSourceCode) | 70 if (!uiSourceCode) |
| 71 return null; | 71 return null; |
| 72 var scriptFile = this.scriptFile(uiSourceCode); | 72 var scriptFile = this.scriptFile(uiSourceCode); |
| 73 if (scriptFile && | 73 if (scriptFile && |
| 74 ((scriptFile.hasDivergedFromVM() && !scriptFile.isMergingToVM()) || scri
ptFile.isDivergingFromVM())) | 74 ((scriptFile.hasDivergedFromVM() && !scriptFile.isMergingToVM()) || scri
ptFile.isDivergingFromVM())) |
| 75 return null; | 75 return null; |
| 76 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi
thSourceURL() ? script.lineOffset : 0); | 76 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi
thSourceURL() ? script.lineOffset : 0); |
| 77 var columnNumber = debuggerModelLocation.columnNumber || 0; | 77 var columnNumber = debuggerModelLocation.columnNumber || 0; |
| 78 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber) | 78 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber) |
| 79 columnNumber -= script.columnOffset; | 79 columnNumber -= script.columnOffset; |
| 80 return uiSourceCode.uiLocation(lineNumber, columnNumber); | 80 return uiSourceCode.uiLocation(lineNumber, columnNumber); |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @override | 84 * @override |
| 85 * @param {!WebInspector.UISourceCode} uiSourceCode | 85 * @param {!Workspace.UISourceCode} uiSourceCode |
| 86 * @param {number} lineNumber | 86 * @param {number} lineNumber |
| 87 * @param {number} columnNumber | 87 * @param {number} columnNumber |
| 88 * @return {?WebInspector.DebuggerModel.Location} | 88 * @return {?SDK.DebuggerModel.Location} |
| 89 */ | 89 */ |
| 90 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 90 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 91 var scripts = this._scriptsForUISourceCode(uiSourceCode); | 91 var scripts = this._scriptsForUISourceCode(uiSourceCode); |
| 92 console.assert(scripts.length); | 92 console.assert(scripts.length); |
| 93 var script = scripts[scripts.length - 1]; | 93 var script = scripts[scripts.length - 1]; |
| 94 if (script.isInlineScriptWithSourceURL()) | 94 if (script.isInlineScriptWithSourceURL()) |
| 95 return this._debuggerModel.createRawLocation( | 95 return this._debuggerModel.createRawLocation( |
| 96 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co
lumnNumber + script.columnOffset); | 96 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co
lumnNumber + script.columnOffset); |
| 97 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); | 97 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe
r); |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * @param {!WebInspector.Script} script | 101 * @param {!SDK.Script} script |
| 102 */ | 102 */ |
| 103 addScript(script) { | 103 addScript(script) { |
| 104 if (script.isAnonymousScript()) | 104 if (script.isAnonymousScript()) |
| 105 return; | 105 return; |
| 106 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); | 106 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); |
| 107 | 107 |
| 108 var uiSourceCode = this._workspaceUISourceCodeForScript(script); | 108 var uiSourceCode = this._workspaceUISourceCodeForScript(script); |
| 109 if (!uiSourceCode) | 109 if (!uiSourceCode) |
| 110 return; | 110 return; |
| 111 | 111 |
| 112 this._bindUISourceCodeToScripts(uiSourceCode, [script]); | 112 this._bindUISourceCodeToScripts(uiSourceCode, [script]); |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * @override | 116 * @override |
| 117 * @return {boolean} | 117 * @return {boolean} |
| 118 */ | 118 */ |
| 119 isIdentity() { | 119 isIdentity() { |
| 120 return true; | 120 return true; |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * @override | 124 * @override |
| 125 * @param {!WebInspector.UISourceCode} uiSourceCode | 125 * @param {!Workspace.UISourceCode} uiSourceCode |
| 126 * @param {number} lineNumber | 126 * @param {number} lineNumber |
| 127 * @return {boolean} | 127 * @return {boolean} |
| 128 */ | 128 */ |
| 129 uiLineHasMapping(uiSourceCode, lineNumber) { | 129 uiLineHasMapping(uiSourceCode, lineNumber) { |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @param {!WebInspector.UISourceCode} uiSourceCode | 134 * @param {!Workspace.UISourceCode} uiSourceCode |
| 135 * @return {?WebInspector.ResourceScriptFile} | 135 * @return {?Bindings.ResourceScriptFile} |
| 136 */ | 136 */ |
| 137 scriptFile(uiSourceCode) { | 137 scriptFile(uiSourceCode) { |
| 138 return this._uiSourceCodeToScriptFile.get(uiSourceCode) || null; | 138 return this._uiSourceCodeToScriptFile.get(uiSourceCode) || null; |
| 139 } | 139 } |
| 140 | 140 |
| 141 /** | 141 /** |
| 142 * @param {!WebInspector.UISourceCode} uiSourceCode | 142 * @param {!Workspace.UISourceCode} uiSourceCode |
| 143 * @param {?WebInspector.ResourceScriptFile} scriptFile | 143 * @param {?Bindings.ResourceScriptFile} scriptFile |
| 144 */ | 144 */ |
| 145 _setScriptFile(uiSourceCode, scriptFile) { | 145 _setScriptFile(uiSourceCode, scriptFile) { |
| 146 if (scriptFile) | 146 if (scriptFile) |
| 147 this._uiSourceCodeToScriptFile.set(uiSourceCode, scriptFile); | 147 this._uiSourceCodeToScriptFile.set(uiSourceCode, scriptFile); |
| 148 else | 148 else |
| 149 this._uiSourceCodeToScriptFile.remove(uiSourceCode); | 149 this._uiSourceCodeToScriptFile.remove(uiSourceCode); |
| 150 } | 150 } |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * @param {!WebInspector.Event} event | 153 * @param {!Common.Event} event |
| 154 */ | 154 */ |
| 155 _uiSourceCodeAdded(event) { | 155 _uiSourceCodeAdded(event) { |
| 156 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); | 156 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| 157 if (uiSourceCode.isFromServiceProject()) | 157 if (uiSourceCode.isFromServiceProject()) |
| 158 return; | 158 return; |
| 159 var scripts = this._scriptsForUISourceCode(uiSourceCode); | 159 var scripts = this._scriptsForUISourceCode(uiSourceCode); |
| 160 if (!scripts.length) | 160 if (!scripts.length) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 this._bindUISourceCodeToScripts(uiSourceCode, scripts); | 163 this._bindUISourceCodeToScripts(uiSourceCode, scripts); |
| 164 } | 164 } |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * @param {!WebInspector.Event} event | 167 * @param {!Common.Event} event |
| 168 */ | 168 */ |
| 169 _uiSourceCodeRemoved(event) { | 169 _uiSourceCodeRemoved(event) { |
| 170 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); | 170 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); |
| 171 if (uiSourceCode.isFromServiceProject() || !this._boundUISourceCodes.has(uiS
ourceCode)) | 171 if (uiSourceCode.isFromServiceProject() || !this._boundUISourceCodes.has(uiS
ourceCode)) |
| 172 return; | 172 return; |
| 173 | 173 |
| 174 this._unbindUISourceCode(uiSourceCode); | 174 this._unbindUISourceCode(uiSourceCode); |
| 175 } | 175 } |
| 176 | 176 |
| 177 /** | 177 /** |
| 178 * @param {!WebInspector.UISourceCode} uiSourceCode | 178 * @param {!Workspace.UISourceCode} uiSourceCode |
| 179 */ | 179 */ |
| 180 _updateLocations(uiSourceCode) { | 180 _updateLocations(uiSourceCode) { |
| 181 var scripts = this._scriptsForUISourceCode(uiSourceCode); | 181 var scripts = this._scriptsForUISourceCode(uiSourceCode); |
| 182 if (!scripts.length) | 182 if (!scripts.length) |
| 183 return; | 183 return; |
| 184 for (var i = 0; i < scripts.length; ++i) | 184 for (var i = 0; i < scripts.length; ++i) |
| 185 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); | 185 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); |
| 186 } | 186 } |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * @param {!WebInspector.Script} script | 189 * @param {!SDK.Script} script |
| 190 * @return {?WebInspector.UISourceCode} | 190 * @return {?Workspace.UISourceCode} |
| 191 */ | 191 */ |
| 192 _workspaceUISourceCodeForScript(script) { | 192 _workspaceUISourceCodeForScript(script) { |
| 193 if (script.isAnonymousScript()) | 193 if (script.isAnonymousScript()) |
| 194 return null; | 194 return null; |
| 195 return this._networkMapping.uiSourceCodeForScriptURL(script.sourceURL, scrip
t); | 195 return this._networkMapping.uiSourceCodeForScriptURL(script.sourceURL, scrip
t); |
| 196 } | 196 } |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * @param {!WebInspector.UISourceCode} uiSourceCode | 199 * @param {!Workspace.UISourceCode} uiSourceCode |
| 200 * @return {!Array.<!WebInspector.Script>} | 200 * @return {!Array.<!SDK.Script>} |
| 201 */ | 201 */ |
| 202 _scriptsForUISourceCode(uiSourceCode) { | 202 _scriptsForUISourceCode(uiSourceCode) { |
| 203 var target = WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode)
; | 203 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| 204 if (target !== this._debuggerModel.target()) | 204 if (target !== this._debuggerModel.target()) |
| 205 return []; | 205 return []; |
| 206 return this._debuggerModel.scriptsForSourceURL(uiSourceCode.url()); | 206 return this._debuggerModel.scriptsForSourceURL(uiSourceCode.url()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @param {!WebInspector.UISourceCode} uiSourceCode | 210 * @param {!Workspace.UISourceCode} uiSourceCode |
| 211 * @param {!Array.<!WebInspector.Script>} scripts | 211 * @param {!Array.<!SDK.Script>} scripts |
| 212 */ | 212 */ |
| 213 _bindUISourceCodeToScripts(uiSourceCode, scripts) { | 213 _bindUISourceCodeToScripts(uiSourceCode, scripts) { |
| 214 console.assert(scripts.length); | 214 console.assert(scripts.length); |
| 215 // Due to different listeners order, a script file could be created just bef
ore uiSourceCode | 215 // Due to different listeners order, a script file could be created just bef
ore uiSourceCode |
| 216 // for the corresponding script was created. Check that we don't create scri
ptFile twice. | 216 // for the corresponding script was created. Check that we don't create scri
ptFile twice. |
| 217 var boundScriptFile = this.scriptFile(uiSourceCode); | 217 var boundScriptFile = this.scriptFile(uiSourceCode); |
| 218 if (boundScriptFile && boundScriptFile._hasScripts(scripts)) | 218 if (boundScriptFile && boundScriptFile._hasScripts(scripts)) |
| 219 return; | 219 return; |
| 220 | 220 |
| 221 var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode, scr
ipts); | 221 var scriptFile = new Bindings.ResourceScriptFile(this, uiSourceCode, scripts
); |
| 222 this._setScriptFile(uiSourceCode, scriptFile); | 222 this._setScriptFile(uiSourceCode, scriptFile); |
| 223 for (var i = 0; i < scripts.length; ++i) | 223 for (var i = 0; i < scripts.length; ++i) |
| 224 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); | 224 this._debuggerWorkspaceBinding.updateLocations(scripts[i]); |
| 225 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCode,
this); | 225 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCode,
this); |
| 226 this._boundUISourceCodes.add(uiSourceCode); | 226 this._boundUISourceCodes.add(uiSourceCode); |
| 227 } | 227 } |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * @param {!WebInspector.UISourceCode} uiSourceCode | 230 * @param {!Workspace.UISourceCode} uiSourceCode |
| 231 */ | 231 */ |
| 232 _unbindUISourceCode(uiSourceCode) { | 232 _unbindUISourceCode(uiSourceCode) { |
| 233 var scriptFile = this.scriptFile(uiSourceCode); | 233 var scriptFile = this.scriptFile(uiSourceCode); |
| 234 if (scriptFile) { | 234 if (scriptFile) { |
| 235 scriptFile.dispose(); | 235 scriptFile.dispose(); |
| 236 this._setScriptFile(uiSourceCode, null); | 236 this._setScriptFile(uiSourceCode, null); |
| 237 } | 237 } |
| 238 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCode,
null); | 238 this._debuggerWorkspaceBinding.setSourceMapping(this._target, uiSourceCode,
null); |
| 239 this._boundUISourceCodes.delete(uiSourceCode); | 239 this._boundUISourceCodes.delete(uiSourceCode); |
| 240 } | 240 } |
| 241 | 241 |
| 242 _debuggerReset() { | 242 _debuggerReset() { |
| 243 for (var uiSourceCode of this._boundUISourceCodes.valuesArray()) | 243 for (var uiSourceCode of this._boundUISourceCodes.valuesArray()) |
| 244 this._unbindUISourceCode(uiSourceCode); | 244 this._unbindUISourceCode(uiSourceCode); |
| 245 this._boundUISourceCodes.clear(); | 245 this._boundUISourceCodes.clear(); |
| 246 console.assert(!this._uiSourceCodeToScriptFile.size); | 246 console.assert(!this._uiSourceCodeToScriptFile.size); |
| 247 } | 247 } |
| 248 | 248 |
| 249 dispose() { | 249 dispose() { |
| 250 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 250 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 251 this._debuggerReset(); | 251 this._debuggerReset(); |
| 252 } | 252 } |
| 253 }; | 253 }; |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * @unrestricted | 256 * @unrestricted |
| 257 */ | 257 */ |
| 258 WebInspector.ResourceScriptFile = class extends WebInspector.Object { | 258 Bindings.ResourceScriptFile = class extends Common.Object { |
| 259 /** | 259 /** |
| 260 * @param {!WebInspector.ResourceScriptMapping} resourceScriptMapping | 260 * @param {!Bindings.ResourceScriptMapping} resourceScriptMapping |
| 261 * @param {!WebInspector.UISourceCode} uiSourceCode | 261 * @param {!Workspace.UISourceCode} uiSourceCode |
| 262 * @param {!Array.<!WebInspector.Script>} scripts | 262 * @param {!Array.<!SDK.Script>} scripts |
| 263 */ | 263 */ |
| 264 constructor(resourceScriptMapping, uiSourceCode, scripts) { | 264 constructor(resourceScriptMapping, uiSourceCode, scripts) { |
| 265 super(); | 265 super(); |
| 266 console.assert(scripts.length); | 266 console.assert(scripts.length); |
| 267 | 267 |
| 268 this._resourceScriptMapping = resourceScriptMapping; | 268 this._resourceScriptMapping = resourceScriptMapping; |
| 269 this._uiSourceCode = uiSourceCode; | 269 this._uiSourceCode = uiSourceCode; |
| 270 | 270 |
| 271 if (this._uiSourceCode.contentType().isScript()) | 271 if (this._uiSourceCode.contentType().isScript()) |
| 272 this._script = scripts[scripts.length - 1]; | 272 this._script = scripts[scripts.length - 1]; |
| 273 | 273 |
| 274 this._uiSourceCode.addEventListener( | 274 this._uiSourceCode.addEventListener( |
| 275 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh
anged, this); | 275 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang
ed, this); |
| 276 this._uiSourceCode.addEventListener( | 276 this._uiSourceCode.addEventListener( |
| 277 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy
Committed, this); | 277 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom
mitted, this); |
| 278 } | 278 } |
| 279 | 279 |
| 280 /** | 280 /** |
| 281 * @param {!Array.<!WebInspector.Script>} scripts | 281 * @param {!Array.<!SDK.Script>} scripts |
| 282 * @return {boolean} | 282 * @return {boolean} |
| 283 */ | 283 */ |
| 284 _hasScripts(scripts) { | 284 _hasScripts(scripts) { |
| 285 return this._script && this._script === scripts[0]; | 285 return this._script && this._script === scripts[0]; |
| 286 } | 286 } |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * @return {boolean} | 289 * @return {boolean} |
| 290 */ | 290 */ |
| 291 _isDiverged() { | 291 _isDiverged() { |
| 292 if (this._uiSourceCode.isDirty()) | 292 if (this._uiSourceCode.isDirty()) |
| 293 return true; | 293 return true; |
| 294 if (!this._script) | 294 if (!this._script) |
| 295 return false; | 295 return false; |
| 296 if (typeof this._scriptSource === 'undefined') | 296 if (typeof this._scriptSource === 'undefined') |
| 297 return false; | 297 return false; |
| 298 var workingCopy = this._uiSourceCode.workingCopy(); | 298 var workingCopy = this._uiSourceCode.workingCopy(); |
| 299 | 299 |
| 300 // Match ignoring sourceURL. | 300 // Match ignoring sourceURL. |
| 301 if (!workingCopy.startsWith(this._scriptSource.trimRight())) | 301 if (!workingCopy.startsWith(this._scriptSource.trimRight())) |
| 302 return true; | 302 return true; |
| 303 var suffix = this._uiSourceCode.workingCopy().substr(this._scriptSource.leng
th); | 303 var suffix = this._uiSourceCode.workingCopy().substr(this._scriptSource.leng
th); |
| 304 return !!suffix.length && !suffix.match(WebInspector.Script.sourceURLRegex); | 304 return !!suffix.length && !suffix.match(SDK.Script.sourceURLRegex); |
| 305 } | 305 } |
| 306 | 306 |
| 307 /** | 307 /** |
| 308 * @param {!WebInspector.Event} event | 308 * @param {!Common.Event} event |
| 309 */ | 309 */ |
| 310 _workingCopyChanged(event) { | 310 _workingCopyChanged(event) { |
| 311 this._update(); | 311 this._update(); |
| 312 } | 312 } |
| 313 | 313 |
| 314 _workingCopyCommitted(event) { | 314 _workingCopyCommitted(event) { |
| 315 if (this._uiSourceCode.project().type() === WebInspector.projectTypes.Snippe
ts) | 315 if (this._uiSourceCode.project().type() === Workspace.projectTypes.Snippets) |
| 316 return; | 316 return; |
| 317 if (!this._script) | 317 if (!this._script) |
| 318 return; | 318 return; |
| 319 var debuggerModel = this._resourceScriptMapping._debuggerModel; | 319 var debuggerModel = this._resourceScriptMapping._debuggerModel; |
| 320 var source = this._uiSourceCode.workingCopy(); | 320 var source = this._uiSourceCode.workingCopy(); |
| 321 debuggerModel.setScriptSource(this._script.scriptId, source, scriptSourceWas
Set.bind(this)); | 321 debuggerModel.setScriptSource(this._script.scriptId, source, scriptSourceWas
Set.bind(this)); |
| 322 | 322 |
| 323 /** | 323 /** |
| 324 * @param {?string} error | 324 * @param {?string} error |
| 325 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails | 325 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails |
| 326 * @this {WebInspector.ResourceScriptFile} | 326 * @this {Bindings.ResourceScriptFile} |
| 327 */ | 327 */ |
| 328 function scriptSourceWasSet(error, exceptionDetails) { | 328 function scriptSourceWasSet(error, exceptionDetails) { |
| 329 if (!error && !exceptionDetails) | 329 if (!error && !exceptionDetails) |
| 330 this._scriptSource = source; | 330 this._scriptSource = source; |
| 331 this._update(); | 331 this._update(); |
| 332 | 332 |
| 333 if (!error && !exceptionDetails) | 333 if (!error && !exceptionDetails) |
| 334 return; | 334 return; |
| 335 if (!exceptionDetails) { | 335 if (!exceptionDetails) { |
| 336 WebInspector.console.addMessage( | 336 Common.console.addMessage( |
| 337 WebInspector.UIString('LiveEdit failed: %s', error), WebInspector.Co
nsole.MessageLevel.Warning); | 337 Common.UIString('LiveEdit failed: %s', error), Common.Console.Messag
eLevel.Warning); |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 var messageText = WebInspector.UIString('LiveEdit compile failed: %s', exc
eptionDetails.text); | 340 var messageText = Common.UIString('LiveEdit compile failed: %s', exception
Details.text); |
| 341 this._uiSourceCode.addLineMessage( | 341 this._uiSourceCode.addLineMessage( |
| 342 WebInspector.UISourceCode.Message.Level.Error, messageText, exceptionD
etails.lineNumber, | 342 Workspace.UISourceCode.Message.Level.Error, messageText, exceptionDeta
ils.lineNumber, |
| 343 exceptionDetails.columnNumber); | 343 exceptionDetails.columnNumber); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 _update() { | 347 _update() { |
| 348 if (this._isDiverged() && !this._hasDivergedFromVM) | 348 if (this._isDiverged() && !this._hasDivergedFromVM) |
| 349 this._divergeFromVM(); | 349 this._divergeFromVM(); |
| 350 else if (!this._isDiverged() && this._hasDivergedFromVM) | 350 else if (!this._isDiverged() && this._hasDivergedFromVM) |
| 351 this._mergeToVM(); | 351 this._mergeToVM(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 _divergeFromVM() { | 354 _divergeFromVM() { |
| 355 this._isDivergingFromVM = true; | 355 this._isDivergingFromVM = true; |
| 356 this._resourceScriptMapping._updateLocations(this._uiSourceCode); | 356 this._resourceScriptMapping._updateLocations(this._uiSourceCode); |
| 357 delete this._isDivergingFromVM; | 357 delete this._isDivergingFromVM; |
| 358 this._hasDivergedFromVM = true; | 358 this._hasDivergedFromVM = true; |
| 359 this.dispatchEventToListeners(WebInspector.ResourceScriptFile.Events.DidDive
rgeFromVM, this._uiSourceCode); | 359 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidDivergeF
romVM, this._uiSourceCode); |
| 360 } | 360 } |
| 361 | 361 |
| 362 _mergeToVM() { | 362 _mergeToVM() { |
| 363 delete this._hasDivergedFromVM; | 363 delete this._hasDivergedFromVM; |
| 364 this._isMergingToVM = true; | 364 this._isMergingToVM = true; |
| 365 this._resourceScriptMapping._updateLocations(this._uiSourceCode); | 365 this._resourceScriptMapping._updateLocations(this._uiSourceCode); |
| 366 delete this._isMergingToVM; | 366 delete this._isMergingToVM; |
| 367 this.dispatchEventToListeners(WebInspector.ResourceScriptFile.Events.DidMerg
eToVM, this._uiSourceCode); | 367 this.dispatchEventToListeners(Bindings.ResourceScriptFile.Events.DidMergeToV
M, this._uiSourceCode); |
| 368 } | 368 } |
| 369 | 369 |
| 370 /** | 370 /** |
| 371 * @return {boolean} | 371 * @return {boolean} |
| 372 */ | 372 */ |
| 373 hasDivergedFromVM() { | 373 hasDivergedFromVM() { |
| 374 return this._hasDivergedFromVM; | 374 return this._hasDivergedFromVM; |
| 375 } | 375 } |
| 376 | 376 |
| 377 /** | 377 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 390 | 390 |
| 391 checkMapping() { | 391 checkMapping() { |
| 392 if (!this._script || typeof this._scriptSource !== 'undefined') { | 392 if (!this._script || typeof this._scriptSource !== 'undefined') { |
| 393 this._mappingCheckedForTest(); | 393 this._mappingCheckedForTest(); |
| 394 return; | 394 return; |
| 395 } | 395 } |
| 396 this._script.requestContent().then(callback.bind(this)); | 396 this._script.requestContent().then(callback.bind(this)); |
| 397 | 397 |
| 398 /** | 398 /** |
| 399 * @param {?string} source | 399 * @param {?string} source |
| 400 * @this {WebInspector.ResourceScriptFile} | 400 * @this {Bindings.ResourceScriptFile} |
| 401 */ | 401 */ |
| 402 function callback(source) { | 402 function callback(source) { |
| 403 this._scriptSource = source; | 403 this._scriptSource = source; |
| 404 this._update(); | 404 this._update(); |
| 405 this._mappingCheckedForTest(); | 405 this._mappingCheckedForTest(); |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 _mappingCheckedForTest() { | 409 _mappingCheckedForTest() { |
| 410 } | 410 } |
| 411 | 411 |
| 412 /** | 412 /** |
| 413 * @return {?WebInspector.Target} | 413 * @return {?SDK.Target} |
| 414 */ | 414 */ |
| 415 target() { | 415 target() { |
| 416 if (!this._script) | 416 if (!this._script) |
| 417 return null; | 417 return null; |
| 418 return this._script.target(); | 418 return this._script.target(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 dispose() { | 421 dispose() { |
| 422 this._uiSourceCode.removeEventListener( | 422 this._uiSourceCode.removeEventListener( |
| 423 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh
anged, this); | 423 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang
ed, this); |
| 424 this._uiSourceCode.removeEventListener( | 424 this._uiSourceCode.removeEventListener( |
| 425 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy
Committed, this); | 425 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom
mitted, this); |
| 426 } | 426 } |
| 427 | 427 |
| 428 /** | 428 /** |
| 429 * @param {string} sourceMapURL | 429 * @param {string} sourceMapURL |
| 430 */ | 430 */ |
| 431 addSourceMapURL(sourceMapURL) { | 431 addSourceMapURL(sourceMapURL) { |
| 432 if (!this._script) | 432 if (!this._script) |
| 433 return; | 433 return; |
| 434 this._script.addSourceMapURL(sourceMapURL); | 434 this._script.addSourceMapURL(sourceMapURL); |
| 435 } | 435 } |
| 436 | 436 |
| 437 /** | 437 /** |
| 438 * @return {boolean} | 438 * @return {boolean} |
| 439 */ | 439 */ |
| 440 hasSourceMapURL() { | 440 hasSourceMapURL() { |
| 441 return this._script && !!this._script.sourceMapURL; | 441 return this._script && !!this._script.sourceMapURL; |
| 442 } | 442 } |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 /** @enum {symbol} */ | 445 /** @enum {symbol} */ |
| 446 WebInspector.ResourceScriptFile.Events = { | 446 Bindings.ResourceScriptFile.Events = { |
| 447 DidMergeToVM: Symbol('DidMergeToVM'), | 447 DidMergeToVM: Symbol('DidMergeToVM'), |
| 448 DidDivergeFromVM: Symbol('DidDivergeFromVM'), | 448 DidDivergeFromVM: Symbol('DidDivergeFromVM'), |
| 449 }; | 449 }; |
| OLD | NEW |