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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js

Issue 2604883002: DevTools: namespace globals (Closed)
Patch Set: address CL feedback Created 3 years, 12 months 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
OLDNEW
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 var SourceMapV3 = class { 34 SDK.SourceMapV3 = class {
35 constructor() { 35 constructor() {
36 /** @type {number} */ this.version; 36 /** @type {number} */ this.version;
37 /** @type {string|undefined} */ this.file; 37 /** @type {string|undefined} */ this.file;
38 /** @type {!Array.<string>} */ this.sources; 38 /** @type {!Array.<string>} */ this.sources;
39 /** @type {!Array.<!SourceMapV3.Section>|undefined} */ this.sections; 39 /** @type {!Array.<!SDK.SourceMapV3.Section>|undefined} */ this.sections;
40 /** @type {string} */ this.mappings; 40 /** @type {string} */ this.mappings;
41 /** @type {string|undefined} */ this.sourceRoot; 41 /** @type {string|undefined} */ this.sourceRoot;
42 /** @type {!Array.<string>|undefined} */ this.names; 42 /** @type {!Array.<string>|undefined} */ this.names;
43 } 43 }
44 }; 44 };
45 45
46 /** 46 /**
47 * @unrestricted 47 * @unrestricted
48 */ 48 */
49 SourceMapV3.Section = class { 49 SDK.SourceMapV3.Section = class {
50 constructor() { 50 constructor() {
51 /** @type {!SourceMapV3} */ this.map; 51 /** @type {!SDK.SourceMapV3} */ this.map;
52 /** @type {!SourceMapV3.Offset} */ this.offset; 52 /** @type {!SDK.SourceMapV3.Offset} */ this.offset;
53 } 53 }
54 }; 54 };
55 55
56 /** 56 /**
57 * @unrestricted 57 * @unrestricted
58 */ 58 */
59 SourceMapV3.Offset = class { 59 SDK.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 SDK.SourceMapEntry = class { 69 SDK.SourceMapEntry = class {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 /** 172 /**
173 * @implements {SDK.SourceMap} 173 * @implements {SDK.SourceMap}
174 * @unrestricted 174 * @unrestricted
175 */ 175 */
176 SDK.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 {!SDK.SourceMapV3} payload
183 */ 183 */
184 constructor(compiledURL, sourceMappingURL, payload) { 184 constructor(compiledURL, sourceMappingURL, payload) {
185 if (!SDK.TextSourceMap._base64Map) { 185 if (!SDK.TextSourceMap._base64Map) {
186 const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789+/'; 186 const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0123456789+/';
187 SDK.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 SDK.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;
(...skipping 25 matching lines...) Expand all
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 {!SDK.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 SDK.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 Common.console.warn('DevTools failed to parse SourceMap: ' + sourceMapUR L); 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
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 return a.sourceColumnNumber - b.sourceColumnNumber; 392 return a.sourceColumnNumber - b.sourceColumnNumber;
393 393
394 if (a.lineNumber !== b.lineNumber) 394 if (a.lineNumber !== b.lineNumber)
395 return a.lineNumber - b.lineNumber; 395 return a.lineNumber - b.lineNumber;
396 396
397 return a.columnNumber - b.columnNumber; 397 return a.columnNumber - b.columnNumber;
398 } 398 }
399 } 399 }
400 400
401 /** 401 /**
402 * @param {function(!SourceMapV3, number, number)} callback 402 * @param {function(!SDK.SourceMapV3, number, number)} callback
403 */ 403 */
404 _eachSection(callback) { 404 _eachSection(callback) {
405 if (!this._json.sections) { 405 if (!this._json.sections) {
406 callback(this._json, 0, 0); 406 callback(this._json, 0, 0);
407 return; 407 return;
408 } 408 }
409 for (var section of this._json.sections) 409 for (var section of this._json.sections)
410 callback(section.map, section.offset.line, section.offset.column); 410 callback(section.map, section.offset.line, section.offset.column);
411 } 411 }
412 412
413 /** 413 /**
414 * @param {!SourceMapV3} sourceMap 414 * @param {!SDK.SourceMapV3} sourceMap
415 */ 415 */
416 _parseSources(sourceMap) { 416 _parseSources(sourceMap) {
417 var sourcesList = []; 417 var sourcesList = [];
418 var sourceRoot = sourceMap.sourceRoot || ''; 418 var sourceRoot = sourceMap.sourceRoot || '';
419 if (sourceRoot && !sourceRoot.endsWith('/')) 419 if (sourceRoot && !sourceRoot.endsWith('/'))
420 sourceRoot += '/'; 420 sourceRoot += '/';
421 for (var i = 0; i < sourceMap.sources.length; ++i) { 421 for (var i = 0; i < sourceMap.sources.length; ++i) {
422 var href = sourceRoot + sourceMap.sources[i]; 422 var href = sourceRoot + sourceMap.sources[i];
423 var url = Common.ParsedURL.completeURL(this._sourceMappingURL, href) || hr ef; 423 var url = Common.ParsedURL.completeURL(this._sourceMappingURL, href) || hr ef;
424 var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i]; 424 var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
425 if (url === this._compiledURL && source) 425 if (url === this._compiledURL && source)
426 url += Common.UIString(' [sm]'); 426 url += Common.UIString(' [sm]');
427 this._sourceInfos.set(url, new SDK.TextSourceMap.SourceInfo(source, null)) ; 427 this._sourceInfos.set(url, new SDK.TextSourceMap.SourceInfo(source, null)) ;
428 sourcesList.push(url); 428 sourcesList.push(url);
429 } 429 }
430 sourceMap[SDK.TextSourceMap._sourcesListSymbol] = sourcesList; 430 sourceMap[SDK.TextSourceMap._sourcesListSymbol] = sourcesList;
431 } 431 }
432 432
433 /** 433 /**
434 * @param {!SourceMapV3} map 434 * @param {!SDK.SourceMapV3} map
435 * @param {number} lineNumber 435 * @param {number} lineNumber
436 * @param {number} columnNumber 436 * @param {number} columnNumber
437 */ 437 */
438 _parseMap(map, lineNumber, columnNumber) { 438 _parseMap(map, lineNumber, columnNumber) {
439 var sourceIndex = 0; 439 var sourceIndex = 0;
440 var sourceLineNumber = 0; 440 var sourceLineNumber = 0;
441 var sourceColumnNumber = 0; 441 var sourceColumnNumber = 0;
442 var nameIndex = 0; 442 var nameIndex = 0;
443 var sources = map[SDK.TextSourceMap._sourcesListSymbol]; 443 var sources = map[SDK.TextSourceMap._sourcesListSymbol];
444 var names = map.names || []; 444 var names = map.names || [];
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 * @param {?string} content 589 * @param {?string} content
590 * @param {?Array<!SDK.SourceMapEntry>} reverseMappings 590 * @param {?Array<!SDK.SourceMapEntry>} reverseMappings
591 */ 591 */
592 constructor(content, reverseMappings) { 592 constructor(content, reverseMappings) {
593 this.content = content; 593 this.content = content;
594 this.reverseMappings = reverseMappings; 594 this.reverseMappings = reverseMappings;
595 } 595 }
596 }; 596 };
597 597
598 SDK.TextSourceMap._sourcesListSymbol = Symbol('sourcesList'); 598 SDK.TextSourceMap._sourcesListSymbol = Symbol('sourcesList');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698