sourcemapped-stacktrace
Advanced tools
Comparing version 1.1.8 to 1.1.9
{ | ||
"name": "sourcemapped-stacktrace", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"homepage": "https://github.com/novocaine/sourcemapped-stacktrace", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -33,2 +33,3 @@ /* | ||
* @param {boolean} [opts.cacheGlobally] - Whether to cache sourcemaps globally across multiple calls. | ||
* @param {boolean} [opts.sync] - Whether to use synchronous ajax to load the sourcemaps. | ||
*/ | ||
@@ -46,6 +47,3 @@ var mapStackTrace = function(stack, done, opts) { | ||
var fetcher = new Fetcher(function() { | ||
var result = processSourceMaps(lines, rows, fetcher.mapForUri); | ||
done(result); | ||
}, opts); | ||
var fetcher = new Fetcher(opts); | ||
@@ -81,7 +79,6 @@ if (isChromeOrEdge() || isIE11Plus()) { | ||
// if opts.cacheGlobally set, all maps could have been cached already, | ||
// thus we need to call done callback right away | ||
if ( fetcher.sem === 0 ) { | ||
fetcher.done(fetcher.mapForUri); | ||
} | ||
fetcher.sem.whenReady(function() { | ||
var result = processSourceMaps(lines, rows, fetcher.mapForUri); | ||
done(result); | ||
}); | ||
}; | ||
@@ -105,11 +102,51 @@ | ||
var Fetcher = function(done, opts) { | ||
this.sem = 0; | ||
var Semaphore = function() { | ||
this.count = 0; | ||
this.pending = []; | ||
}; | ||
Semaphore.prototype.incr = function() { | ||
this.count++; | ||
}; | ||
Semaphore.prototype.decr = function() { | ||
this.count--; | ||
this.flush(); | ||
}; | ||
Semaphore.prototype.whenReady = function(fn) { | ||
this.pending.push(fn); | ||
this.flush(); | ||
}; | ||
Semaphore.prototype.flush = function() { | ||
if (this.count === 0) { | ||
this.pending.forEach(function(fn) { fn(); }); | ||
this.pending = []; | ||
} | ||
}; | ||
var Fetcher = function(opts) { | ||
this.sem = new Semaphore(); | ||
this.sync = opts && opts.sync; | ||
this.mapForUri = opts && opts.cacheGlobally ? global_mapForUri : {}; | ||
this.done = done; | ||
}; | ||
Fetcher.prototype.ajax = function(uri, callback) { | ||
var xhr = createXMLHTTPObject(); | ||
var that = this; | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState == 4) { | ||
callback.call(that, xhr, uri); | ||
} | ||
}; | ||
xhr.open("GET", uri, !this.sync); | ||
xhr.send(); | ||
} | ||
Fetcher.prototype.fetchScript = function(uri) { | ||
if (!(uri in this.mapForUri)) { | ||
this.sem++; | ||
this.sem.incr(); | ||
this.mapForUri[uri] = null; | ||
@@ -120,9 +157,3 @@ } else { | ||
var xhr = createXMLHTTPObject(); | ||
var that = this; | ||
xhr.onreadystatechange = function(e) { | ||
that.onScriptLoad.call(that, e, uri); | ||
}; | ||
xhr.open("GET", uri, true); | ||
xhr.send(); | ||
this.ajax(uri, this.onScriptLoad); | ||
}; | ||
@@ -132,10 +163,4 @@ | ||
Fetcher.prototype.onScriptLoad = function(e, uri) { | ||
if (e.target.readyState !== 4) { | ||
return; | ||
} | ||
if (e.target.status === 200 || | ||
(uri.slice(0, 7) === "file://" && e.target.status === 0)) | ||
{ | ||
Fetcher.prototype.onScriptLoad = function(xhr, uri) { | ||
if (xhr.status === 200 || (uri.slice(0, 7) === "file://" && xhr.status === 0)) { | ||
// find .map in file. | ||
@@ -145,3 +170,3 @@ // | ||
// whitespace inserted by some packers. | ||
var match = e.target.responseText.match("//# [s]ourceMappingURL=(.*)[\\s]*$", "m"); | ||
var match = xhr.responseText.match("//# [s]ourceMappingURL=(.*)[\\s]*$", "m"); | ||
if (match && match.length === 2) { | ||
@@ -155,3 +180,3 @@ // get the map | ||
this.mapForUri[uri] = new source_map_consumer.SourceMapConsumer(atob(embeddedSourceMap[2])); | ||
this.done(this.mapForUri); | ||
this.sem.decr(); | ||
} else { | ||
@@ -171,32 +196,17 @@ if (!absUrlRegex.test(mapUri)) { | ||
var xhrMap = createXMLHTTPObject(); | ||
var that = this; | ||
xhrMap.onreadystatechange = function() { | ||
if (xhrMap.readyState === 4) { | ||
that.sem--; | ||
if (xhrMap.status === 200 || | ||
(mapUri.slice(0, 7) === "file://" && xhrMap.status === 0)) { | ||
that.mapForUri[uri] = new source_map_consumer.SourceMapConsumer(xhrMap.responseText); | ||
} | ||
if (that.sem === 0) { | ||
that.done(that.mapForUri); | ||
} | ||
this.ajax(mapUri, function(xhr) { | ||
if (xhr.status === 200 || (mapUri.slice(0, 7) === "file://" && xhr.status === 0)) { | ||
this.mapForUri[uri] = new source_map_consumer.SourceMapConsumer(xhr.responseText); | ||
} | ||
}; | ||
xhrMap.open("GET", mapUri, true); | ||
xhrMap.send(); | ||
this.sem.decr(); | ||
}); | ||
} | ||
} else { | ||
// no map | ||
this.sem--; | ||
this.sem.decr(); | ||
} | ||
} else { | ||
// HTTP error fetching uri of the script | ||
this.sem--; | ||
this.sem.decr(); | ||
} | ||
if (this.sem === 0) { | ||
this.done(this.mapForUri); | ||
} | ||
}; | ||
@@ -203,0 +213,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96062
2353