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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js b/third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js
index 598a8a3fa96359827960c5f5f2a2eedbaf401ea9..dce2f0a658ce891a2a8afb6d364e562eb96d7183 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/SourceMap.js
@@ -27,12 +27,11 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
/**
- * @constructor
+ * @unrestricted
*/
-function SourceMapV3()
-{
+var SourceMapV3 = class {
+ constructor() {
/** @type {number} */ this.version;
/** @type {string|undefined} */ this.file;
/** @type {!Array.<string>} */ this.sources;
@@ -40,142 +39,153 @@ function SourceMapV3()
/** @type {string} */ this.mappings;
/** @type {string|undefined} */ this.sourceRoot;
/** @type {!Array.<string>|undefined} */ this.names;
-}
+ }
+};
/**
- * @constructor
+ * @unrestricted
*/
-SourceMapV3.Section = function()
-{
+SourceMapV3.Section = class {
+ constructor() {
/** @type {!SourceMapV3} */ this.map;
/** @type {!SourceMapV3.Offset} */ this.offset;
+ }
};
/**
- * @constructor
+ * @unrestricted
*/
-SourceMapV3.Offset = function()
-{
+SourceMapV3.Offset = class {
+ constructor() {
/** @type {number} */ this.line;
/** @type {number} */ this.column;
+ }
};
/**
- * @constructor
- * @param {number} lineNumber
- * @param {number} columnNumber
- * @param {string=} sourceURL
- * @param {number=} sourceLineNumber
- * @param {number=} sourceColumnNumber
- * @param {string=} name
+ * @unrestricted
*/
-WebInspector.SourceMapEntry = function(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, name)
-{
+WebInspector.SourceMapEntry = class {
+ /**
+ * @param {number} lineNumber
+ * @param {number} columnNumber
+ * @param {string=} sourceURL
+ * @param {number=} sourceLineNumber
+ * @param {number=} sourceColumnNumber
+ * @param {string=} name
+ */
+ constructor(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, name) {
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
this.sourceURL = sourceURL;
this.sourceLineNumber = sourceLineNumber;
this.sourceColumnNumber = sourceColumnNumber;
this.name = name;
+ }
};
/**
* @interface
*/
-WebInspector.SourceMap = function() { };
+WebInspector.SourceMap = function() {};
WebInspector.SourceMap.prototype = {
- /**
- * @return {string}
- */
- compiledURL: function() { },
-
- /**
- * @return {string}
- */
- url: function() { },
-
- /**
- * @return {!Array<string>}
- */
- sourceURLs: function() { },
-
- /**
- * @param {string} sourceURL
- * @param {!WebInspector.ResourceType} contentType
- * @return {!WebInspector.ContentProvider}
- */
- sourceContentProvider: function(sourceURL, contentType) { },
-
- /**
- * @param {string} sourceURL
- * @return {?string}
- */
- embeddedContentByURL: function(sourceURL) { },
-
- /**
- * @param {number} lineNumber in compiled resource
- * @param {number} columnNumber in compiled resource
- * @return {?WebInspector.SourceMapEntry}
- */
- findEntry: function(lineNumber, columnNumber) { },
-
- /**
- * @return {boolean}
- */
- editable: function() { },
-
- /**
- * @param {!Array<!WebInspector.TextRange>} ranges
- * @param {!Array<string>} texts
- * @return {!Promise<?WebInspector.SourceMap.EditResult>}
- */
- editCompiled: function(ranges, texts) { },
+ /**
+ * @return {string}
+ */
+ compiledURL: function() {},
+
+ /**
+ * @return {string}
+ */
+ url: function() {},
+
+ /**
+ * @return {!Array<string>}
+ */
+ sourceURLs: function() {},
+
+ /**
+ * @param {string} sourceURL
+ * @param {!WebInspector.ResourceType} contentType
+ * @return {!WebInspector.ContentProvider}
+ */
+ sourceContentProvider: function(sourceURL, contentType) {},
+
+ /**
+ * @param {string} sourceURL
+ * @return {?string}
+ */
+ embeddedContentByURL: function(sourceURL) {},
+
+ /**
+ * @param {number} lineNumber in compiled resource
+ * @param {number} columnNumber in compiled resource
+ * @return {?WebInspector.SourceMapEntry}
+ */
+ findEntry: function(lineNumber, columnNumber) {},
+
+ /**
+ * @return {boolean}
+ */
+ editable: function() {},
+
+ /**
+ * @param {!Array<!WebInspector.TextRange>} ranges
+ * @param {!Array<string>} texts
+ * @return {!Promise<?WebInspector.SourceMap.EditResult>}
+ */
+ editCompiled: function(ranges, texts) {},
};
/**
- * @constructor
- * @param {!WebInspector.SourceMap} map
- * @param {!Array<!WebInspector.SourceEdit>} compiledEdits
- * @param {!Map<string, string>} newSources
+ * @unrestricted
*/
-WebInspector.SourceMap.EditResult = function(map, compiledEdits, newSources)
-{
+WebInspector.SourceMap.EditResult = class {
+ /**
+ * @param {!WebInspector.SourceMap} map
+ * @param {!Array<!WebInspector.SourceEdit>} compiledEdits
+ * @param {!Map<string, string>} newSources
+ */
+ constructor(map, compiledEdits, newSources) {
this.map = map;
this.compiledEdits = compiledEdits;
this.newSources = newSources;
+ }
};
/**
* @interface
*/
-WebInspector.SourceMapFactory = function() { };
+WebInspector.SourceMapFactory = function() {};
WebInspector.SourceMapFactory.prototype = {
- /**
- * @param {!WebInspector.Target} target
- * @param {!WebInspector.SourceMap} sourceMap
- * @return {!Promise<?WebInspector.SourceMap>}
- */
- editableSourceMap: function(target, sourceMap) { },
+ /**
+ * @param {!WebInspector.Target} target
+ * @param {!WebInspector.SourceMap} sourceMap
+ * @return {!Promise<?WebInspector.SourceMap>}
+ */
+ editableSourceMap: function(target, sourceMap) {},
};
/**
- * Implements Source Map V3 model. See https://github.com/google/closure-compiler/wiki/Source-Maps
- * for format description.
- * @constructor
* @implements {WebInspector.SourceMap}
- * @param {string} compiledURL
- * @param {string} sourceMappingURL
- * @param {!SourceMapV3} payload
+ * @unrestricted
*/
-WebInspector.TextSourceMap = function(compiledURL, sourceMappingURL, payload)
-{
- if (!WebInspector.TextSourceMap.prototype._base64Map) {
- const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- WebInspector.TextSourceMap.prototype._base64Map = {};
- for (var i = 0; i < base64Digits.length; ++i)
- WebInspector.TextSourceMap.prototype._base64Map[base64Digits.charAt(i)] = i;
+WebInspector.TextSourceMap = class {
+ /**
+ * Implements Source Map V3 model. See https://github.com/google/closure-compiler/wiki/Source-Maps
+ * for format description.
+ * @param {string} compiledURL
+ * @param {string} sourceMappingURL
+ * @param {!SourceMapV3} payload
+ */
+ constructor(compiledURL, sourceMappingURL, payload) {
+ if (!WebInspector.TextSourceMap._base64Map) {
+ const base64Digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
+ WebInspector.TextSourceMap._base64Map = {};
+ for (var i = 0; i < base64Digits.length; ++i)
+ WebInspector.TextSourceMap._base64Map[base64Digits.charAt(i)] = i;
}
this._json = payload;
@@ -186,16 +196,15 @@ WebInspector.TextSourceMap = function(compiledURL, sourceMappingURL, payload)
/** @type {!Map<string, !WebInspector.TextSourceMap.SourceInfo>} */
this._sourceInfos = new Map();
this._eachSection(this._parseSources.bind(this));
-};
-
-/**
- * @param {string} sourceMapURL
- * @param {string} compiledURL
- * @return {!Promise<?WebInspector.TextSourceMap>}
- * @this {WebInspector.TextSourceMap}
- */
-WebInspector.TextSourceMap.load = function(sourceMapURL, compiledURL)
-{
+ }
+
+ /**
+ * @param {string} sourceMapURL
+ * @param {string} compiledURL
+ * @return {!Promise<?WebInspector.TextSourceMap>}
+ * @this {WebInspector.TextSourceMap}
+ */
+ static load(sourceMapURL, compiledURL) {
var callback;
var promise = new Promise(fulfill => callback = fulfill);
WebInspector.multitargetNetworkManager.loadResource(sourceMapURL, contentLoaded);
@@ -206,392 +215,382 @@ WebInspector.TextSourceMap.load = function(sourceMapURL, compiledURL)
* @param {!Object.<string, string>} headers
* @param {string} content
*/
- function contentLoaded(statusCode, headers, content)
- {
- if (!content || statusCode >= 400) {
- callback(null);
- return;
- }
-
- if (content.slice(0, 3) === ")]}")
- content = content.substring(content.indexOf("\n"));
- try {
- var payload = /** @type {!SourceMapV3} */ (JSON.parse(content));
- var baseURL = sourceMapURL.startsWith("data:") ? compiledURL : sourceMapURL;
- callback(new WebInspector.TextSourceMap(compiledURL, baseURL, payload));
- } catch (e) {
- console.error(e);
- WebInspector.console.warn("DevTools failed to parse SourceMap: " + sourceMapURL);
- callback(null);
- }
+ function contentLoaded(statusCode, headers, content) {
+ if (!content || statusCode >= 400) {
+ callback(null);
+ return;
+ }
+
+ if (content.slice(0, 3) === ')]}')
+ content = content.substring(content.indexOf('\n'));
+ try {
+ var payload = /** @type {!SourceMapV3} */ (JSON.parse(content));
+ var baseURL = sourceMapURL.startsWith('data:') ? compiledURL : sourceMapURL;
+ callback(new WebInspector.TextSourceMap(compiledURL, baseURL, payload));
+ } catch (e) {
+ console.error(e);
+ WebInspector.console.warn('DevTools failed to parse SourceMap: ' + sourceMapURL);
+ callback(null);
+ }
}
-};
-
-WebInspector.TextSourceMap.prototype = {
- /**
- * @override
- * @return {string}
- */
- compiledURL: function()
- {
- return this._compiledURL;
- },
-
- /**
- * @override
- * @return {string}
- */
- url: function()
- {
- return this._sourceMappingURL;
- },
-
- /**
- * @override
- * @return {!Array.<string>}
- */
- sourceURLs: function()
- {
- return this._sourceInfos.keysArray();
- },
-
- /**
- * @override
- * @param {string} sourceURL
- * @param {!WebInspector.ResourceType} contentType
- * @return {!WebInspector.ContentProvider}
- */
- sourceContentProvider: function(sourceURL, contentType)
- {
- var info = this._sourceInfos.get(sourceURL);
- if (info.content)
- return WebInspector.StaticContentProvider.fromString(sourceURL, contentType, info.content);
- return new WebInspector.CompilerSourceMappingContentProvider(sourceURL, contentType);
- },
-
- /**
- * @override
- * @param {string} sourceURL
- * @return {?string}
- */
- embeddedContentByURL: function(sourceURL)
- {
- if (!this._sourceInfos.has(sourceURL))
- return null;
- return this._sourceInfos.get(sourceURL).content;
- },
-
- /**
- * @override
- * @return {boolean}
- */
- editable: function()
- {
- return false;
- },
-
- /**
- * @override
- * @param {!Array<!WebInspector.TextRange>} ranges
- * @param {!Array<string>} texts
- * @return {!Promise<?WebInspector.SourceMap.EditResult>}
- */
- editCompiled: function(ranges, texts)
- {
- return Promise.resolve(/** @type {?WebInspector.SourceMap.EditResult} */(null));
- },
-
- /**
- * @override
- * @param {number} lineNumber in compiled resource
- * @param {number} columnNumber in compiled resource
- * @return {?WebInspector.SourceMapEntry}
- */
- findEntry: function(lineNumber, columnNumber)
- {
- var first = 0;
- var mappings = this.mappings();
- var count = mappings.length;
- while (count > 1) {
- var step = count >> 1;
- var middle = first + step;
- var mapping = mappings[middle];
- if (lineNumber < mapping.lineNumber || (lineNumber === mapping.lineNumber && columnNumber < mapping.columnNumber)) {
- count = step;
- } else {
- first = middle;
- count -= step;
- }
- }
- var entry = mappings[first];
- if (!first && entry && (lineNumber < entry.lineNumber || (lineNumber === entry.lineNumber && columnNumber < entry.columnNumber)))
- return null;
- return entry;
- },
+ }
+
+ /**
+ * @override
+ * @return {string}
+ */
+ compiledURL() {
+ return this._compiledURL;
+ }
+
+ /**
+ * @override
+ * @return {string}
+ */
+ url() {
+ return this._sourceMappingURL;
+ }
+
+ /**
+ * @override
+ * @return {!Array.<string>}
+ */
+ sourceURLs() {
+ return this._sourceInfos.keysArray();
+ }
+
+ /**
+ * @override
+ * @param {string} sourceURL
+ * @param {!WebInspector.ResourceType} contentType
+ * @return {!WebInspector.ContentProvider}
+ */
+ sourceContentProvider(sourceURL, contentType) {
+ var info = this._sourceInfos.get(sourceURL);
+ if (info.content)
+ return WebInspector.StaticContentProvider.fromString(sourceURL, contentType, info.content);
+ return new WebInspector.CompilerSourceMappingContentProvider(sourceURL, contentType);
+ }
+
+ /**
+ * @override
+ * @param {string} sourceURL
+ * @return {?string}
+ */
+ embeddedContentByURL(sourceURL) {
+ if (!this._sourceInfos.has(sourceURL))
+ return null;
+ return this._sourceInfos.get(sourceURL).content;
+ }
+
+ /**
+ * @override
+ * @return {boolean}
+ */
+ editable() {
+ return false;
+ }
+
+ /**
+ * @override
+ * @param {!Array<!WebInspector.TextRange>} ranges
+ * @param {!Array<string>} texts
+ * @return {!Promise<?WebInspector.SourceMap.EditResult>}
+ */
+ editCompiled(ranges, texts) {
+ return Promise.resolve(/** @type {?WebInspector.SourceMap.EditResult} */ (null));
+ }
+
+ /**
+ * @override
+ * @param {number} lineNumber in compiled resource
+ * @param {number} columnNumber in compiled resource
+ * @return {?WebInspector.SourceMapEntry}
+ */
+ findEntry(lineNumber, columnNumber) {
+ var first = 0;
+ var mappings = this.mappings();
+ var count = mappings.length;
+ while (count > 1) {
+ var step = count >> 1;
+ var middle = first + step;
+ var mapping = mappings[middle];
+ if (lineNumber < mapping.lineNumber ||
+ (lineNumber === mapping.lineNumber && columnNumber < mapping.columnNumber)) {
+ count = step;
+ } else {
+ first = middle;
+ count -= step;
+ }
+ }
+ var entry = mappings[first];
+ if (!first && entry &&
+ (lineNumber < entry.lineNumber || (lineNumber === entry.lineNumber && columnNumber < entry.columnNumber)))
+ return null;
+ return entry;
+ }
+
+ /**
+ * @param {string} sourceURL
+ * @param {number} lineNumber
+ * @return {?WebInspector.SourceMapEntry}
+ */
+ firstSourceLineMapping(sourceURL, lineNumber) {
+ var mappings = this._reversedMappings(sourceURL);
+ var index = mappings.lowerBound(lineNumber, lineComparator);
+ if (index >= mappings.length || mappings[index].sourceLineNumber !== lineNumber)
+ return null;
+ return mappings[index];
/**
- * @param {string} sourceURL
* @param {number} lineNumber
- * @return {?WebInspector.SourceMapEntry}
- */
- firstSourceLineMapping: function(sourceURL, lineNumber)
- {
- var mappings = this._reversedMappings(sourceURL);
- var index = mappings.lowerBound(lineNumber, lineComparator);
- if (index >= mappings.length || mappings[index].sourceLineNumber !== lineNumber)
- return null;
- return mappings[index];
-
- /**
- * @param {number} lineNumber
- * @param {!WebInspector.SourceMapEntry} mapping
- * @return {number}
- */
- function lineComparator(lineNumber, mapping)
- {
- return lineNumber - mapping.sourceLineNumber;
- }
- },
-
- /**
- * @return {!Array<!WebInspector.SourceMapEntry>}
- */
- mappings: function()
- {
- if (this._mappings === null) {
- this._mappings = [];
- this._eachSection(this._parseMap.bind(this));
- this._json = null;
- }
- return /** @type {!Array<!WebInspector.SourceMapEntry>} */ (this._mappings);
- },
-
- /**
- * @param {string} sourceURL
- * @return {!Array.<!WebInspector.SourceMapEntry>}
+ * @param {!WebInspector.SourceMapEntry} mapping
+ * @return {number}
*/
- _reversedMappings: function(sourceURL)
- {
- if (!this._sourceInfos.has(sourceURL))
- return [];
- var mappings = this.mappings();
- var info = this._sourceInfos.get(sourceURL);
- if (info.reverseMappings === null)
- info.reverseMappings = mappings.filter((mapping) => mapping.sourceURL === sourceURL).sort(sourceMappingComparator);
- return info.reverseMappings;
-
- /**
- * @param {!WebInspector.SourceMapEntry} a
- * @param {!WebInspector.SourceMapEntry} b
- * @return {number}
- */
- function sourceMappingComparator(a, b)
- {
- if (a.sourceLineNumber !== b.sourceLineNumber)
- return a.sourceLineNumber - b.sourceLineNumber;
- if (a.sourceColumnNumber !== b.sourceColumnNumber)
- return a.sourceColumnNumber - b.sourceColumnNumber;
-
- if (a.lineNumber !== b.lineNumber)
- return a.lineNumber - b.lineNumber;
-
- return a.columnNumber - b.columnNumber;
- }
- },
+ function lineComparator(lineNumber, mapping) {
+ return lineNumber - mapping.sourceLineNumber;
+ }
+ }
+
+ /**
+ * @return {!Array<!WebInspector.SourceMapEntry>}
+ */
+ mappings() {
+ if (this._mappings === null) {
+ this._mappings = [];
+ this._eachSection(this._parseMap.bind(this));
+ this._json = null;
+ }
+ return /** @type {!Array<!WebInspector.SourceMapEntry>} */ (this._mappings);
+ }
+
+ /**
+ * @param {string} sourceURL
+ * @return {!Array.<!WebInspector.SourceMapEntry>}
+ */
+ _reversedMappings(sourceURL) {
+ if (!this._sourceInfos.has(sourceURL))
+ return [];
+ var mappings = this.mappings();
+ var info = this._sourceInfos.get(sourceURL);
+ if (info.reverseMappings === null)
+ info.reverseMappings =
+ mappings.filter((mapping) => mapping.sourceURL === sourceURL).sort(sourceMappingComparator);
+ return info.reverseMappings;
/**
- * @param {function(!SourceMapV3, number, number)} callback
+ * @param {!WebInspector.SourceMapEntry} a
+ * @param {!WebInspector.SourceMapEntry} b
+ * @return {number}
*/
- _eachSection: function(callback) {
- if (!this._json.sections) {
- callback(this._json, 0, 0);
- return;
- }
- for (var section of this._json.sections)
- callback(section.map, section.offset.line, section.offset.column);
- },
+ function sourceMappingComparator(a, b) {
+ if (a.sourceLineNumber !== b.sourceLineNumber)
+ return a.sourceLineNumber - b.sourceLineNumber;
+ if (a.sourceColumnNumber !== b.sourceColumnNumber)
+ return a.sourceColumnNumber - b.sourceColumnNumber;
- /**
- * @param {!SourceMapV3} sourceMap
- */
- _parseSources: function(sourceMap) {
- var sourcesList = [];
- var sourceRoot = sourceMap.sourceRoot || "";
- if (sourceRoot && !sourceRoot.endsWith("/"))
- sourceRoot += "/";
- for (var i = 0; i < sourceMap.sources.length; ++i) {
- var href = sourceRoot + sourceMap.sources[i];
- var url = WebInspector.ParsedURL.completeURL(this._sourceMappingURL, href) || href;
- var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
- if (url === this._compiledURL && source)
- url += WebInspector.UIString(" [sm]");
- this._sourceInfos.set(url, new WebInspector.TextSourceMap.SourceInfo(source, null));
- sourcesList.push(url);
- }
- sourceMap[WebInspector.TextSourceMap._sourcesListSymbol] = sourcesList;
- },
+ if (a.lineNumber !== b.lineNumber)
+ return a.lineNumber - b.lineNumber;
- /**
- * @param {!SourceMapV3} map
- * @param {number} lineNumber
- * @param {number} columnNumber
- */
- _parseMap: function(map, lineNumber, columnNumber)
- {
- var sourceIndex = 0;
- var sourceLineNumber = 0;
- var sourceColumnNumber = 0;
- var nameIndex = 0;
- var sources = map[WebInspector.TextSourceMap._sourcesListSymbol];
- var names = map.names || [];
- var stringCharIterator = new WebInspector.TextSourceMap.StringCharIterator(map.mappings);
- var sourceURL = sources[sourceIndex];
-
- while (true) {
- if (stringCharIterator.peek() === ",")
- stringCharIterator.next();
- else {
- while (stringCharIterator.peek() === ";") {
- lineNumber += 1;
- columnNumber = 0;
- stringCharIterator.next();
- }
- if (!stringCharIterator.hasNext())
- break;
- }
-
- columnNumber += this._decodeVLQ(stringCharIterator);
- if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
- this._mappings.push(new WebInspector.SourceMapEntry(lineNumber, columnNumber));
- continue;
- }
-
- var sourceIndexDelta = this._decodeVLQ(stringCharIterator);
- if (sourceIndexDelta) {
- sourceIndex += sourceIndexDelta;
- sourceURL = sources[sourceIndex];
- }
- sourceLineNumber += this._decodeVLQ(stringCharIterator);
- sourceColumnNumber += this._decodeVLQ(stringCharIterator);
-
- if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
- this._mappings.push(new WebInspector.SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber));
- continue;
- }
-
- nameIndex += this._decodeVLQ(stringCharIterator);
- this._mappings.push(new WebInspector.SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
+ return a.columnNumber - b.columnNumber;
+ }
+ }
+
+ /**
+ * @param {function(!SourceMapV3, number, number)} callback
+ */
+ _eachSection(callback) {
+ if (!this._json.sections) {
+ callback(this._json, 0, 0);
+ return;
+ }
+ for (var section of this._json.sections)
+ callback(section.map, section.offset.line, section.offset.column);
+ }
+
+ /**
+ * @param {!SourceMapV3} sourceMap
+ */
+ _parseSources(sourceMap) {
+ var sourcesList = [];
+ var sourceRoot = sourceMap.sourceRoot || '';
+ if (sourceRoot && !sourceRoot.endsWith('/'))
+ sourceRoot += '/';
+ for (var i = 0; i < sourceMap.sources.length; ++i) {
+ var href = sourceRoot + sourceMap.sources[i];
+ var url = WebInspector.ParsedURL.completeURL(this._sourceMappingURL, href) || href;
+ var source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
+ if (url === this._compiledURL && source)
+ url += WebInspector.UIString(' [sm]');
+ this._sourceInfos.set(url, new WebInspector.TextSourceMap.SourceInfo(source, null));
+ sourcesList.push(url);
+ }
+ sourceMap[WebInspector.TextSourceMap._sourcesListSymbol] = sourcesList;
+ }
+
+ /**
+ * @param {!SourceMapV3} map
+ * @param {number} lineNumber
+ * @param {number} columnNumber
+ */
+ _parseMap(map, lineNumber, columnNumber) {
+ var sourceIndex = 0;
+ var sourceLineNumber = 0;
+ var sourceColumnNumber = 0;
+ var nameIndex = 0;
+ var sources = map[WebInspector.TextSourceMap._sourcesListSymbol];
+ var names = map.names || [];
+ var stringCharIterator = new WebInspector.TextSourceMap.StringCharIterator(map.mappings);
+ var sourceURL = sources[sourceIndex];
+
+ while (true) {
+ if (stringCharIterator.peek() === ',')
+ stringCharIterator.next();
+ else {
+ while (stringCharIterator.peek() === ';') {
+ lineNumber += 1;
+ columnNumber = 0;
+ stringCharIterator.next();
}
- },
-
- /**
- * @param {string} char
- * @return {boolean}
- */
- _isSeparator: function(char)
- {
- return char === "," || char === ";";
- },
-
+ if (!stringCharIterator.hasNext())
+ break;
+ }
+
+ columnNumber += this._decodeVLQ(stringCharIterator);
+ if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
+ this._mappings.push(new WebInspector.SourceMapEntry(lineNumber, columnNumber));
+ continue;
+ }
+
+ var sourceIndexDelta = this._decodeVLQ(stringCharIterator);
+ if (sourceIndexDelta) {
+ sourceIndex += sourceIndexDelta;
+ sourceURL = sources[sourceIndex];
+ }
+ sourceLineNumber += this._decodeVLQ(stringCharIterator);
+ sourceColumnNumber += this._decodeVLQ(stringCharIterator);
+
+ if (!stringCharIterator.hasNext() || this._isSeparator(stringCharIterator.peek())) {
+ this._mappings.push(
+ new WebInspector.SourceMapEntry(lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber));
+ continue;
+ }
+
+ nameIndex += this._decodeVLQ(stringCharIterator);
+ this._mappings.push(new WebInspector.SourceMapEntry(
+ lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex]));
+ }
+ }
+
+ /**
+ * @param {string} char
+ * @return {boolean}
+ */
+ _isSeparator(char) {
+ return char === ',' || char === ';';
+ }
+
+ /**
+ * @param {!WebInspector.TextSourceMap.StringCharIterator} stringCharIterator
+ * @return {number}
+ */
+ _decodeVLQ(stringCharIterator) {
+ // Read unsigned value.
+ var result = 0;
+ var shift = 0;
+ do {
+ var digit = WebInspector.TextSourceMap._base64Map[stringCharIterator.next()];
+ result += (digit & WebInspector.TextSourceMap._VLQ_BASE_MASK) << shift;
+ shift += WebInspector.TextSourceMap._VLQ_BASE_SHIFT;
+ } while (digit & WebInspector.TextSourceMap._VLQ_CONTINUATION_MASK);
+
+ // Fix the sign.
+ var negative = result & 1;
+ result >>= 1;
+ return negative ? -result : result;
+ }
+
+ /**
+ * @param {string} url
+ * @param {!WebInspector.TextRange} textRange
+ * @return {!WebInspector.TextRange}
+ */
+ reverseMapTextRange(url, textRange) {
/**
- * @param {!WebInspector.TextSourceMap.StringCharIterator} stringCharIterator
+ * @param {!{lineNumber: number, columnNumber: number}} position
+ * @param {!WebInspector.SourceMapEntry} mapping
* @return {number}
*/
- _decodeVLQ: function(stringCharIterator)
- {
- // Read unsigned value.
- var result = 0;
- var shift = 0;
- do {
- var digit = this._base64Map[stringCharIterator.next()];
- result += (digit & this._VLQ_BASE_MASK) << shift;
- shift += this._VLQ_BASE_SHIFT;
- } while (digit & this._VLQ_CONTINUATION_MASK);
-
- // Fix the sign.
- var negative = result & 1;
- result >>= 1;
- return negative ? -result : result;
- },
-
- /**
- * @param {string} url
- * @param {!WebInspector.TextRange} textRange
- * @return {!WebInspector.TextRange}
- */
- reverseMapTextRange: function(url, textRange)
- {
- /**
- * @param {!{lineNumber: number, columnNumber: number}} position
- * @param {!WebInspector.SourceMapEntry} mapping
- * @return {number}
- */
- function comparator(position, mapping)
- {
- if (position.lineNumber !== mapping.sourceLineNumber)
- return position.lineNumber - mapping.sourceLineNumber;
-
- return position.columnNumber - mapping.sourceColumnNumber;
- }
+ function comparator(position, mapping) {
+ if (position.lineNumber !== mapping.sourceLineNumber)
+ return position.lineNumber - mapping.sourceLineNumber;
- var mappings = this._reversedMappings(url);
- var startIndex = mappings.lowerBound({lineNumber: textRange.startLine, columnNumber: textRange.startColumn}, comparator);
- var endIndex = mappings.upperBound({lineNumber: textRange.endLine, columnNumber: textRange.endColumn}, comparator);
+ return position.columnNumber - mapping.sourceColumnNumber;
+ }
- var startMapping = mappings[startIndex];
- var endMapping = mappings[endIndex];
- return new WebInspector.TextRange(startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumber, endMapping.columnNumber);
- },
+ var mappings = this._reversedMappings(url);
+ var startIndex =
+ mappings.lowerBound({lineNumber: textRange.startLine, columnNumber: textRange.startColumn}, comparator);
+ var endIndex = mappings.upperBound({lineNumber: textRange.endLine, columnNumber: textRange.endColumn}, comparator);
- _VLQ_BASE_SHIFT: 5,
- _VLQ_BASE_MASK: (1 << 5) - 1,
- _VLQ_CONTINUATION_MASK: 1 << 5
+ var startMapping = mappings[startIndex];
+ var endMapping = mappings[endIndex];
+ return new WebInspector.TextRange(
+ startMapping.lineNumber, startMapping.columnNumber, endMapping.lineNumber, endMapping.columnNumber);
+ }
};
+WebInspector.TextSourceMap._VLQ_BASE_SHIFT = 5;
+WebInspector.TextSourceMap._VLQ_BASE_MASK = (1 << 5) - 1;
+WebInspector.TextSourceMap._VLQ_CONTINUATION_MASK = 1 << 5;
+
+
/**
- * @constructor
- * @param {string} string
+ * @unrestricted
*/
-WebInspector.TextSourceMap.StringCharIterator = function(string)
-{
+WebInspector.TextSourceMap.StringCharIterator = class {
+ /**
+ * @param {string} string
+ */
+ constructor(string) {
this._string = string;
this._position = 0;
-};
-
-WebInspector.TextSourceMap.StringCharIterator.prototype = {
- /**
- * @return {string}
- */
- next: function()
- {
- return this._string.charAt(this._position++);
- },
-
- /**
- * @return {string}
- */
- peek: function()
- {
- return this._string.charAt(this._position);
- },
-
- /**
- * @return {boolean}
- */
- hasNext: function()
- {
- return this._position < this._string.length;
- }
+ }
+
+ /**
+ * @return {string}
+ */
+ next() {
+ return this._string.charAt(this._position++);
+ }
+
+ /**
+ * @return {string}
+ */
+ peek() {
+ return this._string.charAt(this._position);
+ }
+
+ /**
+ * @return {boolean}
+ */
+ hasNext() {
+ return this._position < this._string.length;
+ }
};
/**
- * @constructor
- * @param {?string} content
- * @param {?Array<!WebInspector.SourceMapEntry>} reverseMappings
+ * @unrestricted
*/
-WebInspector.TextSourceMap.SourceInfo = function(content, reverseMappings) {
+WebInspector.TextSourceMap.SourceInfo = class {
+ /**
+ * @param {?string} content
+ * @param {?Array<!WebInspector.SourceMapEntry>} reverseMappings
+ */
+ constructor(content, reverseMappings) {
this.content = content;
this.reverseMappings = reverseMappings;
+ }
};
-WebInspector.TextSourceMap._sourcesListSymbol = Symbol("sourcesList");
+WebInspector.TextSourceMap._sourcesListSymbol = Symbol('sourcesList');

Powered by Google App Engine
This is Rietveld 408576698