| 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 WebInspector.SourceMapNamesResolver = {}; | 4 Sources.SourceMapNamesResolver = {}; |
| 5 | 5 |
| 6 WebInspector.SourceMapNamesResolver._cachedMapSymbol = Symbol('cache'); | 6 Sources.SourceMapNamesResolver._cachedMapSymbol = Symbol('cache'); |
| 7 WebInspector.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol('cachedIde
ntifiers'); | 7 Sources.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol('cachedIdentifi
ers'); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * @unrestricted | 10 * @unrestricted |
| 11 */ | 11 */ |
| 12 WebInspector.SourceMapNamesResolver.Identifier = class { | 12 Sources.SourceMapNamesResolver.Identifier = class { |
| 13 /** | 13 /** |
| 14 * @param {string} name | 14 * @param {string} name |
| 15 * @param {number} lineNumber | 15 * @param {number} lineNumber |
| 16 * @param {number} columnNumber | 16 * @param {number} columnNumber |
| 17 */ | 17 */ |
| 18 constructor(name, lineNumber, columnNumber) { | 18 constructor(name, lineNumber, columnNumber) { |
| 19 this.name = name; | 19 this.name = name; |
| 20 this.lineNumber = lineNumber; | 20 this.lineNumber = lineNumber; |
| 21 this.columnNumber = columnNumber; | 21 this.columnNumber = columnNumber; |
| 22 } | 22 } |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * @param {!WebInspector.DebuggerModel.Scope} scope | 26 * @param {!SDK.DebuggerModel.Scope} scope |
| 27 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>>} | 27 * @return {!Promise<!Array<!Sources.SourceMapNamesResolver.Identifier>>} |
| 28 */ | 28 */ |
| 29 WebInspector.SourceMapNamesResolver._scopeIdentifiers = function(scope) { | 29 Sources.SourceMapNamesResolver._scopeIdentifiers = function(scope) { |
| 30 var startLocation = scope.startLocation(); | 30 var startLocation = scope.startLocation(); |
| 31 var endLocation = scope.endLocation(); | 31 var endLocation = scope.endLocation(); |
| 32 | 32 |
| 33 if (scope.type() === Protocol.Debugger.ScopeType.Global || !startLocation || !
endLocation || | 33 if (scope.type() === Protocol.Debugger.ScopeType.Global || !startLocation || !
endLocation || |
| 34 !startLocation.script().sourceMapURL || (startLocation.script() !== endLoc
ation.script())) | 34 !startLocation.script().sourceMapURL || (startLocation.script() !== endLoc
ation.script())) |
| 35 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapNamesResolve
r.Identifier>}*/ ([])); | 35 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.Ide
ntifier>}*/ ([])); |
| 36 | 36 |
| 37 var script = startLocation.script(); | 37 var script = startLocation.script(); |
| 38 return script.requestContent().then(onContent); | 38 return script.requestContent().then(onContent); |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * @param {?string} content | 41 * @param {?string} content |
| 42 * @return {!Promise<!Array<!WebInspector.SourceMapNamesResolver.Identifier>>} | 42 * @return {!Promise<!Array<!Sources.SourceMapNamesResolver.Identifier>>} |
| 43 */ | 43 */ |
| 44 function onContent(content) { | 44 function onContent(content) { |
| 45 if (!content) | 45 if (!content) |
| 46 return Promise.resolve(/** @type {!Array<!WebInspector.SourceMapNamesResol
ver.Identifier>}*/ ([])); | 46 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.I
dentifier>}*/ ([])); |
| 47 | 47 |
| 48 var text = new WebInspector.Text(content); | 48 var text = new Common.Text(content); |
| 49 var scopeRange = new WebInspector.TextRange( | 49 var scopeRange = new Common.TextRange( |
| 50 startLocation.lineNumber, startLocation.columnNumber, endLocation.lineNu
mber, endLocation.columnNumber); | 50 startLocation.lineNumber, startLocation.columnNumber, endLocation.lineNu
mber, endLocation.columnNumber); |
| 51 var scopeText = text.extract(scopeRange); | 51 var scopeText = text.extract(scopeRange); |
| 52 var scopeStart = text.toSourceRange(scopeRange).offset; | 52 var scopeStart = text.toSourceRange(scopeRange).offset; |
| 53 var prefix = 'function fui'; | 53 var prefix = 'function fui'; |
| 54 return WebInspector.formatterWorkerPool.runTask('javaScriptIdentifiers', {co
ntent: prefix + scopeText}) | 54 return Common.formatterWorkerPool.runTask('javaScriptIdentifiers', {content:
prefix + scopeText}) |
| 55 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); | 55 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @param {!WebInspector.Text} text | 59 * @param {!Common.Text} text |
| 60 * @param {number} scopeStart | 60 * @param {number} scopeStart |
| 61 * @param {string} prefix | 61 * @param {string} prefix |
| 62 * @param {?MessageEvent} event | 62 * @param {?MessageEvent} event |
| 63 * @return {!Array<!WebInspector.SourceMapNamesResolver.Identifier>} | 63 * @return {!Array<!Sources.SourceMapNamesResolver.Identifier>} |
| 64 */ | 64 */ |
| 65 function onIdentifiers(text, scopeStart, prefix, event) { | 65 function onIdentifiers(text, scopeStart, prefix, event) { |
| 66 var identifiers = event ? /** @type {!Array<!{name: string, offset: number}>
} */ (event.data) : []; | 66 var identifiers = event ? /** @type {!Array<!{name: string, offset: number}>
} */ (event.data) : []; |
| 67 var result = []; | 67 var result = []; |
| 68 var cursor = new WebInspector.TextCursor(text.lineEndings()); | 68 var cursor = new Common.TextCursor(text.lineEndings()); |
| 69 var promises = []; | 69 var promises = []; |
| 70 for (var i = 0; i < identifiers.length; ++i) { | 70 for (var i = 0; i < identifiers.length; ++i) { |
| 71 var id = identifiers[i]; | 71 var id = identifiers[i]; |
| 72 if (id.offset < prefix.length) | 72 if (id.offset < prefix.length) |
| 73 continue; | 73 continue; |
| 74 var start = scopeStart + id.offset - prefix.length; | 74 var start = scopeStart + id.offset - prefix.length; |
| 75 cursor.resetTo(start); | 75 cursor.resetTo(start); |
| 76 result.push( | 76 result.push( |
| 77 new WebInspector.SourceMapNamesResolver.Identifier(id.name, cursor.lin
eNumber(), cursor.columnNumber())); | 77 new Sources.SourceMapNamesResolver.Identifier(id.name, cursor.lineNumb
er(), cursor.columnNumber())); |
| 78 } | 78 } |
| 79 return result; | 79 return result; |
| 80 } | 80 } |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @param {!WebInspector.DebuggerModel.Scope} scope | 84 * @param {!SDK.DebuggerModel.Scope} scope |
| 85 * @return {!Promise.<!Map<string, string>>} | 85 * @return {!Promise.<!Map<string, string>>} |
| 86 */ | 86 */ |
| 87 WebInspector.SourceMapNamesResolver._resolveScope = function(scope) { | 87 Sources.SourceMapNamesResolver._resolveScope = function(scope) { |
| 88 var identifiersPromise = scope[WebInspector.SourceMapNamesResolver._cachedIden
tifiersSymbol]; | 88 var identifiersPromise = scope[Sources.SourceMapNamesResolver._cachedIdentifie
rsSymbol]; |
| 89 if (identifiersPromise) | 89 if (identifiersPromise) |
| 90 return identifiersPromise; | 90 return identifiersPromise; |
| 91 | 91 |
| 92 var script = scope.callFrame().script; | 92 var script = scope.callFrame().script; |
| 93 var sourceMap = WebInspector.debuggerWorkspaceBinding.sourceMapForScript(scrip
t); | 93 var sourceMap = Bindings.debuggerWorkspaceBinding.sourceMapForScript(script); |
| 94 if (!sourceMap) | 94 if (!sourceMap) |
| 95 return Promise.resolve(new Map()); | 95 return Promise.resolve(new Map()); |
| 96 | 96 |
| 97 /** @type {!Map<string, !WebInspector.Text>} */ | 97 /** @type {!Map<string, !Common.Text>} */ |
| 98 var textCache = new Map(); | 98 var textCache = new Map(); |
| 99 identifiersPromise = WebInspector.SourceMapNamesResolver._scopeIdentifiers(sco
pe).then(onIdentifiers); | 99 identifiersPromise = Sources.SourceMapNamesResolver._scopeIdentifiers(scope).t
hen(onIdentifiers); |
| 100 scope[WebInspector.SourceMapNamesResolver._cachedIdentifiersSymbol] = identifi
ersPromise; | 100 scope[Sources.SourceMapNamesResolver._cachedIdentifiersSymbol] = identifiersPr
omise; |
| 101 return identifiersPromise; | 101 return identifiersPromise; |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @param {!Array<!WebInspector.SourceMapNamesResolver.Identifier>} identifier
s | 104 * @param {!Array<!Sources.SourceMapNamesResolver.Identifier>} identifiers |
| 105 * @return {!Promise<!Map<string, string>>} | 105 * @return {!Promise<!Map<string, string>>} |
| 106 */ | 106 */ |
| 107 function onIdentifiers(identifiers) { | 107 function onIdentifiers(identifiers) { |
| 108 var namesMapping = new Map(); | 108 var namesMapping = new Map(); |
| 109 // Extract as much as possible from SourceMap. | 109 // Extract as much as possible from SourceMap. |
| 110 for (var i = 0; i < identifiers.length; ++i) { | 110 for (var i = 0; i < identifiers.length; ++i) { |
| 111 var id = identifiers[i]; | 111 var id = identifiers[i]; |
| 112 var entry = sourceMap.findEntry(id.lineNumber, id.columnNumber); | 112 var entry = sourceMap.findEntry(id.lineNumber, id.columnNumber); |
| 113 if (entry && entry.name) | 113 if (entry && entry.name) |
| 114 namesMapping.set(id.name, entry.name); | 114 namesMapping.set(id.name, entry.name); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Resolve missing identifier names from sourcemap ranges. | 117 // Resolve missing identifier names from sourcemap ranges. |
| 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(null, n
amesMapping, id)); | 123 var promise = resolveSourceName(id).then(onSourceNameResolved.bind(null, n
amesMapping, 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._scopeResolvedForTest()) | 127 .then(() => Sources.SourceMapNamesResolver._scopeResolvedForTest()) |
| 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 {!Sources.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 if (!sourceName) | 137 if (!sourceName) |
| 138 return; | 138 return; |
| 139 namesMapping.set(id.name, sourceName); | 139 namesMapping.set(id.name, sourceName); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @param {!WebInspector.SourceMapNamesResolver.Identifier} id | 143 * @param {!Sources.SourceMapNamesResolver.Identifier} id |
| 144 * @return {!Promise<?string>} | 144 * @return {!Promise<?string>} |
| 145 */ | 145 */ |
| 146 function resolveSourceName(id) { | 146 function resolveSourceName(id) { |
| 147 var startEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber); | 147 var startEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber); |
| 148 var endEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber + id.name.
length); | 148 var endEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber + id.name.
length); |
| 149 if (!startEntry || !endEntry || !startEntry.sourceURL || startEntry.sourceUR
L !== endEntry.sourceURL || | 149 if (!startEntry || !endEntry || !startEntry.sourceURL || startEntry.sourceUR
L !== endEntry.sourceURL || |
| 150 !startEntry.sourceLineNumber || !startEntry.sourceColumnNumber || !endEn
try.sourceLineNumber || | 150 !startEntry.sourceLineNumber || !startEntry.sourceColumnNumber || !endEn
try.sourceLineNumber || |
| 151 !endEntry.sourceColumnNumber) | 151 !endEntry.sourceColumnNumber) |
| 152 return Promise.resolve(/** @type {?string} */ (null)); | 152 return Promise.resolve(/** @type {?string} */ (null)); |
| 153 var sourceTextRange = new WebInspector.TextRange( | 153 var sourceTextRange = new Common.TextRange( |
| 154 startEntry.sourceLineNumber, startEntry.sourceColumnNumber, endEntry.sou
rceLineNumber, | 154 startEntry.sourceLineNumber, startEntry.sourceColumnNumber, endEntry.sou
rceLineNumber, |
| 155 endEntry.sourceColumnNumber); | 155 endEntry.sourceColumnNumber); |
| 156 var uiSourceCode = WebInspector.networkMapping.uiSourceCodeForScriptURL(star
tEntry.sourceURL, script); | 156 var uiSourceCode = Bindings.networkMapping.uiSourceCodeForScriptURL(startEnt
ry.sourceURL, script); |
| 157 if (!uiSourceCode) | 157 if (!uiSourceCode) |
| 158 return Promise.resolve(/** @type {?string} */ (null)); | 158 return Promise.resolve(/** @type {?string} */ (null)); |
| 159 | 159 |
| 160 return uiSourceCode.requestContent().then(onSourceContent.bind(null, sourceT
extRange)); | 160 return uiSourceCode.requestContent().then(onSourceContent.bind(null, sourceT
extRange)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * @param {!WebInspector.TextRange} sourceTextRange | 164 * @param {!Common.TextRange} sourceTextRange |
| 165 * @param {?string} content | 165 * @param {?string} content |
| 166 * @return {?string} | 166 * @return {?string} |
| 167 */ | 167 */ |
| 168 function onSourceContent(sourceTextRange, content) { | 168 function onSourceContent(sourceTextRange, content) { |
| 169 if (!content) | 169 if (!content) |
| 170 return null; | 170 return null; |
| 171 var text = textCache.get(content); | 171 var text = textCache.get(content); |
| 172 if (!text) { | 172 if (!text) { |
| 173 text = new WebInspector.Text(content); | 173 text = new Common.Text(content); |
| 174 textCache.set(content, text); | 174 textCache.set(content, text); |
| 175 } | 175 } |
| 176 var originalIdentifier = text.extract(sourceTextRange).trim(); | 176 var originalIdentifier = text.extract(sourceTextRange).trim(); |
| 177 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier : null
; | 177 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier : null
; |
| 178 } | 178 } |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 WebInspector.SourceMapNamesResolver._scopeResolvedForTest = function() {}; | 181 Sources.SourceMapNamesResolver._scopeResolvedForTest = function() {}; |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 184 * @param {!SDK.DebuggerModel.CallFrame} callFrame |
| 185 * @return {!Promise.<!Map<string, string>>} | 185 * @return {!Promise.<!Map<string, string>>} |
| 186 */ | 186 */ |
| 187 WebInspector.SourceMapNamesResolver._allVariablesInCallFrame = function(callFram
e) { | 187 Sources.SourceMapNamesResolver._allVariablesInCallFrame = function(callFrame) { |
| 188 var cached = callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol]; | 188 var cached = callFrame[Sources.SourceMapNamesResolver._cachedMapSymbol]; |
| 189 if (cached) | 189 if (cached) |
| 190 return Promise.resolve(cached); | 190 return Promise.resolve(cached); |
| 191 | 191 |
| 192 var promises = []; | 192 var promises = []; |
| 193 var scopeChain = callFrame.scopeChain(); | 193 var scopeChain = callFrame.scopeChain(); |
| 194 for (var i = 0; i < scopeChain.length; ++i) | 194 for (var i = 0; i < scopeChain.length; ++i) |
| 195 promises.push(WebInspector.SourceMapNamesResolver._resolveScope(scopeChain[i
])); | 195 promises.push(Sources.SourceMapNamesResolver._resolveScope(scopeChain[i])); |
| 196 | 196 |
| 197 return Promise.all(promises).then(mergeVariables); | 197 return Promise.all(promises).then(mergeVariables); |
| 198 | 198 |
| 199 /** | 199 /** |
| 200 * @param {!Array<!Map<string, string>>} nameMappings | 200 * @param {!Array<!Map<string, string>>} nameMappings |
| 201 * @return {!Map<string, string>} | 201 * @return {!Map<string, string>} |
| 202 */ | 202 */ |
| 203 function mergeVariables(nameMappings) { | 203 function mergeVariables(nameMappings) { |
| 204 var reverseMapping = new Map(); | 204 var reverseMapping = new Map(); |
| 205 for (var map of nameMappings) { | 205 for (var map of nameMappings) { |
| 206 for (var compiledName of map.keys()) { | 206 for (var compiledName of map.keys()) { |
| 207 var originalName = map.get(compiledName); | 207 var originalName = map.get(compiledName); |
| 208 if (!reverseMapping.has(originalName)) | 208 if (!reverseMapping.has(originalName)) |
| 209 reverseMapping.set(originalName, compiledName); | 209 reverseMapping.set(originalName, compiledName); |
| 210 } | 210 } |
| 211 } | 211 } |
| 212 callFrame[WebInspector.SourceMapNamesResolver._cachedMapSymbol] = reverseMap
ping; | 212 callFrame[Sources.SourceMapNamesResolver._cachedMapSymbol] = reverseMapping; |
| 213 return reverseMapping; | 213 return reverseMapping; |
| 214 } | 214 } |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 /** | 217 /** |
| 218 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 218 * @param {!SDK.DebuggerModel.CallFrame} callFrame |
| 219 * @param {string} originalText | 219 * @param {string} originalText |
| 220 * @param {!WebInspector.UISourceCode} uiSourceCode | 220 * @param {!Workspace.UISourceCode} uiSourceCode |
| 221 * @param {number} lineNumber | 221 * @param {number} lineNumber |
| 222 * @param {number} startColumnNumber | 222 * @param {number} startColumnNumber |
| 223 * @param {number} endColumnNumber | 223 * @param {number} endColumnNumber |
| 224 * @return {!Promise<string>} | 224 * @return {!Promise<string>} |
| 225 */ | 225 */ |
| 226 WebInspector.SourceMapNamesResolver.resolveExpression = function( | 226 Sources.SourceMapNamesResolver.resolveExpression = function( |
| 227 callFrame, originalText, uiSourceCode, lineNumber, startColumnNumber, endCol
umnNumber) { | 227 callFrame, originalText, uiSourceCode, lineNumber, startColumnNumber, endCol
umnNumber) { |
| 228 if (!Runtime.experiments.isEnabled('resolveVariableNames') || !uiSourceCode.co
ntentType().isFromSourceMap()) | 228 if (!Runtime.experiments.isEnabled('resolveVariableNames') || !uiSourceCode.co
ntentType().isFromSourceMap()) |
| 229 return Promise.resolve(''); | 229 return Promise.resolve(''); |
| 230 | 230 |
| 231 return WebInspector.SourceMapNamesResolver._allVariablesInCallFrame(callFrame)
.then(findCompiledName); | 231 return Sources.SourceMapNamesResolver._allVariablesInCallFrame(callFrame).then
(findCompiledName); |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * @param {!Map<string, string>} reverseMapping | 234 * @param {!Map<string, string>} reverseMapping |
| 235 * @return {!Promise<string>} | 235 * @return {!Promise<string>} |
| 236 */ | 236 */ |
| 237 function findCompiledName(reverseMapping) { | 237 function findCompiledName(reverseMapping) { |
| 238 if (reverseMapping.has(originalText)) | 238 if (reverseMapping.has(originalText)) |
| 239 return Promise.resolve(reverseMapping.get(originalText) || ''); | 239 return Promise.resolve(reverseMapping.get(originalText) || ''); |
| 240 | 240 |
| 241 return WebInspector.SourceMapNamesResolver._resolveExpression( | 241 return Sources.SourceMapNamesResolver._resolveExpression( |
| 242 callFrame, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber)
; | 242 callFrame, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber)
; |
| 243 } | 243 } |
| 244 }; | 244 }; |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * @param {!WebInspector.DebuggerModel.CallFrame} callFrame | 247 * @param {!SDK.DebuggerModel.CallFrame} callFrame |
| 248 * @param {!WebInspector.UISourceCode} uiSourceCode | 248 * @param {!Workspace.UISourceCode} uiSourceCode |
| 249 * @param {number} lineNumber | 249 * @param {number} lineNumber |
| 250 * @param {number} startColumnNumber | 250 * @param {number} startColumnNumber |
| 251 * @param {number} endColumnNumber | 251 * @param {number} endColumnNumber |
| 252 * @return {!Promise<string>} | 252 * @return {!Promise<string>} |
| 253 */ | 253 */ |
| 254 WebInspector.SourceMapNamesResolver._resolveExpression = function( | 254 Sources.SourceMapNamesResolver._resolveExpression = function( |
| 255 callFrame, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber) { | 255 callFrame, uiSourceCode, lineNumber, startColumnNumber, endColumnNumber) { |
| 256 var target = callFrame.target(); | 256 var target = callFrame.target(); |
| 257 var rawLocation = WebInspector.debuggerWorkspaceBinding.uiLocationToRawLocatio
n( | 257 var rawLocation = Bindings.debuggerWorkspaceBinding.uiLocationToRawLocation( |
| 258 target, uiSourceCode, lineNumber, startColumnNumber); | 258 target, uiSourceCode, lineNumber, startColumnNumber); |
| 259 if (!rawLocation) | 259 if (!rawLocation) |
| 260 return Promise.resolve(''); | 260 return Promise.resolve(''); |
| 261 | 261 |
| 262 var script = rawLocation.script(); | 262 var script = rawLocation.script(); |
| 263 if (!script) | 263 if (!script) |
| 264 return Promise.resolve(''); | 264 return Promise.resolve(''); |
| 265 var sourceMap = WebInspector.debuggerWorkspaceBinding.sourceMapForScript(scrip
t); | 265 var sourceMap = Bindings.debuggerWorkspaceBinding.sourceMapForScript(script); |
| 266 if (!sourceMap) | 266 if (!sourceMap) |
| 267 return Promise.resolve(''); | 267 return Promise.resolve(''); |
| 268 | 268 |
| 269 return script.requestContent().then(onContent); | 269 return script.requestContent().then(onContent); |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * @param {?string} content | 272 * @param {?string} content |
| 273 * @return {!Promise<string>} | 273 * @return {!Promise<string>} |
| 274 */ | 274 */ |
| 275 function onContent(content) { | 275 function onContent(content) { |
| 276 if (!content) | 276 if (!content) |
| 277 return Promise.resolve(''); | 277 return Promise.resolve(''); |
| 278 | 278 |
| 279 var text = new WebInspector.Text(content); | 279 var text = new Common.Text(content); |
| 280 var textRange = sourceMap.reverseMapTextRange( | 280 var textRange = sourceMap.reverseMapTextRange( |
| 281 uiSourceCode.url(), new WebInspector.TextRange(lineNumber, startColumnNu
mber, lineNumber, endColumnNumber)); | 281 uiSourceCode.url(), new Common.TextRange(lineNumber, startColumnNumber,
lineNumber, endColumnNumber)); |
| 282 var originalText = text.extract(textRange); | 282 var originalText = text.extract(textRange); |
| 283 if (!originalText) | 283 if (!originalText) |
| 284 return Promise.resolve(''); | 284 return Promise.resolve(''); |
| 285 return WebInspector.formatterWorkerPool.runTask('evaluatableJavaScriptSubstr
ing', {content: originalText}) | 285 return Common.formatterWorkerPool.runTask('evaluatableJavaScriptSubstring',
{content: originalText}) |
| 286 .then(onResult); | 286 .then(onResult); |
| 287 } | 287 } |
| 288 | 288 |
| 289 /** | 289 /** |
| 290 * @param {?MessageEvent} event | 290 * @param {?MessageEvent} event |
| 291 * @return {string} | 291 * @return {string} |
| 292 */ | 292 */ |
| 293 function onResult(event) { | 293 function onResult(event) { |
| 294 return event ? /** @type {string} */ (event.data) : ''; | 294 return event ? /** @type {string} */ (event.data) : ''; |
| 295 } | 295 } |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * @param {?WebInspector.DebuggerModel.CallFrame} callFrame | 299 * @param {?SDK.DebuggerModel.CallFrame} callFrame |
| 300 * @return {!Promise<?WebInspector.RemoteObject>} | 300 * @return {!Promise<?SDK.RemoteObject>} |
| 301 */ | 301 */ |
| 302 WebInspector.SourceMapNamesResolver.resolveThisObject = function(callFrame) { | 302 Sources.SourceMapNamesResolver.resolveThisObject = function(callFrame) { |
| 303 if (!callFrame) | 303 if (!callFrame) |
| 304 return Promise.resolve(/** @type {?WebInspector.RemoteObject} */ (null)); | 304 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); |
| 305 if (!Runtime.experiments.isEnabled('resolveVariableNames') || !callFrame.scope
Chain().length) | 305 if (!Runtime.experiments.isEnabled('resolveVariableNames') || !callFrame.scope
Chain().length) |
| 306 return Promise.resolve(callFrame.thisObject()); | 306 return Promise.resolve(callFrame.thisObject()); |
| 307 | 307 |
| 308 return WebInspector.SourceMapNamesResolver._resolveScope(callFrame.scopeChain(
)[0]).then(onScopeResolved); | 308 return Sources.SourceMapNamesResolver._resolveScope(callFrame.scopeChain()[0])
.then(onScopeResolved); |
| 309 | 309 |
| 310 /** | 310 /** |
| 311 * @param {!Map<string, string>} namesMapping | 311 * @param {!Map<string, string>} namesMapping |
| 312 * @return {!Promise<?WebInspector.RemoteObject>} | 312 * @return {!Promise<?SDK.RemoteObject>} |
| 313 */ | 313 */ |
| 314 function onScopeResolved(namesMapping) { | 314 function onScopeResolved(namesMapping) { |
| 315 var thisMappings = namesMapping.inverse().get('this'); | 315 var thisMappings = namesMapping.inverse().get('this'); |
| 316 if (!thisMappings || thisMappings.size !== 1) | 316 if (!thisMappings || thisMappings.size !== 1) |
| 317 return Promise.resolve(callFrame.thisObject()); | 317 return Promise.resolve(callFrame.thisObject()); |
| 318 | 318 |
| 319 var thisMapping = thisMappings.valuesArray()[0]; | 319 var thisMapping = thisMappings.valuesArray()[0]; |
| 320 var callback; | 320 var callback; |
| 321 var promise = new Promise(fulfill => callback = fulfill); | 321 var promise = new Promise(fulfill => callback = fulfill); |
| 322 callFrame.evaluate(thisMapping, 'backtrace', false, true, false, true, onEva
luated.bind(null, callback)); | 322 callFrame.evaluate(thisMapping, 'backtrace', false, true, false, true, onEva
luated.bind(null, callback)); |
| 323 return promise; | 323 return promise; |
| 324 } | 324 } |
| 325 | 325 |
| 326 /** | 326 /** |
| 327 * @param {function(!WebInspector.RemoteObject)} callback | 327 * @param {function(!SDK.RemoteObject)} callback |
| 328 * @param {?Protocol.Runtime.RemoteObject} evaluateResult | 328 * @param {?Protocol.Runtime.RemoteObject} evaluateResult |
| 329 */ | 329 */ |
| 330 function onEvaluated(callback, evaluateResult) { | 330 function onEvaluated(callback, evaluateResult) { |
| 331 var remoteObject = | 331 var remoteObject = |
| 332 evaluateResult ? callFrame.target().runtimeModel.createRemoteObject(eval
uateResult) : callFrame.thisObject(); | 332 evaluateResult ? callFrame.target().runtimeModel.createRemoteObject(eval
uateResult) : callFrame.thisObject(); |
| 333 callback(remoteObject); | 333 callback(remoteObject); |
| 334 } | 334 } |
| 335 }; | 335 }; |
| 336 | 336 |
| 337 /** | 337 /** |
| 338 * @param {!WebInspector.DebuggerModel.Scope} scope | 338 * @param {!SDK.DebuggerModel.Scope} scope |
| 339 * @return {!WebInspector.RemoteObject} | 339 * @return {!SDK.RemoteObject} |
| 340 */ | 340 */ |
| 341 WebInspector.SourceMapNamesResolver.resolveScopeInObject = function(scope) { | 341 Sources.SourceMapNamesResolver.resolveScopeInObject = function(scope) { |
| 342 if (!Runtime.experiments.isEnabled('resolveVariableNames')) | 342 if (!Runtime.experiments.isEnabled('resolveVariableNames')) |
| 343 return scope.object(); | 343 return scope.object(); |
| 344 | 344 |
| 345 var startLocation = scope.startLocation(); | 345 var startLocation = scope.startLocation(); |
| 346 var endLocation = scope.endLocation(); | 346 var endLocation = scope.endLocation(); |
| 347 | 347 |
| 348 if (scope.type() === Protocol.Debugger.ScopeType.Global || !startLocation || !
endLocation || | 348 if (scope.type() === Protocol.Debugger.ScopeType.Global || !startLocation || !
endLocation || |
| 349 !startLocation.script().sourceMapURL || startLocation.script() !== endLoca
tion.script()) | 349 !startLocation.script().sourceMapURL || startLocation.script() !== endLoca
tion.script()) |
| 350 return scope.object(); | 350 return scope.object(); |
| 351 | 351 |
| 352 return new WebInspector.SourceMapNamesResolver.RemoteObject(scope); | 352 return new Sources.SourceMapNamesResolver.RemoteObject(scope); |
| 353 }; | 353 }; |
| 354 | 354 |
| 355 /** | 355 /** |
| 356 * @unrestricted | 356 * @unrestricted |
| 357 */ | 357 */ |
| 358 WebInspector.SourceMapNamesResolver.RemoteObject = class extends WebInspector.Re
moteObject { | 358 Sources.SourceMapNamesResolver.RemoteObject = class extends SDK.RemoteObject { |
| 359 /** | 359 /** |
| 360 * @param {!WebInspector.DebuggerModel.Scope} scope | 360 * @param {!SDK.DebuggerModel.Scope} scope |
| 361 */ | 361 */ |
| 362 constructor(scope) { | 362 constructor(scope) { |
| 363 super(); | 363 super(); |
| 364 this._scope = scope; | 364 this._scope = scope; |
| 365 this._object = scope.object(); | 365 this._object = scope.object(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 /** | 368 /** |
| 369 * @override | 369 * @override |
| 370 * @return {?Protocol.Runtime.CustomPreview} | 370 * @return {?Protocol.Runtime.CustomPreview} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 /** | 408 /** |
| 409 * @override | 409 * @override |
| 410 * @return {number} | 410 * @return {number} |
| 411 */ | 411 */ |
| 412 arrayLength() { | 412 arrayLength() { |
| 413 return this._object.arrayLength(); | 413 return this._object.arrayLength(); |
| 414 } | 414 } |
| 415 | 415 |
| 416 /** | 416 /** |
| 417 * @override | 417 * @override |
| 418 * @param {function(?Array.<!WebInspector.RemoteObjectProperty>, ?Array.<!WebI
nspector.RemoteObjectProperty>)} callback | 418 * @param {function(?Array.<!SDK.RemoteObjectProperty>, ?Array.<!SDK.RemoteObj
ectProperty>)} callback |
| 419 */ | 419 */ |
| 420 getOwnProperties(callback) { | 420 getOwnProperties(callback) { |
| 421 this._object.getOwnProperties(callback); | 421 this._object.getOwnProperties(callback); |
| 422 } | 422 } |
| 423 | 423 |
| 424 /** | 424 /** |
| 425 * @override | 425 * @override |
| 426 * @param {boolean} accessorPropertiesOnly | 426 * @param {boolean} accessorPropertiesOnly |
| 427 * @param {function(?Array<!WebInspector.RemoteObjectProperty>, ?Array<!WebIns
pector.RemoteObjectProperty>)} callback | 427 * @param {function(?Array<!SDK.RemoteObjectProperty>, ?Array<!SDK.RemoteObjec
tProperty>)} callback |
| 428 */ | 428 */ |
| 429 getAllProperties(accessorPropertiesOnly, callback) { | 429 getAllProperties(accessorPropertiesOnly, callback) { |
| 430 /** | 430 /** |
| 431 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties | 431 * @param {?Array.<!SDK.RemoteObjectProperty>} properties |
| 432 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperties | 432 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties |
| 433 * @this {WebInspector.SourceMapNamesResolver.RemoteObject} | 433 * @this {Sources.SourceMapNamesResolver.RemoteObject} |
| 434 */ | 434 */ |
| 435 function wrappedCallback(properties, internalProperties) { | 435 function wrappedCallback(properties, internalProperties) { |
| 436 WebInspector.SourceMapNamesResolver._resolveScope(this._scope) | 436 Sources.SourceMapNamesResolver._resolveScope(this._scope) |
| 437 .then(resolveNames.bind(null, properties, internalProperties)); | 437 .then(resolveNames.bind(null, properties, internalProperties)); |
| 438 } | 438 } |
| 439 | 439 |
| 440 /** | 440 /** |
| 441 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties | 441 * @param {?Array.<!SDK.RemoteObjectProperty>} properties |
| 442 * @param {?Array.<!WebInspector.RemoteObjectProperty>} internalProperties | 442 * @param {?Array.<!SDK.RemoteObjectProperty>} internalProperties |
| 443 * @param {!Map<string, string>} namesMapping | 443 * @param {!Map<string, string>} namesMapping |
| 444 */ | 444 */ |
| 445 function resolveNames(properties, internalProperties, namesMapping) { | 445 function resolveNames(properties, internalProperties, namesMapping) { |
| 446 var newProperties = []; | 446 var newProperties = []; |
| 447 if (properties) { | 447 if (properties) { |
| 448 for (var i = 0; i < properties.length; ++i) { | 448 for (var i = 0; i < properties.length; ++i) { |
| 449 var property = properties[i]; | 449 var property = properties[i]; |
| 450 var name = namesMapping.get(property.name) || properties[i].name; | 450 var name = namesMapping.get(property.name) || properties[i].name; |
| 451 newProperties.push(new WebInspector.RemoteObjectProperty( | 451 newProperties.push(new SDK.RemoteObjectProperty( |
| 452 name, property.value, property.enumerable, property.writable, prop
erty.isOwn, property.wasThrown, | 452 name, property.value, property.enumerable, property.writable, prop
erty.isOwn, property.wasThrown, |
| 453 property.symbol, property.synthetic)); | 453 property.symbol, property.synthetic)); |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 callback(newProperties, internalProperties); | 457 callback(newProperties, internalProperties); |
| 458 } | 458 } |
| 459 | 459 |
| 460 this._object.getAllProperties(accessorPropertiesOnly, wrappedCallback.bind(t
his)); | 460 this._object.getAllProperties(accessorPropertiesOnly, wrappedCallback.bind(t
his)); |
| 461 } | 461 } |
| 462 | 462 |
| 463 /** | 463 /** |
| 464 * @override | 464 * @override |
| 465 * @param {string|!Protocol.Runtime.CallArgument} argumentName | 465 * @param {string|!Protocol.Runtime.CallArgument} argumentName |
| 466 * @param {string} value | 466 * @param {string} value |
| 467 * @param {function(string=)} callback | 467 * @param {function(string=)} callback |
| 468 */ | 468 */ |
| 469 setPropertyValue(argumentName, value, callback) { | 469 setPropertyValue(argumentName, value, callback) { |
| 470 WebInspector.SourceMapNamesResolver._resolveScope(this._scope).then(resolveN
ame.bind(this)); | 470 Sources.SourceMapNamesResolver._resolveScope(this._scope).then(resolveName.b
ind(this)); |
| 471 | 471 |
| 472 /** | 472 /** |
| 473 * @param {!Map<string, string>} namesMapping | 473 * @param {!Map<string, string>} namesMapping |
| 474 * @this {WebInspector.SourceMapNamesResolver.RemoteObject} | 474 * @this {Sources.SourceMapNamesResolver.RemoteObject} |
| 475 */ | 475 */ |
| 476 function resolveName(namesMapping) { | 476 function resolveName(namesMapping) { |
| 477 var name; | 477 var name; |
| 478 if (typeof argumentName === 'string') | 478 if (typeof argumentName === 'string') |
| 479 name = argumentName; | 479 name = argumentName; |
| 480 else | 480 else |
| 481 name = /** @type {string} */ (argumentName.value); | 481 name = /** @type {string} */ (argumentName.value); |
| 482 | 482 |
| 483 var actualName = name; | 483 var actualName = name; |
| 484 for (var compiledName of namesMapping.keys()) { | 484 for (var compiledName of namesMapping.keys()) { |
| 485 if (namesMapping.get(compiledName) === name) { | 485 if (namesMapping.get(compiledName) === name) { |
| 486 actualName = compiledName; | 486 actualName = compiledName; |
| 487 break; | 487 break; |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 this._object.setPropertyValue(actualName, value, callback); | 490 this._object.setPropertyValue(actualName, value, callback); |
| 491 } | 491 } |
| 492 } | 492 } |
| 493 | 493 |
| 494 /** | 494 /** |
| 495 * @override | 495 * @override |
| 496 * @return {!Promise<?Array<!WebInspector.EventListener>>} | 496 * @return {!Promise<?Array<!SDK.EventListener>>} |
| 497 */ | 497 */ |
| 498 eventListeners() { | 498 eventListeners() { |
| 499 return this._object.eventListeners(); | 499 return this._object.eventListeners(); |
| 500 } | 500 } |
| 501 | 501 |
| 502 /** | 502 /** |
| 503 * @override | 503 * @override |
| 504 * @param {!Protocol.Runtime.CallArgument} name | 504 * @param {!Protocol.Runtime.CallArgument} name |
| 505 * @param {function(string=)} callback | 505 * @param {function(string=)} callback |
| 506 */ | 506 */ |
| 507 deleteProperty(name, callback) { | 507 deleteProperty(name, callback) { |
| 508 this._object.deleteProperty(name, callback); | 508 this._object.deleteProperty(name, callback); |
| 509 } | 509 } |
| 510 | 510 |
| 511 /** | 511 /** |
| 512 * @override | 512 * @override |
| 513 * @param {function(this:Object, ...)} functionDeclaration | 513 * @param {function(this:Object, ...)} functionDeclaration |
| 514 * @param {!Array<!Protocol.Runtime.CallArgument>=} args | 514 * @param {!Array<!Protocol.Runtime.CallArgument>=} args |
| 515 * @param {function(?WebInspector.RemoteObject, boolean=)=} callback | 515 * @param {function(?SDK.RemoteObject, boolean=)=} callback |
| 516 */ | 516 */ |
| 517 callFunction(functionDeclaration, args, callback) { | 517 callFunction(functionDeclaration, args, callback) { |
| 518 this._object.callFunction(functionDeclaration, args, callback); | 518 this._object.callFunction(functionDeclaration, args, callback); |
| 519 } | 519 } |
| 520 | 520 |
| 521 /** | 521 /** |
| 522 * @override | 522 * @override |
| 523 * @param {function(this:Object, ...)} functionDeclaration | 523 * @param {function(this:Object, ...)} functionDeclaration |
| 524 * @param {!Array<!Protocol.Runtime.CallArgument>|undefined} args | 524 * @param {!Array<!Protocol.Runtime.CallArgument>|undefined} args |
| 525 * @param {function(*)} callback | 525 * @param {function(*)} callback |
| 526 */ | 526 */ |
| 527 callFunctionJSON(functionDeclaration, args, callback) { | 527 callFunctionJSON(functionDeclaration, args, callback) { |
| 528 this._object.callFunctionJSON(functionDeclaration, args, callback); | 528 this._object.callFunctionJSON(functionDeclaration, args, callback); |
| 529 } | 529 } |
| 530 | 530 |
| 531 /** | 531 /** |
| 532 * @override | 532 * @override |
| 533 * @return {!WebInspector.Target} | 533 * @return {!SDK.Target} |
| 534 */ | 534 */ |
| 535 target() { | 535 target() { |
| 536 return this._object.target(); | 536 return this._object.target(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 /** | 539 /** |
| 540 * @override | 540 * @override |
| 541 * @return {?WebInspector.DebuggerModel} | 541 * @return {?SDK.DebuggerModel} |
| 542 */ | 542 */ |
| 543 debuggerModel() { | 543 debuggerModel() { |
| 544 return this._object.debuggerModel(); | 544 return this._object.debuggerModel(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 /** | 547 /** |
| 548 * @override | 548 * @override |
| 549 * @return {boolean} | 549 * @return {boolean} |
| 550 */ | 550 */ |
| 551 isNode() { | 551 isNode() { |
| 552 return this._object.isNode(); | 552 return this._object.isNode(); |
| 553 } | 553 } |
| 554 }; | 554 }; |
| OLD | NEW |