From adba5772a7f9969ba70f3707c89afc624a52da24 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Thu, 2 Feb 2017 01:00:59 +0100 Subject: [PATCH] devtools: don't assume monotonic mappings in SDK.TextSourceMap._parseMap Some nasty source maps generated by ClojureScript really use negative indices. issue #53 --- .../devtools/front_end/sdk/SourceMap.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resources/unpacked/devtools/front_end/sdk/SourceMap.js b/resources/unpacked/devtools/front_end/sdk/SourceMap.js index 1bf78db4c1..8fa3a5a1e9 100644 --- a/resources/unpacked/devtools/front_end/sdk/SourceMap.js +++ b/resources/unpacked/devtools/front_end/sdk/SourceMap.js @@ -497,6 +497,23 @@ SDK.TextSourceMap = class { this._mappings.push(new SDK.SourceMapEntry( lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, names[nameIndex])); } + + // we have to sort the mappings for findEntry + // some source maps don't have monotonic mappings, + // _decodeVLQ might return negative values when updating columnNumber + // AFAIK, spec here does not disallow it: + // https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit + this._mappings.sort((a, b) => { + const al = a.lineNumber; + const bl = b.lineNumber; + const ac = a.columnNumber; + const bc = b.columnNumber; + if (al < bl || (al === bl && ac < bc)) { + return -1; + } else { + return 1; + } + }); } /**