Bug 889530 - Don't permanently cache source maps; r=vporof

This commit is contained in:
Nick Fitzgerald 2013-09-05 09:50:10 -07:00
Родитель 3c2eb6cdfd
Коммит f1bbb8fc9d
4 изменённых файлов: 113 добавлений и 21 удалений

Просмотреть файл

@ -3376,8 +3376,6 @@ function ThreadSources(aThreadActor, aUseSourceMaps, aAllowPredicate,
this._allow = aAllowPredicate;
this._onNewSource = aOnNewSource;
// source map URL --> promise of SourceMapConsumer
this._sourceMaps = Object.create(null);
// generated source url --> promise of SourceMapConsumer
this._sourceMapsByGeneratedSource = Object.create(null);
// original source url --> promise of SourceMapConsumer
@ -3450,7 +3448,6 @@ ThreadSources.prototype = {
})
.then(null, (e) => {
reportError(e);
delete this._sourceMaps[this._normalize(aScript.sourceMapURL, aScript.url)];
delete this._sourceMapsByGeneratedSource[aScript.url];
return [this.source(aScript.url)];
})
@ -3465,9 +3462,6 @@ ThreadSources.prototype = {
* |aScript| must have a non-null sourceMapURL.
*/
sourceMap: function TS_sourceMap(aScript) {
if (aScript.url in this._sourceMapsByGeneratedSource) {
return this._sourceMapsByGeneratedSource[aScript.url];
}
dbg_assert(aScript.sourceMapURL, "Script should have a sourceMapURL");
let sourceMapURL = this._normalize(aScript.sourceMapURL, aScript.url);
let map = this._fetchSourceMap(sourceMapURL, aScript.url)
@ -3495,17 +3489,12 @@ ThreadSources.prototype = {
* them from aScriptURL.
*/
_fetchSourceMap: function TS__fetchSourceMap(aAbsSourceMapURL, aScriptURL) {
if (aAbsSourceMapURL in this._sourceMaps) {
return this._sourceMaps[aAbsSourceMapURL];
}
let promise = fetch(aAbsSourceMapURL).then(({ content }) => {
let map = new SourceMapConsumer(content);
this._setSourceMapRoot(map, aAbsSourceMapURL, aScriptURL);
return map;
});
this._sourceMaps[aAbsSourceMapURL] = promise;
return promise;
return fetch(aAbsSourceMapURL, { loadFromCache: false })
.then(({ content }) => {
let map = new SourceMapConsumer(content);
this._setSourceMapRoot(map, aAbsSourceMapURL, aScriptURL);
return map;
});
},
/**

Просмотреть файл

@ -201,8 +201,8 @@ function finishClient(aClient)
/**
* Takes a relative file path and returns the absolute file url for it.
*/
function getFileUrl(aName) {
let file = do_get_file(aName);
function getFileUrl(aName, aAllowMissing=false) {
let file = do_get_file(aName, aAllowMissing);
return Services.io.newFileURI(file).spec;
}
@ -210,9 +210,9 @@ function getFileUrl(aName) {
* Returns the full path of the file with the specified name in a
* platform-independent and URL-like form.
*/
function getFilePath(aName)
function getFilePath(aName, aAllowMissing=false)
{
let file = do_get_file(aName);
let file = do_get_file(aName, aAllowMissing);
let path = Services.io.newFileURI(file).spec;
let filePrePath = "file://";
if ("nsILocalFileWin" in Ci &&

Просмотреть файл

@ -0,0 +1,102 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Test that we don't permanently cache source maps.
*/
var gDebuggee;
var gClient;
var gThreadClient;
Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-source-map");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function() {
attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
setup_code();
});
});
do_test_pending();
}
// The MAP_FILE_NAME is .txt so that the OS will definitely have an extension ->
// content type mapping for the extension. If it doesn't (like .map or .json),
// it logs console errors, which cause the test to fail. See bug 907839.
const MAP_FILE_NAME = "temporary-generated.txt";
const TEMP_FILE_1 = "temporary1.js";
const TEMP_FILE_2 = "temporary2.js";
const TEMP_GENERATED_SOURCE = "temporary-generated.js";
function setup_code() {
let node = new SourceNode(1, 0,
getFileUrl(TEMP_FILE_1, true),
"function temporary1() {}\n");
let { code, map } = node.toStringWithSourceMap({
file: getFileUrl(TEMP_GENERATED_SOURCE, true)
});
code += "//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true);
writeFile(MAP_FILE_NAME, map.toString());
Cu.evalInSandbox(code,
gDebuggee,
"1.8",
getFileUrl(TEMP_GENERATED_SOURCE, true),
1);
test_initial_sources();
}
function test_initial_sources() {
gThreadClient.getSources(function ({ error, sources }) {
do_check_true(!error);
do_check_eq(sources.length, 1);
do_check_eq(sources[0].url, getFileUrl(TEMP_FILE_1, true));
setup_new_code();
});
}
function setup_new_code() {
let node = new SourceNode(1, 0,
getFileUrl(TEMP_FILE_2, true),
"function temporary2() {}\n");
let { code, map } = node.toStringWithSourceMap({
file: getFileUrl(TEMP_GENERATED_SOURCE, true)
});
code += "\n//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true);
writeFile(MAP_FILE_NAME, map.toString());
Cu.evalInSandbox(code,
gDebuggee,
"1.8",
getFileUrl(TEMP_GENERATED_SOURCE, true),
1);
gClient.addOneTimeListener("newSource", test_new_sources);
}
function test_new_sources() {
gThreadClient.getSources(function ({ error, sources }) {
do_check_true(!error);
// Should now have TEMP_FILE_2 as a source.
do_check_eq(sources.length, 2);
let s = sources.filter(s => s.url === getFileUrl(TEMP_FILE_2, true))[0];
do_check_true(!!s);
finish_test();
});
}
function finish_test() {
do_get_file(MAP_FILE_NAME).remove(false);
finishClient(gClient);
}

Просмотреть файл

@ -119,6 +119,7 @@ reason = bug 820380
[test_sourcemaps-09.js]
[test_sourcemaps-10.js]
[test_sourcemaps-11.js]
[test_sourcemaps-13.js]
[test_objectgrips-01.js]
[test_objectgrips-02.js]
[test_objectgrips-03.js]