Skip to content

Parsing caching #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions stacktrace-gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@
}
}

function _extractLocationInfoFromSourceMap(stackframe, rawSourceMap, sourceCache) {
function _extractLocationInfoFromSourceMap(stackframe, rawSourceMap, sourceCache, mapConsumer) {
return new Promise(function(resolve, reject) {
var mapConsumer = new SourceMap.SourceMapConsumer(rawSourceMap);

var loc = mapConsumer.originalPositionFor({
line: stackframe.lineNumber,
column: stackframe.columnNumber
Expand Down Expand Up @@ -180,6 +178,12 @@

this._atob = opts.atob || _atob;

this.processedSourceMapCache = {};

this.sourceMapConsumerCache = {};

var that = this;

this._get = function _get(location) {
return new Promise(function(resolve, reject) {
var isDataUrl = location.substr(0, 5) === 'data:';
Expand Down Expand Up @@ -282,16 +286,29 @@
if (sourceMappingURL[0] !== '/' && !isDataUrl && !(/^https?:\/\/|^\/\//i).test(sourceMappingURL)) {
sourceMappingURL = base + sourceMappingURL;
}

this._get(sourceMappingURL).then(function(sourceMap) {
if (typeof sourceMap === 'string') {
sourceMap = _parseJson(sourceMap.replace(/^\)\]\}'/, ''));
if(that.processedSourceMapCache[sourceMappingURL]) {
sourceMap = that.processedSourceMapCache[sourceMappingURL];
}
else {
if (typeof sourceMap === 'string') {
sourceMap = _parseJson(sourceMap.replace(/^\)\]\}'/, ''));
}
if (typeof sourceMap.sourceRoot === 'undefined') {
sourceMap.sourceRoot = base;
}
that.processedSourceMapCache[sourceMappingURL] = sourceMap;
}
var sourceMapConsumer;
if(that.sourceMapConsumerCache[sourceMappingURL]) {
sourceMapConsumer = that.sourceMapConsumerCache[sourceMappingURL];
}
if (typeof sourceMap.sourceRoot === 'undefined') {
sourceMap.sourceRoot = base;
else {
sourceMapConsumer = new SourceMap.SourceMapConsumer(sourceMap);
that.sourceMapConsumerCache[sourceMappingURL] = sourceMapConsumer;
}

_extractLocationInfoFromSourceMap(stackframe, sourceMap, sourceCache)
_extractLocationInfoFromSourceMap(stackframe, sourceMap, sourceCache, sourceMapConsumer)
.then(resolve)['catch'](function() {
resolve(stackframe);
});
Expand Down