| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 SourceMapV3.Offset = class { | 59 SourceMapV3.Offset = class { |
| 60 constructor() { | 60 constructor() { |
| 61 /** @type {number} */ this.line; | 61 /** @type {number} */ this.line; |
| 62 /** @type {number} */ this.column; | 62 /** @type {number} */ this.column; |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @unrestricted | 67 * @unrestricted |
| 68 */ | 68 */ |
| 69 WebInspector.SourceMapEntry = class { | 69 SDK.SourceMapEntry = class { |
| 70 /** | 70 /** |
| 71 * @param {number} lineNumber | 71 * @param {number} lineNumber |
| 72 * @param {number} columnNumber | 72 * @param {number} columnNumber |
| 73 * @param {string=} sourceURL | 73 * @param {string=} sourceURL |
| 74 * @param {number=} sourceLineNumber | 74 * @param {number=} sourceLineNumber |
| 75 * @param {number=} sourceColumnNumber | 75 * @param {number=} sourceColumnNumber |
| 76 * @param {string=} name | 76 * @param {string=} name |
| 77 */ | 77 */ |
| 78 constructor(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColum
nNumber, name) { | 78 constructor(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColum
nNumber, name) { |
| 79 this.lineNumber = lineNumber; | 79 this.lineNumber = lineNumber; |
| 80 this.columnNumber = columnNumber; | 80 this.columnNumber = columnNumber; |
| 81 this.sourceURL = sourceURL; | 81 this.sourceURL = sourceURL; |
| 82 this.sourceLineNumber = sourceLineNumber; | 82 this.sourceLineNumber = sourceLineNumber; |
| 83 this.sourceColumnNumber = sourceColumnNumber; | 83 this.sourceColumnNumber = sourceColumnNumber; |
| 84 this.name = name; | 84 this.name = name; |
| 85 } | 85 } |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * @interface | 89 * @interface |
| 90 */ | 90 */ |
| 91 WebInspector.SourceMap = function() {}; | 91 SDK.SourceMap = function() {}; |
| 92 | 92 |
| 93 WebInspector.SourceMap.prototype = { | 93 SDK.SourceMap.prototype = { |
| 94 /** | 94 /** |
| 95 * @return {string} | 95 * @return {string} |
| 96 */ | 96 */ |
| 97 compiledURL: function() {}, | 97 compiledURL: function() {}, |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * @return {string} | 100 * @return {string} |
| 101 */ | 101 */ |
| 102 url: function() {}, | 102 url: function() {}, |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * @return {!Array<string>} | 105 * @return {!Array<string>} |
| 106 */ | 106 */ |
| 107 sourceURLs: function() {}, | 107 sourceURLs: function() {}, |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * @param {string} sourceURL | 110 * @param {string} sourceURL |
| 111 * @param {!WebInspector.ResourceType} contentType | 111 * @param {!Common.ResourceType} contentType |
| 112 * @return {!WebInspector.ContentProvider} | 112 * @return {!Common.ContentProvider} |
| 113 */ | 113 */ |
| 114 sourceContentProvider: function(sourceURL, contentType) {}, | 114 sourceContentProvider: function(sourceURL, contentType) {}, |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * @param {string} sourceURL | 117 * @param {string} sourceURL |
| 118 * @return {?string} | 118 * @return {?string} |
| 119 */ | 119 */ |
| 120 embeddedContentByURL: function(sourceURL) {}, | 120 embeddedContentByURL: function(sourceURL) {}, |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * @param {number} lineNumber in compiled resource | 123 * @param {number} lineNumber in compiled resource |
| 124 * @param {number} columnNumber in compiled resource | 124 * @param {number} columnNumber in compiled resource |
| 125 * @return {?WebInspector.SourceMapEntry} | 125 * @return {?SDK.SourceMapEntry} |
| 126 */ | 126 */ |
| 127 findEntry: function(lineNumber, columnNumber) {}, | 127 findEntry: function(lineNumber, columnNumber) {}, |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @return {boolean} | 130 * @return {boolean} |
| 131 */ | 131 */ |
| 132 editable: function() {}, | 132 editable: function() {}, |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * @param {!Array<!WebInspector.TextRange>} ranges | 135 * @param {!Array<!Common.TextRange>} ranges |
| 136 * @param {!Array<string>} texts | 136 * @param {!Array<string>} texts |
| 137 * @return {!Promise<?WebInspector.SourceMap.EditResult>} | 137 * @return {!Promise<?SDK.SourceMap.EditResult>} |
| 138 */ | 138 */ |
| 139 editCompiled: function(ranges, texts) {}, | 139 editCompiled: function(ranges, texts) {}, |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @unrestricted | 143 * @unrestricted |
| 144 */ | 144 */ |
| 145 WebInspector.SourceMap.EditResult = class { | 145 SDK.SourceMap.EditResult = class { |
| 146 /** | 146 /** |
| 147 * @param {!WebInspector.SourceMap} map | 147 * @param {!SDK.SourceMap} map |
| 148 * @param {!Array<!WebInspector.SourceEdit>} compiledEdits | 148 * @param {!Array<!Common.SourceEdit>} compiledEdits |
| 149 * @param {!Map<string, string>} newSources | 149 * @param {!Map<string, string>} newSources |
| 150 */ | 150 */ |
| 151 constructor(map, compiledEdits, newSources) { | 151 constructor(map, compiledEdits, newSources) { |
| 152 this.map = map; | 152 this.map = map; |
| 153 this.compiledEdits = compiledEdits; | 153 this.compiledEdits = compiledEdits; |
| 154 this.newSources = newSources; | 154 this.newSources = newSources; |
| 155 } | 155 } |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 /** | 158 /** |
| 159 * @interface | 159 * @interface |
| 160 */ | 160 */ |
| 161 WebInspector.SourceMapFactory = function() {}; | 161 SDK.SourceMapFactory = function() {}; |
| 162 | 162 |
| 163 WebInspector.SourceMapFactory.prototype = { | 163 SDK.SourceMapFactory.prototype = { |
| 164 /** | 164 /** |
| 165 * @param {!WebInspector.Target} target | 165 * @param {!SDK.Target} target |
| 166 * @param {!WebInspector.SourceMap} sourceMap | 166 * @param {!SDK.SourceMap} sourceMap |
| 167 * @return {!Promise<?WebInspector.SourceMap>} | 167 * @return {!Promise<?SDK.SourceMap>} |
| 168 */ | 168 */ |
| 169 editableSourceMap: function(target, sourceMap) {}, | 169 editableSourceMap: function(target, sourceMap) {}, |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * @implements {WebInspector.SourceMap} | 173 * @implements {SDK.SourceMap} |
| 174 * @unrestricted | 174 * @unrestricted |
| 175 */ | 175 */ |
| 176 WebInspector.TextSourceMap = class { | 176 SDK.TextSourceMap = class { |
| 177 /** | 177 /** |
| 178 * Implements Source Map V3 model. See https://github.com/google/closure-compi
ler/wiki/Source-Maps | 178 * Implements Source Map V3 model. See https://github.com/google/closure-compi
ler/wiki/Source-Maps |
| 179 * for format description. | 179 * for format description. |
| 180 * @param {string} compiledURL | 180 * @param {string} compiledURL |
| 181 * @param {string} sourceMappingURL | 181 * @param {string} sourceMappingURL |
| 182 * @param {!SourceMapV3} payload | 182 * @param {!SourceMapV3} payload |
| 183 */ | 183 */ |
| 184 constructor(compiledURL, sourceMappingURL, payload) { | 184 constructor(compiledURL, sourceMappingURL, payload) { |
| 185 if (!WebInspector.TextSourceMap._base64Map) { | 185 if (!SDK.TextSourceMap._base64Map) { |
| 186 const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
0123456789+/'; | 186 const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
0123456789+/'; |
| 187 WebInspector.TextSourceMap._base64Map = {}; | 187 SDK.TextSourceMap._base64Map = {}; |
| 188 for (var i = 0; i < base64Digits.length; ++i) | 188 for (var i = 0; i < base64Digits.length; ++i) |
| 189 WebInspector.TextSourceMap._base64Map[base64Digits.charAt(i)] = i; | 189 SDK.TextSourceMap._base64Map[base64Digits.charAt(i)] = i; |
| 190 } | 190 } |
| 191 | 191 |
| 192 this._json = payload; | 192 this._json = payload; |
| 193 this._compiledURL = compiledURL; | 193 this._compiledURL = compiledURL; |
| 194 this._sourceMappingURL = sourceMappingURL; | 194 this._sourceMappingURL = sourceMappingURL; |
| 195 /** @type {?Array<!WebInspector.SourceMapEntry>} */ | 195 /** @type {?Array<!SDK.SourceMapEntry>} */ |
| 196 this._mappings = null; | 196 this._mappings = null; |
| 197 /** @type {!Map<string, !WebInspector.TextSourceMap.SourceInfo>} */ | 197 /** @type {!Map<string, !SDK.TextSourceMap.SourceInfo>} */ |
| 198 this._sourceInfos = new Map(); | 198 this._sourceInfos = new Map(); |
| 199 this._eachSection(this._parseSources.bind(this)); | 199 this._eachSection(this._parseSources.bind(this)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 /** | 202 /** |
| 203 * @param {string} sourceMapURL | 203 * @param {string} sourceMapURL |
| 204 * @param {string} compiledURL | 204 * @param {string} compiledURL |
| 205 * @return {!Promise<?WebInspector.TextSourceMap>} | 205 * @return {!Promise<?SDK.TextSourceMap>} |
| 206 * @this {WebInspector.TextSourceMap} | 206 * @this {SDK.TextSourceMap} |
| 207 */ | 207 */ |
| 208 static load(sourceMapURL, compiledURL) { | 208 static load(sourceMapURL, compiledURL) { |
| 209 var callback; | 209 var callback; |
| 210 var promise = new Promise(fulfill => callback = fulfill); | 210 var promise = new Promise(fulfill => callback = fulfill); |
| 211 WebInspector.multitargetNetworkManager.loadResource(sourceMapURL, contentLoa
ded); | 211 SDK.multitargetNetworkManager.loadResource(sourceMapURL, contentLoaded); |
| 212 return promise; | 212 return promise; |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * @param {number} statusCode | 215 * @param {number} statusCode |
| 216 * @param {!Object.<string, string>} headers | 216 * @param {!Object.<string, string>} headers |
| 217 * @param {string} content | 217 * @param {string} content |
| 218 */ | 218 */ |
| 219 function contentLoaded(statusCode, headers, content) { | 219 function contentLoaded(statusCode, headers, content) { |
| 220 if (!content || statusCode >= 400) { | 220 if (!content || statusCode >= 400) { |
| 221 callback(null); | 221 callback(null); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 if (content.slice(0, 3) === ')]}') | 225 if (content.slice(0, 3) === ')]}') |
| 226 content = content.substring(content.indexOf('\n')); | 226 content = content.substring(content.indexOf('\n')); |
| 227 try { | 227 try { |
| 228 var payload = /** @type {!SourceMapV3} */ (JSON.parse(content)); | 228 var payload = /** @type {!SourceMapV3} */ (JSON.parse(content)); |
| 229 var baseURL = sourceMapURL.startsWith('data:') ? compiledURL : sourceMap
URL; | 229 var baseURL = sourceMapURL.startsWith('data:') ? compiledURL : sourceMap
URL; |
| 230 callback(new WebInspector.TextSourceMap(compiledURL, baseURL, payload)); | 230 callback(new SDK.TextSourceMap(compiledURL, baseURL, payload)); |
| 231 } catch (e) { | 231 } catch (e) { |
| 232 console.error(e); | 232 console.error(e); |
| 233 WebInspector.console.warn('DevTools failed to parse SourceMap: ' + sourc
eMapURL); | 233 Common.console.warn('DevTools failed to parse SourceMap: ' + sourceMapUR
L); |
| 234 callback(null); | 234 callback(null); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 /** | 239 /** |
| 240 * @override | 240 * @override |
| 241 * @return {string} | 241 * @return {string} |
| 242 */ | 242 */ |
| 243 compiledURL() { | 243 compiledURL() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 256 * @override | 256 * @override |
| 257 * @return {!Array.<string>} | 257 * @return {!Array.<string>} |
| 258 */ | 258 */ |
| 259 sourceURLs() { | 259 sourceURLs() { |
| 260 return this._sourceInfos.keysArray(); | 260 return this._sourceInfos.keysArray(); |
| 261 } | 261 } |
| 262 | 262 |
| 263 /** | 263 /** |
| 264 * @override | 264 * @override |
| 265 * @param {string} sourceURL | 265 * @param {string} sourceURL |
| 266 * @param {!WebInspector.ResourceType} contentType | 266 * @param {!Common.ResourceType} contentType |
| 267 * @return {!WebInspector.ContentProvider} | 267 * @return {!Common.ContentProvider} |
| 268 */ | 268 */ |
| 269 sourceContentProvider(sourceURL, contentType) { | 269 sourceContentProvider(sourceURL, contentType) { |
| 270 var info = this._sourceInfos.get(sourceURL); | 270 var info = this._sourceInfos.get(sourceURL); |
| 271 if (info.content) | 271 if (info.content) |
| 272 return WebInspector.StaticContentProvider.fromString(sourceURL, contentTyp
e, info.content); | 272 return Common.StaticContentProvider.fromString(sourceURL, contentType, inf
o.content); |
| 273 return new WebInspector.CompilerSourceMappingContentProvider(sourceURL, cont
entType); | 273 return new SDK.CompilerSourceMappingContentProvider(sourceURL, contentType); |
| 274 } | 274 } |
| 275 | 275 |
| 276 /** | 276 /** |
| 277 * @override | 277 * @override |
| 278 * @param {string} sourceURL | 278 * @param {string} sourceURL |
| 279 * @return {?string} | 279 * @return {?string} |
| 280 */ | 280 */ |
| 281 embeddedContentByURL(sourceURL) { | 281 embeddedContentByURL(sourceURL) { |
| 282 if (!this._sourceInfos.has(sourceURL)) | 282 if (!this._sourceInfos.has(sourceURL)) |
| 283 return null; | 283 return null; |
| 284 return this._sourceInfos.get(sourceURL).content; | 284 return this._sourceInfos.get(sourceURL).content; |
| 285 } | 285 } |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * @override | 288 * @override |
| 289 * @return {boolean} | 289 * @return {boolean} |
| 290 */ | 290 */ |
| 291 editable() { | 291 editable() { |
| 292 return false; | 292 return false; |
| 293 } | 293 } |
| 294 | 294 |
| 295 /** | 295 /** |
| 296 * @override | 296 * @override |
| 297 * @param {!Array<!WebInspector.TextRange>} ranges | 297 * @param {!Array<!Common.TextRange>} ranges |
| 298 * @param {!Array<string>} texts | 298 * @param {!Array<string>} texts |
| 299 * @return {!Promise<?WebInspector.SourceMap.EditResult>} | 299 * @return {!Promise<?SDK.SourceMap.EditResult>} |
| 300 */ | 300 */ |
| 301 editCompiled(ranges, texts) { | 301 editCompiled(ranges, texts) { |
| 302 return Promise.resolve(/** @type {?WebInspector.SourceMap.EditResult} */ (nu
ll)); | 302 return Promise.resolve(/** @type {?SDK.SourceMap.EditResult} */ (null)); |
| 303 } | 303 } |
| 304 | 304 |
| 305 /** | 305 /** |
| 306 * @override | 306 * @override |
| 307 * @param {number} lineNumber in compiled resource | 307 * @param {number} lineNumber in compiled resource |
| 308 * @param {number} columnNumber in compiled resource | 308 * @param {number} columnNumber in compiled resource |
| 309 * @return {?WebInspector.SourceMapEntry} | 309 * @return {?SDK.SourceMapEntry} |
| 310 */ | 310 */ |
| 311 findEntry(lineNumber, columnNumber) { | 311 findEntry(lineNumber, columnNumber) { |
| 312 var first = 0; | 312 var first = 0; |
| 313 var mappings = this.mappings(); | 313 var mappings = this.mappings(); |
| 314 var count = mappings.length; | 314 var count = mappings.length; |
| 315 while (count > 1) { | 315 while (count > 1) { |
| 316 var step = count >> 1; | 316 var step = count >> 1; |
| 317 var middle = first + step; | 317 var middle = first + step; |
| 318 var mapping = mappings[middle]; | 318 var mapping = mappings[middle]; |
| 319 if (lineNumber < mapping.lineNumber || | 319 if (lineNumber < mapping.lineNumber || |
| 320 (lineNumber === mapping.lineNumber && columnNumber < mapping.columnNum
ber)) { | 320 (lineNumber === mapping.lineNumber && columnNumber < mapping.columnNum
ber)) { |
| 321 count = step; | 321 count = step; |
| 322 } else { | 322 } else { |
| 323 first = middle; | 323 first = middle; |
| 324 count -= step; | 324 count -= step; |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 var entry = mappings[first]; | 327 var entry = mappings[first]; |
| 328 if (!first && entry && | 328 if (!first && entry && |
| 329 (lineNumber < entry.lineNumber || (lineNumber === entry.lineNumber && co
lumnNumber < entry.columnNumber))) | 329 (lineNumber < entry.lineNumber || (lineNumber === entry.lineNumber && co
lumnNumber < entry.columnNumber))) |
| 330 return null; | 330 return null; |
| 331 return entry; | 331 return entry; |
| 332 } | 332 } |
| 333 | 333 |
| 334 /** | 334 /** |
| 335 * @param {string} sourceURL | 335 * @param {string} sourceURL |
| 336 * @param {number} lineNumber | 336 * @param {number} lineNumber |
| 337 * @return {?WebInspector.SourceMapEntry} | 337 * @return {?SDK.SourceMapEntry} |
| 338 */ | 338 */ |
| 339 firstSourceLineMapping(sourceURL, lineNumber) { | 339 firstSourceLineMapping(sourceURL, lineNumber) { |
| 340 var mappings = this._reversedMappings(sourceURL); | 340 var mappings = this._reversedMappings(sourceURL); |
| 341 var index = mappings.lowerBound(lineNumber, lineComparator); | 341 var index = mappings.lowerBound(lineNumber, lineComparator); |
| 342 if (index >= mappings.length || mappings[index].sourceLineNumber !== lineNum
ber) | 342 if (index >= mappings.length || mappings[index].sourceLineNumber !== lineNum
ber) |
| 343 return null; | 343 return null; |
| 344 return mappings[index]; | 344 return mappings[index]; |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * @param {number} lineNumber | 347 * @param {number} lineNumber |
| 348 * @param {!WebInspector.SourceMapEntry} mapping | 348 * @param {!SDK.SourceMapEntry} mapping |
| 349 * @return {number} | 349 * @return {number} |
| 350 */ | 350 */ |
| 351 function lineComparator(lineNumber, mapping) { | 351 function lineComparator(lineNumber, mapping) { |
| 352 return lineNumber - mapping.sourceLineNumber; | 352 return lineNumber - mapping.sourceLineNumber; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 /** | 356 /** |
| 357 * @return {!Array<!WebInspector.SourceMapEntry>} | 357 * @return {!Array<!SDK.SourceMapEntry>} |
| 358 */ | 358 */ |
| 359 mappings() { | 359 mappings() { |
| 360 if (this._mappings === null) { | 360 if (this._mappings === null) { |
| 361 this._mappings = []; | 361 this._mappings = []; |
| 362 this._eachSection(this._parseMap.bind(this)); | 362 this._eachSection(this._parseMap.bind(this)); |
| 363 this._json = null; | 363 this._json = null; |
| 364 } | 364 } |
| 365 return /** @type {!Array<!WebInspector.SourceMapEntry>} */ (this._mappings); | 365 return /** @type {!Array<!SDK.SourceMapEntry>} */ (this._mappings); |
| 366 } | 366 } |
| 367 | 367 |
| 368 /** | 368 /** |
| 369 * @param {string} sourceURL | 369 * @param {string} sourceURL |
| 370 * @return {!Array.<!WebInspector.SourceMapEntry>} | 370 * @return {!Array.<!SDK.SourceMapEntry>} |
| 371 */ | 371 */ |
| 372 _reversedMappings(sourceURL) { | 372 _reversedMappings(sourceURL) { |
| 373 if (!this._sourceInfos.has(sourceURL)) | 373 if (!this._sourceInfos.has(sourceURL)) |
| 374 return []; | 374 return []; |
| 375 var mappings = this.mappings(); | 375 var mappings = this.mappings(); |
| 376 var info = this._sourceInfos.get(sourceURL); | 376 var info = this._sourceInfos.get(sourceURL); |
| 377 if (info.reverseMappings === null) | 377 if (info.reverseMappings === null) |
| 378 info.reverseMappings = | 378 info.reverseMappings = |
| 379 mappings.filter((mapping) => mapping.sourceURL === sourceURL).sort(sou
rceMappingComparator); | 379 mappings.filter((mapping) => mapping.sourceURL === sourceURL).sort(sou
rceMappingComparator); |
| 380 return info.reverseMappings; | 380 return info.reverseMappings; |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * @param {!WebInspector.SourceMapEntry} a | 383 * @param {!SDK.SourceMapEntry} a |
| 384 * @param {!WebInspector.SourceMapEntry} b | 384 * @param {!SDK.SourceMapEntry} b |
| 385 * @return {number} | 385 * @return {number} |
| 386 */ | 386 */ |
| 387 function sourceMappingComparator(a, b) { | 387 function sourceMappingComparator(a, b) { |
| 388 if (a.sourceLineNumber !== b.sourceLineNumber) | 388 if (a.sourceLineNumber !== b.sourceLineNumber) |
| 389 return a.sourceLineNumber - b.sourceLineNumber; | 389 return a.sourceLineNumber - b.sourceLineNumber; |
| 390 if (a.sourceColumnNumber !== b.sourceColumnNumber) | 390 if (a.sourceColumnNumber !== b.sourceColumnNumber) |
| 391 return a.sourceColumnNumber - b.sourceColumnNumber; | 391 return a.sourceColumnNumber - b.sourceColumnNumber; |
| 392 | 392 |
| 393 if (a.lineNumber !== b.lineNumber) | 393 if (a.lineNumber !== b.lineNumber) |
| 394 return a.lineNumber - b.lineNumber; | 394 return a.lineNumber - b.lineNumber; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 412 /** | 412 /** |
| 413 * @param {!SourceMapV3} sourceMap | 413 * @param {!SourceMapV3} sourceMap |
| 414 */ | 414 */ |
| 415 _parseSources(sourceMap) { | 415 _parseSources(sourceMap) { |
| 416 var sourcesList = []; | 416 var sourcesList = []; |
| 417 var sourceRoot = sourceMap.sourceRoot || ''; | 417 var sourceRoot = sourceMap.sourceRoot || ''; |
| 418 if (sourceRoot && !sourceRoot.endsWith('/')) | 418 if (sourceRoot && !sourceRoot.endsWith('/')) |
| 419 sourceRoot += '/'; | 419 sourceRoot += '/'; |
| 420 for (var i = 0; i < sourceMap.sources.length; ++i) { | 420 for (var i = 0; i < sourceMap.sources.length; ++i) { |
| 421 var href = sourceRoot + sourceMap.sources[i]; | 421 var href = sourceRoot + sourceMap.sources[i]; |
| 422 var url = WebInspector.ParsedURL.completeURL(this._sourceMappingURL, href)
|| href; | 422 var url = Common.ParsedURL.completeURL(this._sourceMappingURL, href) || hr
ef; |
| 423 var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i]; | 423 var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i]; |
| 424 if (url === this._compiledURL && source) | 424 if (url === this._compiledURL && source) |
| 425 url += WebInspector.UIString(' [sm]'); | 425 url += Common.UIString(' [sm]'); |
| 426 this._sourceInfos.set(url, new WebInspector.TextSourceMap.SourceInfo(sourc
e, null)); | 426 this._sourceInfos.set(url, new SDK.TextSourceMap.SourceInfo(source, null))
; |
| 427 sourcesList.push(url); | 427 sourcesList.push(url); |
| 428 } | 428 } |
| 429 sourceMap[WebInspector.TextSourceMap._sourcesListSymbol] = sourcesList; | 429 sourceMap[SDK.TextSourceMap._sourcesListSymbol] = sourcesList; |
| 430 } | 430 } |
| 431 | 431 |
| 432 /** | 432 /** |
| 433 * @param {!SourceMapV3} map | 433 * @param {!SourceMapV3} map |
| 434 * @param {number} lineNumber | 434 * @param {number} lineNumber |
| 435 * @param {number} columnNumber | 435 * @param {number} columnNumber |
| 436 */ | 436 */ |
| 437 _parseMap(map, lineNumber, columnNumber) { | 437 _parseMap(map, lineNumber, columnNumber) { |
| 438 var sourceIndex = 0; | 438 var sourceIndex = 0; |
| 439 var sourceLineNumber = 0; | 439 var sourceLineNumber = 0; |
| 440 var sourceColumnNumber = 0; | 440 var sourceColumnNumber = 0; |
| 441 var nameIndex = 0; | 441 var nameIndex = 0; |
| 442 var sources = map[WebInspector.TextSourceMap._sourcesListSymbol]; | 442 var sources = map[SDK.TextSourceMap._sourcesListSymbol]; |
| 443 var names = map.names || []; | 443 var names = map.names || []; |
| 444 var stringCharIterator = new WebInspector.TextSourceMap.StringCharIterator(m
ap.mappings); | 444 var stringCharIterator = new SDK.TextSourceMap.StringCharIterator(map.mappin
gs); |
| 445 var sourceURL = sources[sourceIndex]; | 445 var sourceURL = sources[sourceIndex]; |
| 446 | 446 |
| 447 while (true) { | 447 while (true) { |
| 448 if (stringCharIterator.peek() === ',') | 448 if (stringCharIterator.peek() === ',') |
| 449 stringCharIterator.next(); | 449 stringCharIterator.next(); |
| 450 else { | 450 else { |
| 451 while (stringCharIterator.peek() === ';') { | 451 while (stringCharIterator.peek() === ';') { |
| 452 lineNumber += 1; | 452 lineNumber += 1; |
| 453 columnNumber = 0; | 453 columnNumber = 0; |
| 454 stringCharIterator.next(); | 454 stringCharIterator.next(); |
| 455 } | 455 } |
| 456 if (!stringCharIterator.hasNext()) | 456 if (!stringCharIterator.hasNext()) |
| 457 break; | 457 break; |
| 458 } | 458 } |
| 459 | 459 |
| 460 columnNumber += this._decodeVLQ(stringCharIterator); | 460 columnNumber += this._decodeVLQ(stringCharIterator); |
| 461 if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.
peek())) { | 461 if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.
peek())) { |
| 462 this._mappings.push(new WebInspector.SourceMapEntry(lineNumber, columnNu
mber)); | 462 this._mappings.push(new SDK.SourceMapEntry(lineNumber, columnNumber)); |
| 463 continue; | 463 continue; |
| 464 } | 464 } |
| 465 | 465 |
| 466 var sourceIndexDelta = this._decodeVLQ(stringCharIterator); | 466 var sourceIndexDelta = this._decodeVLQ(stringCharIterator); |
| 467 if (sourceIndexDelta) { | 467 if (sourceIndexDelta) { |
| 468 sourceIndex += sourceIndexDelta; | 468 sourceIndex += sourceIndexDelta; |
| 469 sourceURL = sources[sourceIndex]; | 469 sourceURL = sources[sourceIndex]; |
| 470 } | 470 } |
| 471 sourceLineNumber += this._decodeVLQ(stringCharIterator); | 471 sourceLineNumber += this._decodeVLQ(stringCharIterator); |
| 472 sourceColumnNumber += this._decodeVLQ(stringCharIterator); | 472 sourceColumnNumber += this._decodeVLQ(stringCharIterator); |
| 473 | 473 |
| 474 if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.
peek())) { | 474 if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.
peek())) { |
| 475 this._mappings.push( | 475 this._mappings.push( |
| 476 new WebInspector.SourceMapEntry(lineNumber, columnNumber, sourceURL,
sourceLineNumber, sourceColumnNumber)); | 476 new SDK.SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLi
neNumber, sourceColumnNumber)); |
| 477 continue; | 477 continue; |
| 478 } | 478 } |
| 479 | 479 |
| 480 nameIndex += this._decodeVLQ(stringCharIterator); | 480 nameIndex += this._decodeVLQ(stringCharIterator); |
| 481 this._mappings.push(new WebInspector.SourceMapEntry( | 481 this._mappings.push(new SDK.SourceMapEntry( |
| 482 lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNum
ber, names[nameIndex])); | 482 lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNum
ber, names[nameIndex])); |
| 483 } | 483 } |
| 484 } | 484 } |
| 485 | 485 |
| 486 /** | 486 /** |
| 487 * @param {string} char | 487 * @param {string} char |
| 488 * @return {boolean} | 488 * @return {boolean} |
| 489 */ | 489 */ |
| 490 _isSeparator(char) { | 490 _isSeparator(char) { |
| 491 return char === ',' || char === ';'; | 491 return char === ',' || char === ';'; |
| 492 } | 492 } |
| 493 | 493 |
| 494 /** | 494 /** |
| 495 * @param {!WebInspector.TextSourceMap.StringCharIterator} stringCharIterator | 495 * @param {!SDK.TextSourceMap.StringCharIterator} stringCharIterator |
| 496 * @return {number} | 496 * @return {number} |
| 497 */ | 497 */ |
| 498 _decodeVLQ(stringCharIterator) { | 498 _decodeVLQ(stringCharIterator) { |
| 499 // Read unsigned value. | 499 // Read unsigned value. |
| 500 var result = 0; | 500 var result = 0; |
| 501 var shift = 0; | 501 var shift = 0; |
| 502 do { | 502 do { |
| 503 var digit = WebInspector.TextSourceMap._base64Map[stringCharIterator.next(
)]; | 503 var digit = SDK.TextSourceMap._base64Map[stringCharIterator.next()]; |
| 504 result += (digit & WebInspector.TextSourceMap._VLQ_BASE_MASK) << shift; | 504 result += (digit & SDK.TextSourceMap._VLQ_BASE_MASK) << shift; |
| 505 shift += WebInspector.TextSourceMap._VLQ_BASE_SHIFT; | 505 shift += SDK.TextSourceMap._VLQ_BASE_SHIFT; |
| 506 } while (digit & WebInspector.TextSourceMap._VLQ_CONTINUATION_MASK); | 506 } while (digit & SDK.TextSourceMap._VLQ_CONTINUATION_MASK); |
| 507 | 507 |
| 508 // Fix the sign. | 508 // Fix the sign. |
| 509 var negative = result & 1; | 509 var negative = result & 1; |
| 510 result >>= 1; | 510 result >>= 1; |
| 511 return negative ? -result : result; | 511 return negative ? -result : result; |
| 512 } | 512 } |
| 513 | 513 |
| 514 /** | 514 /** |
| 515 * @param {string} url | 515 * @param {string} url |
| 516 * @param {!WebInspector.TextRange} textRange | 516 * @param {!Common.TextRange} textRange |
| 517 * @return {!WebInspector.TextRange} | 517 * @return {!Common.TextRange} |
| 518 */ | 518 */ |
| 519 reverseMapTextRange(url, textRange) { | 519 reverseMapTextRange(url, textRange) { |
| 520 /** | 520 /** |
| 521 * @param {!{lineNumber: number, columnNumber: number}} position | 521 * @param {!{lineNumber: number, columnNumber: number}} position |
| 522 * @param {!WebInspector.SourceMapEntry} mapping | 522 * @param {!SDK.SourceMapEntry} mapping |
| 523 * @return {number} | 523 * @return {number} |
| 524 */ | 524 */ |
| 525 function comparator(position, mapping) { | 525 function comparator(position, mapping) { |
| 526 if (position.lineNumber !== mapping.sourceLineNumber) | 526 if (position.lineNumber !== mapping.sourceLineNumber) |
| 527 return position.lineNumber - mapping.sourceLineNumber; | 527 return position.lineNumber - mapping.sourceLineNumber; |
| 528 | 528 |
| 529 return position.columnNumber - mapping.sourceColumnNumber; | 529 return position.columnNumber - mapping.sourceColumnNumber; |
| 530 } | 530 } |
| 531 | 531 |
| 532 var mappings = this._reversedMappings(url); | 532 var mappings = this._reversedMappings(url); |
| 533 var startIndex = | 533 var startIndex = |
| 534 mappings.lowerBound({lineNumber: textRange.startLine, columnNumber: text
Range.startColumn}, comparator); | 534 mappings.lowerBound({lineNumber: textRange.startLine, columnNumber: text
Range.startColumn}, comparator); |
| 535 var endIndex = mappings.upperBound({lineNumber: textRange.endLine, columnNum
ber: textRange.endColumn}, comparator); | 535 var endIndex = mappings.upperBound({lineNumber: textRange.endLine, columnNum
ber: textRange.endColumn}, comparator); |
| 536 | 536 |
| 537 var startMapping = mappings[startIndex]; | 537 var startMapping = mappings[startIndex]; |
| 538 var endMapping = mappings[endIndex]; | 538 var endMapping = mappings[endIndex]; |
| 539 return new WebInspector.TextRange( | 539 return new Common.TextRange( |
| 540 startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumbe
r, endMapping.columnNumber); | 540 startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumbe
r, endMapping.columnNumber); |
| 541 } | 541 } |
| 542 }; | 542 }; |
| 543 | 543 |
| 544 WebInspector.TextSourceMap._VLQ_BASE_SHIFT = 5; | 544 SDK.TextSourceMap._VLQ_BASE_SHIFT = 5; |
| 545 WebInspector.TextSourceMap._VLQ_BASE_MASK = (1 << 5) - 1; | 545 SDK.TextSourceMap._VLQ_BASE_MASK = (1 << 5) - 1; |
| 546 WebInspector.TextSourceMap._VLQ_CONTINUATION_MASK = 1 << 5; | 546 SDK.TextSourceMap._VLQ_CONTINUATION_MASK = 1 << 5; |
| 547 | 547 |
| 548 | 548 |
| 549 /** | 549 /** |
| 550 * @unrestricted | 550 * @unrestricted |
| 551 */ | 551 */ |
| 552 WebInspector.TextSourceMap.StringCharIterator = class { | 552 SDK.TextSourceMap.StringCharIterator = class { |
| 553 /** | 553 /** |
| 554 * @param {string} string | 554 * @param {string} string |
| 555 */ | 555 */ |
| 556 constructor(string) { | 556 constructor(string) { |
| 557 this._string = string; | 557 this._string = string; |
| 558 this._position = 0; | 558 this._position = 0; |
| 559 } | 559 } |
| 560 | 560 |
| 561 /** | 561 /** |
| 562 * @return {string} | 562 * @return {string} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 576 * @return {boolean} | 576 * @return {boolean} |
| 577 */ | 577 */ |
| 578 hasNext() { | 578 hasNext() { |
| 579 return this._position < this._string.length; | 579 return this._position < this._string.length; |
| 580 } | 580 } |
| 581 }; | 581 }; |
| 582 | 582 |
| 583 /** | 583 /** |
| 584 * @unrestricted | 584 * @unrestricted |
| 585 */ | 585 */ |
| 586 WebInspector.TextSourceMap.SourceInfo = class { | 586 SDK.TextSourceMap.SourceInfo = class { |
| 587 /** | 587 /** |
| 588 * @param {?string} content | 588 * @param {?string} content |
| 589 * @param {?Array<!WebInspector.SourceMapEntry>} reverseMappings | 589 * @param {?Array<!SDK.SourceMapEntry>} reverseMappings |
| 590 */ | 590 */ |
| 591 constructor(content, reverseMappings) { | 591 constructor(content, reverseMappings) { |
| 592 this.content = content; | 592 this.content = content; |
| 593 this.reverseMappings = reverseMappings; | 593 this.reverseMappings = reverseMappings; |
| 594 } | 594 } |
| 595 }; | 595 }; |
| 596 | 596 |
| 597 WebInspector.TextSourceMap._sourcesListSymbol = Symbol('sourcesList'); | 597 SDK.TextSourceMap._sourcesListSymbol = Symbol('sourcesList'); |
| OLD | NEW |