Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/SourceMapNamesResolver.js

Issue 2570263002: DevTools: introduce API for the Common.FormatterWorkerPool. (Closed)
Patch Set: address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sources/ScriptFormatter.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 function onContent(content) { 44 function onContent(content) {
45 if (!content) 45 if (!content)
46 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.I dentifier>}*/ ([])); 46 return Promise.resolve(/** @type {!Array<!Sources.SourceMapNamesResolver.I dentifier>}*/ ([]));
47 47
48 var text = new Common.Text(content); 48 var text = new Common.Text(content);
49 var scopeRange = new Common.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 Common.formatterWorkerPool.runTask('javaScriptIdentifiers', {content: prefix + scopeText}) 54 return Common.formatterWorkerPool.javaScriptIdentifiers(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 {!Common.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 {!Array<!{name: string, offset: number}>} identifiers
63 * @return {!Array<!Sources.SourceMapNamesResolver.Identifier>} 63 * @return {!Array<!Sources.SourceMapNamesResolver.Identifier>}
64 */ 64 */
65 function onIdentifiers(text, scopeStart, prefix, event) { 65 function onIdentifiers(text, scopeStart, prefix, identifiers) {
66 var identifiers = event ? /** @type {!Array<!{name: string, offset: number}> } */ (event.data) : [];
67 var result = []; 66 var result = [];
68 var cursor = new Common.TextCursor(text.lineEndings()); 67 var cursor = new Common.TextCursor(text.lineEndings());
69 var promises = []; 68 var promises = [];
70 for (var i = 0; i < identifiers.length; ++i) { 69 for (var i = 0; i < identifiers.length; ++i) {
71 var id = identifiers[i]; 70 var id = identifiers[i];
72 if (id.offset < prefix.length) 71 if (id.offset < prefix.length)
73 continue; 72 continue;
74 var start = scopeStart + id.offset - prefix.length; 73 var start = scopeStart + id.offset - prefix.length;
75 cursor.resetTo(start); 74 cursor.resetTo(start);
76 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()));
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 function onContent(content) { 274 function onContent(content) {
276 if (!content) 275 if (!content)
277 return Promise.resolve(''); 276 return Promise.resolve('');
278 277
279 var text = new Common.Text(content); 278 var text = new Common.Text(content);
280 var textRange = sourceMap.reverseMapTextRange( 279 var textRange = sourceMap.reverseMapTextRange(
281 uiSourceCode.url(), new Common.TextRange(lineNumber, startColumnNumber, lineNumber, endColumnNumber)); 280 uiSourceCode.url(), new Common.TextRange(lineNumber, startColumnNumber, lineNumber, endColumnNumber));
282 var originalText = text.extract(textRange); 281 var originalText = text.extract(textRange);
283 if (!originalText) 282 if (!originalText)
284 return Promise.resolve(''); 283 return Promise.resolve('');
285 return Common.formatterWorkerPool.runTask('evaluatableJavaScriptSubstring', {content: originalText}).then(onResult); 284 return Common.formatterWorkerPool.evaluatableJavaScriptSubstring(originalTex t);
286 }
287
288 /**
289 * @param {?MessageEvent} event
290 * @return {string}
291 */
292 function onResult(event) {
293 return event ? /** @type {string} */ (event.data) : '';
294 } 285 }
295 }; 286 };
296 287
297 /** 288 /**
298 * @param {?SDK.DebuggerModel.CallFrame} callFrame 289 * @param {?SDK.DebuggerModel.CallFrame} callFrame
299 * @return {!Promise<?SDK.RemoteObject>} 290 * @return {!Promise<?SDK.RemoteObject>}
300 */ 291 */
301 Sources.SourceMapNamesResolver.resolveThisObject = function(callFrame) { 292 Sources.SourceMapNamesResolver.resolveThisObject = function(callFrame) {
302 if (!callFrame) 293 if (!callFrame)
303 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null)); 294 return Promise.resolve(/** @type {?SDK.RemoteObject} */ (null));
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 532 }
542 533
543 /** 534 /**
544 * @override 535 * @override
545 * @return {boolean} 536 * @return {boolean}
546 */ 537 */
547 isNode() { 538 isNode() {
548 return this._object.isNode(); 539 return this._object.isNode();
549 } 540 }
550 }; 541 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sources/ScriptFormatter.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698