| 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 {!Map.<!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 if (!script) |
| 113 return true; |
| 114 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 91 if (!sourceMap) | 115 if (!sourceMap) |
| 92 return true; | 116 return true; |
| 93 | |
| 94 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe
r); | 117 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe
r); |
| 95 } | 118 } |
| 96 | 119 |
| 97 /** | 120 /** |
| 98 * @override | 121 * @override |
| 99 * @param {!SDK.DebuggerModel.Location} rawLocation | 122 * @param {!SDK.DebuggerModel.Location} rawLocation |
| 100 * @return {?Workspace.UILocation} | 123 * @return {?Workspace.UILocation} |
| 101 */ | 124 */ |
| 102 rawLocationToUILocation(rawLocation) { | 125 rawLocationToUILocation(rawLocation) { |
| 103 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL
ocation); | 126 var script = rawLocation.script(); |
| 127 if (!script) |
| 128 return null; |
| 104 | 129 |
| 105 var stubUISourceCode = this._stubUISourceCodes.get(debuggerModelLocation.scr
iptId); | 130 var lineNumber = rawLocation.lineNumber; |
| 131 var columnNumber = rawLocation.columnNumber || 0; |
| 132 var stubUISourceCode = this._stubUISourceCodes.get(script); |
| 106 if (stubUISourceCode) | 133 if (stubUISourceCode) |
| 107 return new Workspace.UILocation(stubUISourceCode, rawLocation.lineNumber,
rawLocation.columnNumber); | 134 return new Workspace.UILocation(stubUISourceCode, lineNumber, columnNumber
); |
| 108 | 135 |
| 109 var sourceMap = this._sourceMapForScriptId.get(debuggerModelLocation.scriptI
d); | 136 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 110 if (!sourceMap) | 137 if (!sourceMap) |
| 111 return null; | 138 return null; |
| 112 var lineNumber = debuggerModelLocation.lineNumber; | |
| 113 var columnNumber = debuggerModelLocation.columnNumber || 0; | |
| 114 var entry = sourceMap.findEntry(lineNumber, columnNumber); | 139 var entry = sourceMap.findEntry(lineNumber, columnNumber); |
| 115 if (!entry || !entry.sourceURL) | 140 if (!entry || !entry.sourceURL) |
| 116 return null; | 141 return null; |
| 117 var script = rawLocation.script(); | |
| 118 if (!script) | |
| 119 return null; | |
| 120 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( | 142 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( |
| 121 this._workspace, /** @type {string} */ (entry.sourceURL), script); | 143 this._workspace, /** @type {string} */ (entry.sourceURL), script); |
| 122 if (!uiSourceCode) | 144 if (!uiSourceCode) |
| 123 return null; | 145 return null; |
| 124 return uiSourceCode.uiLocation( | 146 return uiSourceCode.uiLocation( |
| 125 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e
ntry.sourceColumnNumber)); | 147 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e
ntry.sourceColumnNumber)); |
| 126 } | 148 } |
| 127 | 149 |
| 128 /** | 150 /** |
| 129 * @override | 151 * @override |
| 130 * @param {!Workspace.UISourceCode} uiSourceCode | 152 * @param {!Workspace.UISourceCode} uiSourceCode |
| 131 * @param {number} lineNumber | 153 * @param {number} lineNumber |
| 132 * @param {number} columnNumber | 154 * @param {number} columnNumber |
| 133 * @return {?SDK.DebuggerModel.Location} | 155 * @return {?SDK.DebuggerModel.Location} |
| 134 */ | 156 */ |
| 135 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { | 157 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { |
| 136 if (uiSourceCode.project().type() === Workspace.projectTypes.Service) | 158 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; |
| 159 if (!script) |
| 137 return null; | 160 return null; |
| 138 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); | 161 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 139 if (!sourceMap) | 162 if (!sourceMap) |
| 140 return null; | 163 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)
; | 164 var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber)
; |
| 144 if (!entry) | 165 if (!entry) |
| 145 return null; | 166 return null; |
| 146 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry
.columnNumber); | 167 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry
.columnNumber); |
| 147 } | 168 } |
| 148 | 169 |
| 149 /** | 170 /** |
| 171 * @param {!Common.Event} event |
| 172 */ |
| 173 _sourceMapWillAttach(event) { |
| 174 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 175 // Create stub UISourceCode for the time source mapping is being loaded. |
| 176 this._addStubUISourceCode(script); |
| 177 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); |
| 178 } |
| 179 |
| 180 /** |
| 181 * @param {!Common.Event} event |
| 182 */ |
| 183 _sourceMapFailedToAttach(event) { |
| 184 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 185 this._removeStubUISourceCode(script); |
| 186 } |
| 187 |
| 188 /** |
| 189 * @param {!Common.Event} event |
| 190 */ |
| 191 _sourceMapAttached(event) { |
| 192 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 193 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); |
| 194 this._removeStubUISourceCode(script); |
| 195 |
| 196 if (Bindings.blackboxManager.isBlackboxedURL(script.sourceURL, script.isCont
entScript())) |
| 197 return; |
| 198 Bindings.blackboxManager.sourceMapLoaded(script, sourceMap); |
| 199 |
| 200 this._populateSourceMapSources(script, sourceMap); |
| 201 this._sourceMapAttachedForTest(sourceMap); |
| 202 } |
| 203 |
| 204 /** |
| 205 * @param {!Common.Event} event |
| 206 */ |
| 207 _sourceMapDetached(event) { |
| 208 var script = /** @type {!SDK.Script} */ (event.data.client); |
| 209 var sources = this._scriptSources.get(script); |
| 210 if (!sources.size) |
| 211 return; |
| 212 var frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol]; |
| 213 for (var uiSourceCode of sources) { |
| 214 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou
rceCode, null); |
| 215 this._networkProject.removeSourceMapFile(uiSourceCode.url(), frameId, scri
pt.isContentScript()); |
| 216 } |
| 217 this._debuggerWorkspaceBinding.updateLocations(script); |
| 218 } |
| 219 |
| 220 /** |
| 150 * @param {!SDK.Script} script | 221 * @param {!SDK.Script} script |
| 151 */ | 222 * @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 */ | 223 */ |
| 161 sourceMapForScript(script) { | 224 sourceMapForScript(script) { |
| 162 return this._sourceMapForScriptId.get(script.scriptId) || null; | 225 return this._sourceMapManager.sourceMapForClient(script); |
| 163 } | 226 } |
| 164 | 227 |
| 165 /** | 228 /** |
| 166 * @param {!SDK.Script} script | 229 * @param {!SDK.Script} script |
| 167 */ | 230 */ |
| 168 maybeLoadSourceMap(script) { | 231 maybeLoadSourceMap(script) { |
| 169 if (!script.sourceMapURL) | 232 //TODO: populate source map sources |
| 233 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 234 if (!sourceMap) |
| 170 return; | 235 return; |
| 171 if (this._sourceMapLoadingPromises.has(script.sourceMapURL)) | 236 this._populateSourceMapSources(script, sourceMap); |
| 172 return; | |
| 173 if (this._sourceMapForScriptId.has(script.scriptId)) | |
| 174 return; | |
| 175 this._processScript(script); | |
| 176 } | 237 } |
| 177 | 238 |
| 178 /** | 239 /** |
| 179 * @param {!Common.Event} event | |
| 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 | 240 * @param {?SDK.TextSourceMap} sourceMap |
| 211 */ | 241 */ |
| 212 _sourceMapAttachedForTest(sourceMap) { | 242 _sourceMapAttachedForTest(sourceMap) { |
| 213 } | 243 } |
| 214 | 244 |
| 215 /** | 245 /** |
| 216 * @param {!SDK.Script} script | 246 * @param {!SDK.Script} script |
| 217 * @param {string} uiSourceCodePath | 247 * @param {!SDK.TextSourceMap} sourceMap |
| 218 * @param {?SDK.TextSourceMap} sourceMap | |
| 219 */ | 248 */ |
| 220 _sourceMapLoaded(script, uiSourceCodePath, sourceMap) { | 249 _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(); | 250 var executionContext = script.executionContext(); |
| 243 var frameId = executionContext ? executionContext.frameId || '' : ''; | 251 var frameId = executionContext ? executionContext.frameId || '' : ''; |
| 252 script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId; |
| 244 for (var sourceURL of sourceMap.sourceURLs()) { | 253 for (var sourceURL of sourceMap.sourceURLs()) { |
| 245 if (this._sourceMapForURL.get(sourceURL)) | 254 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.re
sourceTypes.SourceMapScript); |
| 246 continue; | 255 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); |
| 247 this._sourceMapForURL.set(sourceURL, sourceMap); | 256 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded
Content.length : null; |
| 248 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(this._
workspace, sourceURL, script); | 257 var uiSourceCode = this._networkProject.addSourceMapFile( |
| 249 if (!uiSourceCode) { | 258 contentProvider, frameId, script.isContentScript(), embeddedContentLen
gth); |
| 250 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.
resourceTypes.SourceMapScript); | 259 uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol] = script; |
| 251 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); | 260 this._scriptSources.set(script, uiSourceCode); |
| 252 var embeddedContentLength = typeof embeddedContent === 'string' ? embedd
edContent.length : null; | 261 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 } | 262 } |
| 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); | 263 this._debuggerWorkspaceBinding.updateLocations(script); |
| 273 } | 264 } |
| 274 | 265 |
| 275 /** | 266 /** |
| 276 * @override | 267 * @override |
| 277 * @return {boolean} | 268 * @return {boolean} |
| 278 */ | 269 */ |
| 279 isIdentity() { | 270 isIdentity() { |
| 280 return false; | 271 return false; |
| 281 } | 272 } |
| 282 | 273 |
| 283 /** | 274 /** |
| 284 * @override | 275 * @override |
| 285 * @param {!Workspace.UISourceCode} uiSourceCode | 276 * @param {!Workspace.UISourceCode} uiSourceCode |
| 286 * @param {number} lineNumber | 277 * @param {number} lineNumber |
| 287 * @return {boolean} | 278 * @return {boolean} |
| 288 */ | 279 */ |
| 289 uiLineHasMapping(uiSourceCode, lineNumber) { | 280 uiLineHasMapping(uiSourceCode, lineNumber) { |
| 290 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url()); | 281 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; |
| 282 var sourceMap = this._sourceMapManager.sourceMapForClient(script); |
| 291 if (!sourceMap) | 283 if (!sourceMap) |
| 292 return true; | 284 return true; |
| 293 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); | 285 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); |
| 294 } | 286 } |
| 295 | 287 |
| 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() { | 288 dispose() { |
| 385 Common.EventTarget.removeEventListeners(this._eventListeners); | 289 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 386 this._debuggerReset(); | |
| 387 this._stubProject.dispose(); | 290 this._stubProject.dispose(); |
| 388 } | 291 } |
| 389 }; | 292 }; |
| 390 | 293 |
| 391 Bindings.CompilerScriptMapping._originSymbol = Symbol('origin'); | 294 Bindings.CompilerScriptMapping._scriptSymbol = Symbol('Bindings.CompilerScriptMa
pping._scriptSymbol'); |
| 295 Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptM
apping._frameIdSymbol'); |
| OLD | NEW |