| 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 22 matching lines...) Expand all Loading... |
| 33 */ | 33 */ |
| 34 Bindings.CompilerScriptMapping = class { | 34 Bindings.CompilerScriptMapping = class { |
| 35 /** | 35 /** |
| 36 * @param {!SDK.DebuggerModel} debuggerModel | 36 * @param {!SDK.DebuggerModel} debuggerModel |
| 37 * @param {!Workspace.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 38 * @param {!Bindings.NetworkProject} networkProject | 38 * @param {!Bindings.NetworkProject} networkProject |
| 39 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding | 39 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding |
| 40 */ | 40 */ |
| 41 constructor(debuggerModel, workspace, networkProject, debuggerWorkspaceBinding
) { | 41 constructor(debuggerModel, workspace, networkProject, debuggerWorkspaceBinding
) { |
| 42 this._debuggerModel = debuggerModel; | 42 this._debuggerModel = debuggerModel; |
| 43 this._sourceMapManager = this._debuggerModel.sourceMapManager(); |
| 43 this._workspace = workspace; | 44 this._workspace = workspace; |
| 44 this._networkProject = networkProject; | 45 this._networkProject = networkProject; |
| 45 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; | 46 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; |
| 46 | 47 |
| 47 /** @type {!Map<string, !Promise<?SDK.TextSourceMap>>} */ | 48 /** @type {!Multimap<!SDK.Script, !Workspace.UISourceCode>} */ |
| 48 this._sourceMapLoadingPromises = new Map(); | 49 this._scriptSources = new Multimap(); |
| 49 /** @type {!Map<string, !SDK.TextSourceMap>} */ | 50 /** @type {!Map<!SDK.Script, !Workspace.UISourceCode>} */ |
| 50 this._sourceMapForScriptId = new Map(); | |
| 51 /** @type {!Map.<!SDK.TextSourceMap, !SDK.Script>} */ | |
| 52 this._scriptForSourceMap = new Map(); | |
| 53 /** @type {!Map.<string, !SDK.TextSourceMap>} */ | |
| 54 this._sourceMapForURL = new Map(); | |
| 55 /** @type {!Map.<string, !Workspace.UISourceCode>} */ | |
| 56 this._stubUISourceCodes = new Map(); | 51 this._stubUISourceCodes = new Map(); |
| 57 | 52 |
| 58 var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._debu
ggerModel.target()); | 53 var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._debu
ggerModel.target()); |
| 59 this._stubProject = new Bindings.ContentProviderBasedProject( | 54 this._stubProject = new Bindings.ContentProviderBasedProject( |
| 60 workspace, projectId, Workspace.projectTypes.Service, '', true /* isServ
iceProject */); | 55 workspace, projectId, Workspace.projectTypes.Service, '', true /* isServ
iceProject */); |
| 61 this._eventListeners = [ | 56 this._eventListeners = [ |
| 62 workspace.addEventListener( | 57 this._sourceMapManager.addEventListener( |
| 63 Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedT
oWorkspace, this), | 58 SDK.SourceMapManager.Events.SourceMapWillAttach, this._sourceMapWillAt
tach, this), |
| 64 debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCleare
d, this._debuggerReset, this), | 59 this._sourceMapManager.addEventListener( |
| 65 debuggerModel.addEventListener(SDK.DebuggerModel.Events.SourceMapURLAdded,
this._sourceMapURLAdded.bind(this)) | 60 SDK.SourceMapManager.Events.SourceMapFailedToAttach, this._sourceMapFa
iledToAttach, this), |
| 61 this._sourceMapManager.addEventListener( |
| 62 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached
, this), |
| 63 this._sourceMapManager.addEventListener( |
| 64 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached
, this), |
| 66 ]; | 65 ]; |
| 67 } | 66 } |
| 68 | 67 |
| 69 /** | 68 /** |
| 69 * @param {!SDK.Script} script |
| 70 */ |
| 71 _addStubUISourceCode(script) { |
| 72 var stubUISourceCode = this._stubProject.addContentProvider( |
| 73 script.sourceURL + ':sourcemap', |
| 74 Common.StaticContentProvider.fromString( |
| 75 script.sourceURL, Common.resourceTypes.Script, |
| 76 '\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown wh
ile source map is being loaded!')); |
| 77 this._stubUISourceCodes.set(script, stubUISourceCode); |
| 78 } |
| 79 |
| 80 /** |
| 81 * @param {!SDK.Script} script |
| 82 */ |
| 83 _removeStubUISourceCode(script) { |
| 84 var uiSourceCode = this._stubUISourceCodes.get(script); |
| 85 this._stubUISourceCodes.delete(script); |
| 86 this._stubProject.removeFile(uiSourceCode.url()); |
| 87 } |
| 88 |
| 89 /** |
| 70 * @param {!Workspace.UISourceCode} uiSourceCode | 90 * @param {!Workspace.UISourceCode} uiSourceCode |
| 71 * @return {?string} | 91 * @return {?string} |
| 72 */ | 92 */ |
| 73 static uiSourceCodeOrigin(uiSourceCode) { | 93 static uiSourceCodeOrigin(uiSourceCode) { |
| 74 return uiSourceCode[Bindings.CompilerScriptMapping._originSymbol] || null; | 94 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; |
| 95 return script ? script.sourceURL : null; |
| 75 } | 96 } |
| 76 | 97 |
| 77 /** | 98 /** |
| 78 * @param {!SDK.Target} target | 99 * @param {!SDK.Target} target |
| 79 * @return {string} | 100 * @return {string} |
| 80 */ | 101 */ |
| 81 static projectIdForTarget(target) { | 102 static projectIdForTarget(target) { |
| 82 return 'compiler-script-project:' + target.id(); | 103 return 'compiler-script-project:' + target.id(); |
| 83 } | 104 } |
| 84 | 105 |
| 85 /** | 106 /** |
| 86 * @param {!SDK.DebuggerModel.Location} rawLocation | 107 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 87 * @return {boolean} | 108 * @return {boolean} |
| 88 */ | 109 */ |
| 89 mapsToSourceCode(rawLocation) { | 110 mapsToSourceCode(rawLocation) { |
| 90 var sourceMap = this._sourceMapForScriptId.get(rawLocation.scriptId); | 111 var script = rawLocation.script(); |
| 112 var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) :
null; |
| 91 if (!sourceMap) | 113 if (!sourceMap) |
| 92 return true; | 114 return true; |
| 93 | |
| 94 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe
r); | 115 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe
r); |
| 95 } | 116 } |
| 96 | 117 |
| 97 /** | 118 /** |
| 98 * @override | 119 * @override |
| 99 * @param {!SDK.DebuggerModel.Location} rawLocation | 120 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 100 * @return {?Workspace.UILocation} | 121 * @return {?Workspace.UILocation} |
| 101 */ | 122 */ |
| 102 rawLocationToUILocation(rawLocation) { | 123 rawLocationToUILocation(rawLocation) { |
| 103 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); | 124 var script = rawLocation.script(); |
| 125 if (!script) |
| 126 return null; |
| 104 | 127 |
| 105 var stubUISourceCode = this._stubUISourceCodes.get(debuggerModelLocation.scr
iptId); | 128 var lineNumber = rawLocation.lineNumber; |
| 129 var columnNumber = rawLocation.columnNumber || 0; |
| 130 var stubUISourceCode = this._stubUISourceCodes.get(script); |
| 106 if (stubUISourceCode) | 131 if (stubUISourceCode) |
| 107 return new Workspace.UILocation(stubUISourceCode, rawLocation.lineNumber,
rawLocation.columnNumber); | 132 return new Workspace.UILocation(stubUISourceCode, lineNumber, columnNumber
); |
| 108 | 133 |
| 109 var sourceMap = this._sourceMapForScriptId.get(debuggerModelLocation.scriptI
d); | 134 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 110 if (!sourceMap) | 135 if (!sourceMap) |
| 111 return null; | 136 return null; |
| 112 var lineNumber = debuggerModelLocation.lineNumber; | |
| 113 var columnNumber = debuggerModelLocation.columnNumber || 0; | |
| 114 var entry = sourceMap.findEntry(lineNumber, columnNumber); | 137 var entry = sourceMap.findEntry(lineNumber, columnNumber); |
| 115 if (!entry || !entry.sourceURL) | 138 if (!entry || !entry.sourceURL) |
| 116 return null; | 139 return null; |
| 117 var script = rawLocation.script(); | |
| 118 if (!script) | |
| 119 return null; | |
| 120 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( | 140 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( |
| 121 this._workspace, /** @type {string} */ (entry.sourceURL), script); | 141 this._workspace, /** @type {string} */ (entry.sourceURL), script); |
| 122 if (!uiSourceCode) | 142 if (!uiSourceCode) |
| 123 return null; | 143 return null; |
| 124 return uiSourceCode.uiLocation( | 144 return uiSourceCode.uiLocation( |
| 125 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e
ntry.sourceColumnNumber)); | 145 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e
ntry.sourceColumnNumber)); |
| 126 } | 146 } |
| 127 | 147 |
| 128 /** | 148 /** |
| 129 * @override | 149 * @override |
| 130 * @param {!Workspace.UISourceCode} uiSourceCode | 150 * @param {!Workspace.UISourceCode} uiSourceCode |
| 131 * @param {number} lineNumber | 151 * @param {number} lineNumber |
| 132 * @param {number} columnNumber | 152 * @param {number} columnNumber |
| 133 * @return {?SDK.DebuggerModel.Location} | 153 * @return {?SDK.DebuggerModel.Location} |
| 134 */ | 154 */ |
| 135 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 155 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 136 if (uiSourceCode.project().type() === Workspace.projectTypes.Service) | 156 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; |
| 157 if (!script) |
| 137 return null; | 158 return null; |
| 138 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); | 159 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 139 if (!sourceMap) | 160 if (!sourceMap) |
| 140 return null; | 161 return null; |
| 141 var script = /** @type {!SDK.Script} */ (this._scriptForSourceMap.get(source
Map)); | |
| 142 console.assert(script); | |
| 143 var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber)
; | 162 var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber)
; |
| 144 if (!entry) | 163 if (!entry) |
| 145 return null; | 164 return null; |
| 146 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry
.columnNumber); | 165 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry
.columnNumber); |
| 147 } | 166 } |
| 148 | 167 |
| 149 /** | 168 /** |
| 169 * @param {!Common.Event} event |
| 170 */ |
| 171 _sourceMapWillAttach(event) { |
| 172 var script = /** @type {!SDK.Script} */ (event.data); |
| 173 // Create stub UISourceCode for the time source mapping is being loaded. |
| 174 this._addStubUISourceCode(script); |
| 175 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); |
| 176 } |
| 177 |
| 178 /** |
| 179 * @param {!Common.Event} event |
| 180 */ |
| 181 _sourceMapFailedToAttach(event) { |
| 182 var script = /** @type {!SDK.Script} */ (event.data); |
| 183 this._removeStubUISourceCode(script); |
| 184 } |
| 185 |
| 186 /** |
| 187 * @param {!Common.Event} event |
| 188 */ |
| 189 _sourceMapAttached(event) { |
| 190 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 191 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); |
| 192 this._removeStubUISourceCode(script); |
| 193 |
| 194 if (Bindings.blackboxManager.isBlackboxedURL(script.sourceURL, script.isCont
entScript())) |
| 195 return; |
| 196 Bindings.blackboxManager.sourceMapLoaded(script, sourceMap); |
| 197 |
| 198 this._populateSourceMapSources(script, sourceMap); |
| 199 this._sourceMapAttachedForTest(sourceMap); |
| 200 } |
| 201 |
| 202 /** |
| 203 * @param {!Common.Event} event |
| 204 */ |
| 205 _sourceMapDetached(event) { |
| 206 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 207 var sources = this._scriptSources.get(script); |
| 208 if (!sources.size) |
| 209 return; |
| 210 var frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol]; |
| 211 for (var uiSourceCode of sources) { |
| 212 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou
rceCode, null); |
| 213 this._networkProject.removeSourceMapFile(uiSourceCode.url(), frameId, scri
pt.isContentScript()); |
| 214 } |
| 215 this._debuggerWorkspaceBinding.updateLocations(script); |
| 216 } |
| 217 |
| 218 /** |
| 150 * @param {!SDK.Script} script | 219 * @param {!SDK.Script} script |
| 151 */ | 220 * @return {?SDK.SourceMap} |
| 152 addScript(script) { | |
| 153 if (script.sourceMapURL) | |
| 154 this._processScript(script); | |
| 155 } | |
| 156 | |
| 157 /** | |
| 158 * @param {!SDK.Script} script | |
| 159 * @return {?SDK.TextSourceMap} | |
| 160 */ | 221 */ |
| 161 sourceMapForScript(script) { | 222 sourceMapForScript(script) { |
| 162 return this._sourceMapForScriptId.get(script.scriptId) || null; | 223 return this._sourceMapManager.sourceMapForClient(script); |
| 163 } | 224 } |
| 164 | 225 |
| 165 /** | 226 /** |
| 166 * @param {!SDK.Script} script | 227 * @param {!SDK.Script} script |
| 167 */ | 228 */ |
| 168 maybeLoadSourceMap(script) { | 229 maybeLoadSourceMap(script) { |
| 169 if (!script.sourceMapURL) | 230 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 231 if (!sourceMap || this._scriptSources.has(script)) |
| 170 return; | 232 return; |
| 171 if (this._sourceMapLoadingPromises.has(script.sourceMapURL)) | 233 this._populateSourceMapSources(script, sourceMap); |
| 172 return; | |
| 173 if (this._sourceMapForScriptId.has(script.scriptId)) | |
| 174 return; | |
| 175 this._processScript(script); | |
| 176 } | 234 } |
| 177 | 235 |
| 178 /** | 236 /** |
| 179 * @param {!Common.Event} event | 237 * @param {?SDK.SourceMap} sourceMap |
| 180 */ | |
| 181 _sourceMapURLAdded(event) { | |
| 182 var script = /** @type {!SDK.Script} */ (event.data); | |
| 183 if (!script.sourceMapURL) | |
| 184 return; | |
| 185 this._processScript(script); | |
| 186 } | |
| 187 | |
| 188 /** | |
| 189 * @param {!SDK.Script} script | |
| 190 */ | |
| 191 _processScript(script) { | |
| 192 if (Bindings.blackboxManager.isBlackboxedURL(script.sourceURL, script.isCont
entScript())) | |
| 193 return; | |
| 194 // Create stub UISourceCode for the time source mapping is being loaded. | |
| 195 var stubUISourceCode = this._stubProject.addContentProvider( | |
| 196 script.sourceURL + ':sourcemap', | |
| 197 Common.StaticContentProvider.fromString( | |
| 198 script.sourceURL, Common.resourceTypes.Script, | |
| 199 '\n\n\n\n\n// Please wait a bit.\n// Compiled script is not shown wh
ile source map is being loaded!')); | |
| 200 this._stubUISourceCodes.set(script.scriptId, stubUISourceCode); | |
| 201 | |
| 202 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); | |
| 203 this._loadSourceMapForScript(script).then(sourceMap => { | |
| 204 this._sourceMapLoaded(script, stubUISourceCode.url(), sourceMap); | |
| 205 this._sourceMapAttachedForTest(sourceMap); | |
| 206 }); | |
| 207 } | |
| 208 | |
| 209 /** | |
| 210 * @param {?SDK.TextSourceMap} sourceMap | |
| 211 */ | 238 */ |
| 212 _sourceMapAttachedForTest(sourceMap) { | 239 _sourceMapAttachedForTest(sourceMap) { |
| 213 } | 240 } |
| 214 | 241 |
| 215 /** | 242 /** |
| 216 * @param {!SDK.Script} script | 243 * @param {!SDK.Script} script |
| 217 * @param {string} uiSourceCodePath | 244 * @param {!SDK.SourceMap} sourceMap |
| 218 * @param {?SDK.TextSourceMap} sourceMap | |
| 219 */ | 245 */ |
| 220 _sourceMapLoaded(script, uiSourceCodePath, sourceMap) { | 246 _populateSourceMapSources(script, sourceMap) { |
| 221 Bindings.blackboxManager.sourceMapLoaded(script, sourceMap); | |
| 222 | |
| 223 this._stubUISourceCodes.delete(script.scriptId); | |
| 224 this._stubProject.removeFile(uiSourceCodePath); | |
| 225 | |
| 226 if (!sourceMap) { | |
| 227 this._debuggerWorkspaceBinding.updateLocations(script); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 if (this._scriptForSourceMap.get(sourceMap)) { | |
| 232 this._sourceMapForScriptId.set(script.scriptId, sourceMap); | |
| 233 this._debuggerWorkspaceBinding.updateLocations(script); | |
| 234 return; | |
| 235 } | |
| 236 | |
| 237 this._sourceMapForScriptId.set(script.scriptId, sourceMap); | |
| 238 this._scriptForSourceMap.set(sourceMap, script); | |
| 239 | |
| 240 // Report sources. | |
| 241 var missingSources = []; | |
| 242 var executionContext = script.executionContext(); | 247 var executionContext = script.executionContext(); |
| 243 var frameId = executionContext ? executionContext.frameId || '' : ''; | 248 var frameId = executionContext ? executionContext.frameId || '' : ''; |
| 249 script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId; |
| 244 for (var sourceURL of sourceMap.sourceURLs()) { | 250 for (var sourceURL of sourceMap.sourceURLs()) { |
| 245 if (this._sourceMapForURL.get(sourceURL)) | 251 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.re
sourceTypes.SourceMapScript); |
| 246 continue; | 252 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); |
| 247 this._sourceMapForURL.set(sourceURL, sourceMap); | 253 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded
Content.length : null; |
| 248 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(this._
workspace, sourceURL, script); | 254 var uiSourceCode = this._networkProject.addSourceMapFile( |
| 249 if (!uiSourceCode) { | 255 contentProvider, frameId, script.isContentScript(), embeddedContentLen
gth); |
| 250 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.
resourceTypes.SourceMapScript); | 256 uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol] = script; |
| 251 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); | 257 this._scriptSources.set(script, uiSourceCode); |
| 252 var embeddedContentLength = typeof embeddedContent === 'string' ? embedd
edContent.length : null; | 258 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou
rceCode, this); |
| 253 uiSourceCode = this._networkProject.addSourceMapFile( | |
| 254 contentProvider, frameId, script.isContentScript(), embeddedContentL
ength); | |
| 255 uiSourceCode[Bindings.CompilerScriptMapping._originSymbol] = script.sour
ceURL; | |
| 256 } | |
| 257 if (uiSourceCode) { | |
| 258 this._bindUISourceCode(uiSourceCode); | |
| 259 } else { | |
| 260 if (missingSources.length < 3) | |
| 261 missingSources.push(sourceURL); | |
| 262 else if (missingSources.peekLast() !== '\u2026') | |
| 263 missingSources.push('\u2026'); | |
| 264 } | |
| 265 } | 259 } |
| 266 if (missingSources.length) { | |
| 267 Common.console.warn(Common.UIString( | |
| 268 'Source map %s points to the files missing from the workspace: [%s]',
sourceMap.url(), | |
| 269 missingSources.join(', '))); | |
| 270 } | |
| 271 | |
| 272 this._debuggerWorkspaceBinding.updateLocations(script); | 260 this._debuggerWorkspaceBinding.updateLocations(script); |
| 273 } | 261 } |
| 274 | 262 |
| 275 /** | 263 /** |
| 276 * @override | 264 * @override |
| 277 * @return {boolean} | 265 * @return {boolean} |
| 278 */ | 266 */ |
| 279 isIdentity() { | 267 isIdentity() { |
| 280 return false; | 268 return false; |
| 281 } | 269 } |
| 282 | 270 |
| 283 /** | 271 /** |
| 284 * @override | 272 * @override |
| 285 * @param {!Workspace.UISourceCode} uiSourceCode | 273 * @param {!Workspace.UISourceCode} uiSourceCode |
| 286 * @param {number} lineNumber | 274 * @param {number} lineNumber |
| 287 * @return {boolean} | 275 * @return {boolean} |
| 288 */ | 276 */ |
| 289 uiLineHasMapping(uiSourceCode, lineNumber) { | 277 uiLineHasMapping(uiSourceCode, lineNumber) { |
| 290 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); | 278 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; |
| 279 var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) :
null; |
| 291 if (!sourceMap) | 280 if (!sourceMap) |
| 292 return true; | 281 return true; |
| 293 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); | 282 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); |
| 294 } | 283 } |
| 295 | 284 |
| 296 /** | |
| 297 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 298 */ | |
| 299 _bindUISourceCode(uiSourceCode) { | |
| 300 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourc
eCode, this); | |
| 301 } | |
| 302 | |
| 303 /** | |
| 304 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 305 */ | |
| 306 _unbindUISourceCode(uiSourceCode) { | |
| 307 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourc
eCode, null); | |
| 308 } | |
| 309 | |
| 310 /** | |
| 311 * @param {!Common.Event} event | |
| 312 */ | |
| 313 _uiSourceCodeAddedToWorkspace(event) { | |
| 314 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | |
| 315 if (!this._sourceMapForURL.get(uiSourceCode.url())) | |
| 316 return; | |
| 317 this._bindUISourceCode(uiSourceCode); | |
| 318 } | |
| 319 | |
| 320 /** | |
| 321 * @param {!SDK.Script} script | |
| 322 * @return {!Promise<?SDK.TextSourceMap>} | |
| 323 */ | |
| 324 _loadSourceMapForScript(script) { | |
| 325 // script.sourceURL can be a random string, but is generally an absolute pat
h -> complete it to inspected page url for | |
| 326 // relative links. | |
| 327 var scriptURL = Common.ParsedURL.completeURL(this._debuggerModel.target().in
spectedURL(), script.sourceURL); | |
| 328 if (!scriptURL) | |
| 329 return Promise.resolve(/** @type {?SDK.TextSourceMap} */ (null)); | |
| 330 | |
| 331 console.assert(script.sourceMapURL); | |
| 332 var scriptSourceMapURL = /** @type {string} */ (script.sourceMapURL); | |
| 333 | |
| 334 var sourceMapURL = Common.ParsedURL.completeURL(scriptURL, scriptSourceMapUR
L); | |
| 335 if (!sourceMapURL) | |
| 336 return Promise.resolve(/** @type {?SDK.TextSourceMap} */ (null)); | |
| 337 | |
| 338 var loadingPromise = this._sourceMapLoadingPromises.get(sourceMapURL); | |
| 339 if (!loadingPromise) { | |
| 340 loadingPromise = SDK.TextSourceMap.load(sourceMapURL, scriptURL).then(sour
ceMapLoaded.bind(this, sourceMapURL)); | |
| 341 this._sourceMapLoadingPromises.set(sourceMapURL, loadingPromise); | |
| 342 } | |
| 343 return loadingPromise; | |
| 344 | |
| 345 /** | |
| 346 * @param {string} url | |
| 347 * @param {?SDK.TextSourceMap} sourceMap | |
| 348 * @this {Bindings.CompilerScriptMapping} | |
| 349 */ | |
| 350 function sourceMapLoaded(url, sourceMap) { | |
| 351 if (!sourceMap) { | |
| 352 this._sourceMapLoadingPromises.delete(url); | |
| 353 return null; | |
| 354 } | |
| 355 | |
| 356 return sourceMap; | |
| 357 } | |
| 358 } | |
| 359 | |
| 360 _debuggerReset() { | |
| 361 /** | |
| 362 * @param {!SDK.TextSourceMap} sourceMap | |
| 363 * @this {Bindings.CompilerScriptMapping} | |
| 364 */ | |
| 365 function unbindSourceMapSources(sourceMap) { | |
| 366 var script = this._scriptForSourceMap.get(sourceMap); | |
| 367 if (!script) | |
| 368 return; | |
| 369 for (var sourceURL of sourceMap.sourceURLs()) { | |
| 370 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(this
._workspace, sourceURL, script); | |
| 371 if (uiSourceCode) | |
| 372 this._unbindUISourceCode(uiSourceCode); | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 Array.from(new Set(this._sourceMapForURL.values())).forEach(unbindSourceMapS
ources.bind(this)); | |
| 377 | |
| 378 this._sourceMapLoadingPromises.clear(); | |
| 379 this._sourceMapForScriptId.clear(); | |
| 380 this._scriptForSourceMap.clear(); | |
| 381 this._sourceMapForURL.clear(); | |
| 382 } | |
| 383 | |
| 384 dispose() { | 285 dispose() { |
| 385 Common.EventTarget.removeEventListeners(this._eventListeners); | 286 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 386 this._debuggerReset(); | |
| 387 this._stubProject.dispose(); | 287 this._stubProject.dispose(); |
| 388 } | 288 } |
| 389 }; | 289 }; |
| 390 | 290 |
| 391 Bindings.CompilerScriptMapping._originSymbol = Symbol('origin'); | 291 Bindings.CompilerScriptMapping._scriptSymbol = Symbol('Bindings.CompilerScriptMa
pping._scriptSymbol'); |
| 292 Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptM
apping._frameIdSymbol'); |
| OLD | NEW |