| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 WebInspector.SourceMapNamesResolver = {}; | 5 WebInspector.SourceMapNamesResolver = {}; |
| 6 | 6 |
| 7 WebInspector.SourceMapNamesResolver._cachedMapSymbol = Symbol("cache"); | 7 WebInspector.SourceMapNamesResolver._cachedMapSymbol = Symbol("cache"); |
| 8 WebInspector.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol("cachedIde
ntifiers"); | 8 WebInspector.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol("cachedIde
ntifiers"); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * @constructor | 11 * @constructor |
| 12 * @param {string} name | 12 * @param {string} name |
| 13 * @param {number} lineNumber | 13 * @param {number} lineNumber |
| 14 * @param {number} columnNumber | 14 * @param {number} columnNumber |
| 15 */ | 15 */ |
| 16 WebInspector.SourceMapNamesResolver.Identifier = function(name, lineNumber, colu
mnNumber) | 16 WebInspector.SourceMapNamesResolver.Identifier = function(name, lineNumber, colu
mnNumber) |
| 17 { | 17 { |
| 18 this.name = name; | 18 this.name = name; |
| 19 this.lineNumber = lineNumber; | 19 this.lineNumber = lineNumber; |
| 20 this.columnNumber = columnNumber; | 20 this.columnNumber = columnNumber; |
| 21 } | 21 }; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * @param {!WebInspector.DebuggerModel.Scope} scope | 24 * @param {!WebInspector.DebuggerModel.Scope} scope |
| 25 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>>} | 25 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>>} |
| 26 */ | 26 */ |
| 27 WebInspector.SourceMapNamesResolver._scopeIdentifiers = function(scope) | 27 WebInspector.SourceMapNamesResolver._scopeIdentifiers = function(scope) |
| 28 { | 28 { |
| 29 var startLocation = scope.startLocation(); | 29 var startLocation = scope.startLocation(); |
| 30 var endLocation = scope.endLocation(); | 30 var endLocation = scope.endLocation(); |
| 31 | 31 |
| 32 if (scope.type() === DebuggerAgent.ScopeType.Global || !startLocation || !en
dLocation || !startLocation.script().sourceMapURL || (startLocation.script() !==
endLocation.script())) | 32 if (scope.type() === DebuggerAgent.ScopeType.Global || !startLocation || !en
dLocation || !startLocation.script().sourceMapURL || (startLocation.script() !==
endLocation.script())) |
| 33 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapNamesRes
olver.Identifier>}*/([])); | 33 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapNamesRes
olver.Identifier>}*/([])); |
| 34 | 34 |
| 35 var script = startLocation.script(); | 35 var script = startLocation.script(); |
| 36 return script.requestContent().then(onContent); | 36 return script.requestContent().then(onContent); |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * @param {?string} content | 39 * @param {?string} content |
| 40 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>
>} | 40 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>
>} |
| 41 */ | 41 */ |
| 42 function onContent(content) | 42 function onContent(content) |
| 43 { | 43 { |
| 44 if (!content) | 44 if (!content) |
| 45 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapName
sResolver.Identifier>}*/([])); | 45 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapName
sResolver.Identifier>}*/([])); |
| 46 | 46 |
| 47 var text = new WebInspector.Text(content); | 47 var text = new WebInspector.Text(content); |
| 48 var scopeRange = new WebInspector.TextRange(startLocation.lineNumber, st
artLocation.columnNumber, endLocation.lineNumber, endLocation.columnNumber) | 48 var scopeRange = new WebInspector.TextRange(startLocation.lineNumber, st
artLocation.columnNumber, endLocation.lineNumber, endLocation.columnNumber); |
| 49 var scopeText = text.extract(scopeRange); | 49 var scopeText = text.extract(scopeRange); |
| 50 var scopeStart = text.toSourceRange(scopeRange).offset; | 50 var scopeStart = text.toSourceRange(scopeRange).offset; |
| 51 var prefix = "function fui"; | 51 var prefix = "function fui"; |
| 52 return WebInspector.formatterWorkerPool.runTask("javaScriptIdentifiers",
{content: prefix + scopeText}) | 52 return WebInspector.formatterWorkerPool.runTask("javaScriptIdentifiers",
{content: prefix + scopeText}) |
| 53 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); | 53 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {!WebInspector.Text} text | 57 * @param {!WebInspector.Text} text |
| 58 * @param {number} scopeStart | 58 * @param {number} scopeStart |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 for (var i = 0; i < identifiers.length; ++i) { | 69 for (var i = 0; i < identifiers.length; ++i) { |
| 70 var id = identifiers[i]; | 70 var id = identifiers[i]; |
| 71 if (id.offset < prefix.length) | 71 if (id.offset < prefix.length) |
| 72 continue; | 72 continue; |
| 73 var start = scopeStart + id.offset - prefix.length; | 73 var start = scopeStart + id.offset - prefix.length; |
| 74 cursor.resetTo(start); | 74 cursor.resetTo(start); |
| 75 result.push(new WebInspector.SourceMapNamesResolver.Identifier(id.na
me, cursor.lineNumber(), cursor.columnNumber())); | 75 result.push(new WebInspector.SourceMapNamesResolver.Identifier(id.na
me, cursor.lineNumber(), cursor.columnNumber())); |
| 76 } | 76 } |
| 77 return result; | 77 return result; |
| 78 } | 78 } |
| 79 } | 79 }; |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * @param {!WebInspector.DebuggerModel.Scope} scope | 82 * @param {!WebInspector.DebuggerModel.Scope} scope |
| 83 * @return {!Promise.<!Map<string, string>>} | 83 * @return {!Promise.<!Map<string, string>>} |
| 84 */ | 84 */ |
| 85 WebInspector.SourceMapNamesResolver._resolveScope = function(scope) | 85 WebInspector.SourceMapNamesResolver._resolveScope = function(scope) |
| 86 { | 86 { |
| 87 var identifiersPromise = scope[WebInspector.SourceMapNamesResolver._cachedId
entifiersSymbol]; | 87 var identifiersPromise = scope[WebInspector.SourceMapNamesResolver._cachedId
entifiersSymbol]; |
| 88 if (identifiersPromise) | 88 if (identifiersPromise) |
| 89 return identifiersPromise; | 89 return identifiersPromise; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 118 var promises = []; | 118 var promises = []; |
| 119 for (var i = 0; i < identifiers.length; ++i) { | 119 for (var i = 0; i < identifiers.length; ++i) { |
| 120 var id = identifiers[i]; | 120 var id = identifiers[i]; |
| 121 if (namesMapping.has(id.name)) | 121 if (namesMapping.has(id.name)) |
| 122 continue; | 122 continue; |
| 123 var promise = resolveSourceName(id).then(onSourceNameResolved.bind(n
ull, namesMapping, id)); | 123 var promise = resolveSourceName(id).then(onSourceNameResolved.bind(n
ull, namesMapping, id)); |
| 124 promises.push(promise); | 124 promises.push(promise); |
| 125 } | 125 } |
| 126 return Promise.all(promises) | 126 return Promise.all(promises) |
| 127 .then(() => WebInspector.SourceMapNamesResolver._scopeResolvedForTes
t()) | 127 .then(() => WebInspector.SourceMapNamesResolver._scopeResolvedForTes
t()) |
| 128 .then(() => namesMapping) | 128 .then(() => namesMapping); |
| 129 } | 129 } |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * @param {!Map<string, string>} namesMapping | 132 * @param {!Map<string, string>} namesMapping |
| 133 * @param {!WebInspector.SourceMapNamesResolver.Identifier} id | 133 * @param {!WebInspector.SourceMapNamesResolver.Identifier} id |
| 134 * @param {?string} sourceName | 134 * @param {?string} sourceName |
| 135 */ | 135 */ |
| 136 function onSourceNameResolved(namesMapping, id, sourceName) | 136 function onSourceNameResolved(namesMapping, id, sourceName) |
| 137 { | 137 { |
| 138 if (!sourceName) | 138 if (!sourceName) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (!content) | 171 if (!content) |
| 172 return null; | 172 return null; |
| 173 var text = textCache.get(content); | 173 var text = textCache.get(content); |
| 174 if (!text) { | 174 if (!text) { |
| 175 text = new WebInspector.Text(content); | 175 text = new WebInspector.Text(content); |
| 176 textCache.set(content, text); | 176 textCache.set(content, text); |
| 177 } | 177 } |
| 178 var originalIdentifier = text.extract(sourceTextRange).trim(); | 178 var originalIdentifier = text.extract(sourceTextRange).trim(); |
| 179 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier :
null; | 179 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier :
null; |
| 180 } | 180 } |
| 181 } | 181 }; |
| 182 | 182 |
| 183 WebInspector.SourceMapNamesResolver._scopeResolvedForTest = function() { } | 183 WebInspector.SourceMapNamesResolver._scopeResolvedForTest = function() { }; |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 186 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame |
| 187 * @return {!Promise.<!Map<string, string>>} | 187 * @return {!Promise.<!Map<string, string>>} |
| 188 */ | 188 */ |
| 189 WebInspector.SourceMapNamesResolver._allVariablesInCallFrame = function(callFram
e) | 189 WebInspector.SourceMapNamesResolver._allVariablesInCallFrame = function(callFram
e) |
| 190 { | 190 { |
| 191 var cached = callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol]
; | 191 var cached = callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol]
; |
| 192 if (cached) | 192 if (cached) |
| 193 return Promise.resolve(cached); | 193 return Promise.resolve(cached); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 209 for (var map of nameMappings) { | 209 for (var map of nameMappings) { |
| 210 for (var compiledName of map.keys()) { | 210 for (var compiledName of map.keys()) { |
| 211 var originalName = map.get(compiledName); | 211 var originalName = map.get(compiledName); |
| 212 if (!reverseMapping.has(originalName)) | 212 if (!reverseMapping.has(originalName)) |
| 213 reverseMapping.set(originalName, compiledName); | 213 reverseMapping.set(originalName, compiledName); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol] = revers
eMapping; | 216 callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol] = revers
eMapping; |
| 217 return reverseMapping; | 217 return reverseMapping; |
| 218 } | 218 } |
| 219 } | 219 }; |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 222 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame |
| 223 * @param {string} originalText | 223 * @param {string} originalText |
| 224 * @param {!WebInspector.UISourceCode} uiSourceCode | 224 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 225 * @param {number} lineNumber | 225 * @param {number} lineNumber |
| 226 * @param {number} startColumnNumber | 226 * @param {number} startColumnNumber |
| 227 * @param {number} endColumnNumber | 227 * @param {number} endColumnNumber |
| 228 * @return {!Promise<string>} | 228 * @return {!Promise<string>} |
| 229 */ | 229 */ |
| 230 WebInspector.SourceMapNamesResolver.resolveExpression = function(callFrame, orig
inalText, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber) | 230 WebInspector.SourceMapNamesResolver.resolveExpression = function(callFrame, orig
inalText, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber) |
| 231 { | 231 { |
| 232 if (!Runtime.experiments.isEnabled("resolveVariableNames") || !uiSourceCode.
contentType().isFromSourceMap()) | 232 if (!Runtime.experiments.isEnabled("resolveVariableNames") || !uiSourceCode.
contentType().isFromSourceMap()) |
| 233 return Promise.resolve(""); | 233 return Promise.resolve(""); |
| 234 | 234 |
| 235 return WebInspector.SourceMapNamesResolver._allVariablesInCallFrame(callFram
e).then(findCompiledName); | 235 return WebInspector.SourceMapNamesResolver._allVariablesInCallFrame(callFram
e).then(findCompiledName); |
| 236 | 236 |
| 237 /** | 237 /** |
| 238 * @param {!Map<string, string>} reverseMapping | 238 * @param {!Map<string, string>} reverseMapping |
| 239 * @return {!Promise<string>} | 239 * @return {!Promise<string>} |
| 240 */ | 240 */ |
| 241 function findCompiledName(reverseMapping) | 241 function findCompiledName(reverseMapping) |
| 242 { | 242 { |
| 243 if (reverseMapping.has(originalText)) | 243 if (reverseMapping.has(originalText)) |
| 244 return Promise.resolve(reverseMapping.get(originalText) || ""); | 244 return Promise.resolve(reverseMapping.get(originalText) || ""); |
| 245 | 245 |
| 246 return WebInspector.SourceMapNamesResolver._resolveExpression(callFrame,
uiSourceCode, lineNumber, startColumnNumber, endColumnNumber); | 246 return WebInspector.SourceMapNamesResolver._resolveExpression(callFrame,
uiSourceCode, lineNumber, startColumnNumber, endColumnNumber); |
| 247 } | 247 } |
| 248 } | 248 }; |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 251 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame |
| 252 * @param {!WebInspector.UISourceCode} uiSourceCode | 252 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 253 * @param {number} lineNumber | 253 * @param {number} lineNumber |
| 254 * @param {number} startColumnNumber | 254 * @param {number} startColumnNumber |
| 255 * @param {number} endColumnNumber | 255 * @param {number} endColumnNumber |
| 256 * @return {!Promise<string>} | 256 * @return {!Promise<string>} |
| 257 */ | 257 */ |
| 258 WebInspector.SourceMapNamesResolver._resolveExpression = function(callFrame, uiS
ourceCode, lineNumber, startColumnNumber, endColumnNumber) | 258 WebInspector.SourceMapNamesResolver._resolveExpression = function(callFrame, uiS
ourceCode, lineNumber, startColumnNumber, endColumnNumber) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 | 291 |
| 292 /** | 292 /** |
| 293 * @param {?MessageEvent} event | 293 * @param {?MessageEvent} event |
| 294 * @return {string} | 294 * @return {string} |
| 295 */ | 295 */ |
| 296 function onResult(event) | 296 function onResult(event) |
| 297 { | 297 { |
| 298 return event ? /** @type {string} */(event.data) : ""; | 298 return event ? /** @type {string} */(event.data) : ""; |
| 299 } | 299 } |
| 300 } | 300 }; |
| 301 | 301 |
| 302 /** | 302 /** |
| 303 * @param {?WebInspector.DebuggerModel.CallFrame} callFrame | 303 * @param {?WebInspector.DebuggerModel.CallFrame} callFrame |
| 304 * @return {!Promise<?WebInspector.RemoteObject>} | 304 * @return {!Promise<?WebInspector.RemoteObject>} |
| 305 */ | 305 */ |
| 306 WebInspector.SourceMapNamesResolver.resolveThisObject = function(callFrame) | 306 WebInspector.SourceMapNamesResolver.resolveThisObject = function(callFrame) |
| 307 { | 307 { |
| 308 if (!callFrame) | 308 if (!callFrame) |
| 309 return Promise.resolve(/** @type {?WebInspector.RemoteObject} */(null)); | 309 return Promise.resolve(/** @type {?WebInspector.RemoteObject} */(null)); |
| 310 if (!Runtime.experiments.isEnabled("resolveVariableNames") || !callFrame.sco
peChain().length) | 310 if (!Runtime.experiments.isEnabled("resolveVariableNames") || !callFrame.sco
peChain().length) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 332 | 332 |
| 333 /** | 333 /** |
| 334 * @param {function(!WebInspector.RemoteObject)} callback | 334 * @param {function(!WebInspector.RemoteObject)} callback |
| 335 * @param {?RuntimeAgent.RemoteObject} evaluateResult | 335 * @param {?RuntimeAgent.RemoteObject} evaluateResult |
| 336 */ | 336 */ |
| 337 function onEvaluated(callback, evaluateResult) | 337 function onEvaluated(callback, evaluateResult) |
| 338 { | 338 { |
| 339 var remoteObject = evaluateResult ? callFrame.target().runtimeModel.crea
teRemoteObject(evaluateResult) : callFrame.thisObject(); | 339 var remoteObject = evaluateResult ? callFrame.target().runtimeModel.crea
teRemoteObject(evaluateResult) : callFrame.thisObject(); |
| 340 callback(remoteObject); | 340 callback(remoteObject); |
| 341 } | 341 } |
| 342 } | 342 }; |
| 343 | 343 |
| 344 /** | 344 /** |
| 345 * @param {!WebInspector.DebuggerModel.Scope} scope | 345 * @param {!WebInspector.DebuggerModel.Scope} scope |
| 346 * @return {!WebInspector.RemoteObject} | 346 * @return {!WebInspector.RemoteObject} |
| 347 */ | 347 */ |
| 348 WebInspector.SourceMapNamesResolver.resolveScopeInObject = function(scope) | 348 WebInspector.SourceMapNamesResolver.resolveScopeInObject = function(scope) |
| 349 { | 349 { |
| 350 if (!Runtime.experiments.isEnabled("resolveVariableNames")) | 350 if (!Runtime.experiments.isEnabled("resolveVariableNames")) |
| 351 return scope.object(); | 351 return scope.object(); |
| 352 | 352 |
| 353 var startLocation = scope.startLocation(); | 353 var startLocation = scope.startLocation(); |
| 354 var endLocation = scope.endLocation(); | 354 var endLocation = scope.endLocation(); |
| 355 | 355 |
| 356 if (scope.type() === DebuggerAgent.ScopeType.Global || !startLocation || !en
dLocation || !startLocation.script().sourceMapURL || startLocation.script() !==
endLocation.script()) | 356 if (scope.type() === DebuggerAgent.ScopeType.Global || !startLocation || !en
dLocation || !startLocation.script().sourceMapURL || startLocation.script() !==
endLocation.script()) |
| 357 return scope.object(); | 357 return scope.object(); |
| 358 | 358 |
| 359 return new WebInspector.SourceMapNamesResolver.RemoteObject(scope); | 359 return new WebInspector.SourceMapNamesResolver.RemoteObject(scope); |
| 360 } | 360 }; |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * @constructor | 363 * @constructor |
| 364 * @extends {WebInspector.RemoteObject} | 364 * @extends {WebInspector.RemoteObject} |
| 365 * @param {!WebInspector.DebuggerModel.Scope} scope | 365 * @param {!WebInspector.DebuggerModel.Scope} scope |
| 366 */ | 366 */ |
| 367 WebInspector.SourceMapNamesResolver.RemoteObject = function(scope) | 367 WebInspector.SourceMapNamesResolver.RemoteObject = function(scope) |
| 368 { | 368 { |
| 369 WebInspector.RemoteObject.call(this); | 369 WebInspector.RemoteObject.call(this); |
| 370 this._scope = scope; | 370 this._scope = scope; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 */ | 442 */ |
| 443 getAllProperties: function(accessorPropertiesOnly, callback) | 443 getAllProperties: function(accessorPropertiesOnly, callback) |
| 444 { | 444 { |
| 445 /** | 445 /** |
| 446 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties | 446 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties |
| 447 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperti
es | 447 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperti
es |
| 448 * @this {WebInspector.SourceMapNamesResolver.RemoteObject} | 448 * @this {WebInspector.SourceMapNamesResolver.RemoteObject} |
| 449 */ | 449 */ |
| 450 function wrappedCallback(properties, internalProperties) | 450 function wrappedCallback(properties, internalProperties) |
| 451 { | 451 { |
| 452 WebInspector.SourceMapNamesResolver._resolveScope(this._scope).then(
resolveNames.bind(null, properties, internalProperties)) | 452 WebInspector.SourceMapNamesResolver._resolveScope(this._scope).then(
resolveNames.bind(null, properties, internalProperties)); |
| 453 } | 453 } |
| 454 | 454 |
| 455 /** | 455 /** |
| 456 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties | 456 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties |
| 457 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperti
es | 457 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperti
es |
| 458 * @param {!Map<string, string>} namesMapping | 458 * @param {!Map<string, string>} namesMapping |
| 459 */ | 459 */ |
| 460 function resolveNames(properties, internalProperties, namesMapping) | 460 function resolveNames(properties, internalProperties, namesMapping) |
| 461 { | 461 { |
| 462 var newProperties = []; | 462 var newProperties = []; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 /** | 569 /** |
| 570 * @override | 570 * @override |
| 571 * @return {boolean} | 571 * @return {boolean} |
| 572 */ | 572 */ |
| 573 isNode: function() | 573 isNode: function() |
| 574 { | 574 { |
| 575 return this._object.isNode(); | 575 return this._object.isNode(); |
| 576 }, | 576 }, |
| 577 | 577 |
| 578 __proto__: WebInspector.RemoteObject.prototype | 578 __proto__: WebInspector.RemoteObject.prototype |
| 579 } | 579 }; |
| 580 | 580 |
| OLD | NEW |