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 Sources.SourceMapNamesResolver = {}; | 4 Sources.SourceMapNamesResolver = {}; |
5 | 5 |
6 Sources.SourceMapNamesResolver._cachedMapSymbol = Symbol('cache'); | 6 Sources.SourceMapNamesResolver._cachedMapSymbol = Symbol('cache'); |
7 Sources.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol('cachedIdentifi
ers'); | 7 Sources.SourceMapNamesResolver._cachedIdentifiersSymbol = Symbol('cachedIdentifi
ers'); |
8 | 8 |
9 /** | 9 /** |
10 * @unrestricted | 10 * @unrestricted |
(...skipping 28 matching lines...) Expand all Loading... |
39 return script.requestContent().then(onContent); | 39 return script.requestContent().then(onContent); |
40 | 40 |
41 /** | 41 /** |
42 * @param {?string} content | 42 * @param {?string} content |
43 * @return {!Promise<!Array<!Sources.SourceMapNamesResolver.Identifier>>} | 43 * @return {!Promise<!Array<!Sources.SourceMapNamesResolver.Identifier>>} |
44 */ | 44 */ |
45 function onContent(content) { | 45 function onContent(content) { |
46 if (!content) | 46 if (!content) |
47 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.I
dentifier>}*/ ([])); | 47 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.I
dentifier>}*/ ([])); |
48 | 48 |
49 var text = new Common.Text(content); | 49 var text = new TextUtils.Text(content); |
50 var scopeRange = new Common.TextRange( | 50 var scopeRange = new TextUtils.TextRange( |
51 startLocation.lineNumber, startLocation.columnNumber, endLocation.lineNu
mber, endLocation.columnNumber); | 51 startLocation.lineNumber, startLocation.columnNumber, endLocation.lineNu
mber, endLocation.columnNumber); |
52 var scopeText = text.extract(scopeRange); | 52 var scopeText = text.extract(scopeRange); |
53 var scopeStart = text.toSourceRange(scopeRange).offset; | 53 var scopeStart = text.toSourceRange(scopeRange).offset; |
54 var prefix = 'function fui'; | 54 var prefix = 'function fui'; |
55 return Common.formatterWorkerPool.javaScriptIdentifiers(prefix + scopeText) | 55 return Common.formatterWorkerPool.javaScriptIdentifiers(prefix + scopeText) |
56 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); | 56 .then(onIdentifiers.bind(null, text, scopeStart, prefix)); |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * @param {!Common.Text} text | 60 * @param {!TextUtils.Text} text |
61 * @param {number} scopeStart | 61 * @param {number} scopeStart |
62 * @param {string} prefix | 62 * @param {string} prefix |
63 * @param {!Array<!{name: string, offset: number}>} identifiers | 63 * @param {!Array<!{name: string, offset: number}>} identifiers |
64 * @return {!Array<!Sources.SourceMapNamesResolver.Identifier>} | 64 * @return {!Array<!Sources.SourceMapNamesResolver.Identifier>} |
65 */ | 65 */ |
66 function onIdentifiers(text, scopeStart, prefix, identifiers) { | 66 function onIdentifiers(text, scopeStart, prefix, identifiers) { |
67 var result = []; | 67 var result = []; |
68 var cursor = new Common.TextCursor(text.lineEndings()); | 68 var cursor = new TextUtils.TextCursor(text.lineEndings()); |
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 Sources.SourceMapNamesResolver.Identifier(id.name, cursor.
lineNumber(), cursor.columnNumber())); | 75 result.push(new Sources.SourceMapNamesResolver.Identifier(id.name, cursor.
lineNumber(), cursor.columnNumber())); |
76 } | 76 } |
77 return result; | 77 return result; |
78 } | 78 } |
79 }; | 79 }; |
80 | 80 |
81 /** | 81 /** |
82 * @param {!SDK.DebuggerModel.Scope} scope | 82 * @param {!SDK.DebuggerModel.Scope} scope |
83 * @return {!Promise.<!Map<string, string>>} | 83 * @return {!Promise.<!Map<string, string>>} |
84 */ | 84 */ |
85 Sources.SourceMapNamesResolver._resolveScope = function(scope) { | 85 Sources.SourceMapNamesResolver._resolveScope = function(scope) { |
86 var identifiersPromise = scope[Sources.SourceMapNamesResolver._cachedIdentifie
rsSymbol]; | 86 var identifiersPromise = scope[Sources.SourceMapNamesResolver._cachedIdentifie
rsSymbol]; |
87 if (identifiersPromise) | 87 if (identifiersPromise) |
88 return identifiersPromise; | 88 return identifiersPromise; |
89 | 89 |
90 var script = scope.callFrame().script; | 90 var script = scope.callFrame().script; |
91 var sourceMap = Bindings.debuggerWorkspaceBinding.sourceMapForScript(script); | 91 var sourceMap = Bindings.debuggerWorkspaceBinding.sourceMapForScript(script); |
92 if (!sourceMap) | 92 if (!sourceMap) |
93 return Promise.resolve(new Map()); | 93 return Promise.resolve(new Map()); |
94 | 94 |
95 /** @type {!Map<string, !Common.Text>} */ | 95 /** @type {!Map<string, !TextUtils.Text>} */ |
96 var textCache = new Map(); | 96 var textCache = new Map(); |
97 identifiersPromise = Sources.SourceMapNamesResolver._scopeIdentifiers(scope).t
hen(onIdentifiers); | 97 identifiersPromise = Sources.SourceMapNamesResolver._scopeIdentifiers(scope).t
hen(onIdentifiers); |
98 scope[Sources.SourceMapNamesResolver._cachedIdentifiersSymbol] = identifiersPr
omise; | 98 scope[Sources.SourceMapNamesResolver._cachedIdentifiersSymbol] = identifiersPr
omise; |
99 return identifiersPromise; | 99 return identifiersPromise; |
100 | 100 |
101 /** | 101 /** |
102 * @param {!Array<!Sources.SourceMapNamesResolver.Identifier>} identifiers | 102 * @param {!Array<!Sources.SourceMapNamesResolver.Identifier>} identifiers |
103 * @return {!Promise<!Map<string, string>>} | 103 * @return {!Promise<!Map<string, string>>} |
104 */ | 104 */ |
105 function onIdentifiers(identifiers) { | 105 function onIdentifiers(identifiers) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 * @param {!Sources.SourceMapNamesResolver.Identifier} id | 141 * @param {!Sources.SourceMapNamesResolver.Identifier} id |
142 * @return {!Promise<?string>} | 142 * @return {!Promise<?string>} |
143 */ | 143 */ |
144 function resolveSourceName(id) { | 144 function resolveSourceName(id) { |
145 var startEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber); | 145 var startEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber); |
146 var endEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber + id.name.
length); | 146 var endEntry = sourceMap.findEntry(id.lineNumber, id.columnNumber + id.name.
length); |
147 if (!startEntry || !endEntry || !startEntry.sourceURL || startEntry.sourceUR
L !== endEntry.sourceURL || | 147 if (!startEntry || !endEntry || !startEntry.sourceURL || startEntry.sourceUR
L !== endEntry.sourceURL || |
148 !startEntry.sourceLineNumber || !startEntry.sourceColumnNumber || !endEn
try.sourceLineNumber || | 148 !startEntry.sourceLineNumber || !startEntry.sourceColumnNumber || !endEn
try.sourceLineNumber || |
149 !endEntry.sourceColumnNumber) | 149 !endEntry.sourceColumnNumber) |
150 return Promise.resolve(/** @type {?string} */ (null)); | 150 return Promise.resolve(/** @type {?string} */ (null)); |
151 var sourceTextRange = new Common.TextRange( | 151 var sourceTextRange = new TextUtils.TextRange( |
152 startEntry.sourceLineNumber, startEntry.sourceColumnNumber, endEntry.sou
rceLineNumber, | 152 startEntry.sourceLineNumber, startEntry.sourceColumnNumber, endEntry.sou
rceLineNumber, |
153 endEntry.sourceColumnNumber); | 153 endEntry.sourceColumnNumber); |
154 var uiSourceCode = | 154 var uiSourceCode = |
155 Bindings.NetworkProject.uiSourceCodeForScriptURL(Workspace.workspace, st
artEntry.sourceURL, script); | 155 Bindings.NetworkProject.uiSourceCodeForScriptURL(Workspace.workspace, st
artEntry.sourceURL, script); |
156 if (!uiSourceCode) | 156 if (!uiSourceCode) |
157 return Promise.resolve(/** @type {?string} */ (null)); | 157 return Promise.resolve(/** @type {?string} */ (null)); |
158 | 158 |
159 return uiSourceCode.requestContent().then(onSourceContent.bind(null, sourceT
extRange)); | 159 return uiSourceCode.requestContent().then(onSourceContent.bind(null, sourceT
extRange)); |
160 } | 160 } |
161 | 161 |
162 /** | 162 /** |
163 * @param {!Common.TextRange} sourceTextRange | 163 * @param {!TextUtils.TextRange} sourceTextRange |
164 * @param {?string} content | 164 * @param {?string} content |
165 * @return {?string} | 165 * @return {?string} |
166 */ | 166 */ |
167 function onSourceContent(sourceTextRange, content) { | 167 function onSourceContent(sourceTextRange, content) { |
168 if (!content) | 168 if (!content) |
169 return null; | 169 return null; |
170 var text = textCache.get(content); | 170 var text = textCache.get(content); |
171 if (!text) { | 171 if (!text) { |
172 text = new Common.Text(content); | 172 text = new TextUtils.Text(content); |
173 textCache.set(content, text); | 173 textCache.set(content, text); |
174 } | 174 } |
175 var originalIdentifier = text.extract(sourceTextRange).trim(); | 175 var originalIdentifier = text.extract(sourceTextRange).trim(); |
176 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier : null
; | 176 return /[a-zA-Z0-9_$]+/.test(originalIdentifier) ? originalIdentifier : null
; |
177 } | 177 } |
178 }; | 178 }; |
179 | 179 |
180 Sources.SourceMapNamesResolver._scopeResolvedForTest = function() {}; | 180 Sources.SourceMapNamesResolver._scopeResolvedForTest = function() {}; |
181 | 181 |
182 /** | 182 /** |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return script.requestContent().then(onContent); | 267 return script.requestContent().then(onContent); |
268 | 268 |
269 /** | 269 /** |
270 * @param {?string} content | 270 * @param {?string} content |
271 * @return {!Promise<string>} | 271 * @return {!Promise<string>} |
272 */ | 272 */ |
273 function onContent(content) { | 273 function onContent(content) { |
274 if (!content) | 274 if (!content) |
275 return Promise.resolve(''); | 275 return Promise.resolve(''); |
276 | 276 |
277 var text = new Common.Text(content); | 277 var text = new TextUtils.Text(content); |
278 var textRange = sourceMap.reverseMapTextRange( | 278 var textRange = sourceMap.reverseMapTextRange( |
279 uiSourceCode.url(), new Common.TextRange(lineNumber, startColumnNumber,
lineNumber, endColumnNumber)); | 279 uiSourceCode.url(), new TextUtils.TextRange(lineNumber, startColumnNumbe
r, lineNumber, endColumnNumber)); |
280 var originalText = text.extract(textRange); | 280 var originalText = text.extract(textRange); |
281 if (!originalText) | 281 if (!originalText) |
282 return Promise.resolve(''); | 282 return Promise.resolve(''); |
283 return Common.formatterWorkerPool.evaluatableJavaScriptSubstring(originalTex
t); | 283 return Common.formatterWorkerPool.evaluatableJavaScriptSubstring(originalTex
t); |
284 } | 284 } |
285 }; | 285 }; |
286 | 286 |
287 /** | 287 /** |
288 * @param {?SDK.DebuggerModel.CallFrame} callFrame | 288 * @param {?SDK.DebuggerModel.CallFrame} callFrame |
289 * @return {!Promise<?SDK.RemoteObject>} | 289 * @return {!Promise<?SDK.RemoteObject>} |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 574 } |
575 | 575 |
576 /** | 576 /** |
577 * @override | 577 * @override |
578 * @return {boolean} | 578 * @return {boolean} |
579 */ | 579 */ |
580 isNode() { | 580 isNode() { |
581 return this._object.isNode(); | 581 return this._object.isNode(); |
582 } | 582 } |
583 }; | 583 }; |
OLD | NEW |