Bug 622760: log exceptions thrown in _onProgress callbacks. r=philiKON

This commit is contained in:
Richard Newman 2011-01-04 16:27:00 -08:00
Родитель 3e59469096
Коммит c9a23f8fc5
3 изменённых файлов: 107 добавлений и 3 удалений

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

@ -452,9 +452,24 @@ ChannelListener.prototype = {
let siStream = Cc["@mozilla.org/scriptableinputstream;1"].
createInstance(Ci.nsIScriptableInputStream);
siStream.init(stream);
this._data += siStream.read(count);
this._onProgress();
try {
this._data += siStream.read(count);
} catch (ex) {
this._log.warn("Exception thrown reading " + count +
" bytes from " + siStream + ".");
throw ex;
}
try {
this._onProgress();
} catch (ex) {
this._log.warn("Got exception calling onProgress handler during fetch of "
+ req.URI.spec);
this._log.debug(Utils.stackTrace(ex));
this._log.trace("Rethrowing; expect a failure code from the HTTP channel.");
throw ex;
}
this.delayAbort();
},

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

@ -472,5 +472,51 @@ function run_test() {
do_check_eq(content.status, 0);
do_check_false(content.success);
_("Checking handling of errors in onProgress.");
let res18 = new Resource("http://localhost:8080/json");
let onProgress = function(rec) {
// Provoke an XPC exception without a Javascript wrapper.
Svc.IO.newURI("::::::::", null, null);
};
res18._onProgress = onProgress;
let oldWarn = res18._log.warn;
let warnings = [];
res18._log.warn = function(msg) { warnings.push(msg) };
error = undefined;
try {
content = res18.get();
} catch (ex) {
error = ex;
}
// It throws and logs.
do_check_eq(error, "Error: NS_ERROR_MALFORMED_URI");
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
"http://localhost:8080/json");
// And this is what happens if JS throws an exception.
res18 = new Resource("http://localhost:8080/json");
onProgress = function(rec) {
throw "BOO!";
};
res18._onProgress = onProgress;
oldWarn = res18._log.warn;
warnings = [];
res18._log.warn = function(msg) { warnings.push(msg) };
error = undefined;
try {
content = res18.get();
} catch (ex) {
error = ex;
}
// It throws and logs.
do_check_eq(error, "Error: NS_ERROR_XPC_JS_THREW_STRING");
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
"http://localhost:8080/json");
server.stop(do_test_finished);
}

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

@ -619,6 +619,49 @@ function run_test() {
next();
}));
}, function (next) {
_("Exception handling inside fetches.");
let res14 = new AsyncResource("http://localhost:8080/json");
res14._onProgress = function(rec) {
// Provoke an XPC exception without a Javascript wrapper.
Svc.IO.newURI("::::::::", null, null);
};
let warnings = [];
res14._log.warn = function(msg) { warnings.push(msg) };
res14.get(ensureThrows(function (error, content) {
do_check_eq(error, "Error: NS_ERROR_MALFORMED_URI");
do_check_eq(content, null);
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
"http://localhost:8080/json");
do_test_finished();
next();
}));
}, function (next) {
_("JS exception handling inside fetches.");
let res15 = new AsyncResource("http://localhost:8080/json");
res15._onProgress = function(rec) {
throw "BOO!";
};
warnings = [];
res15._log.warn = function(msg) { warnings.push(msg) };
res15.get(ensureThrows(function (error, content) {
do_check_eq(error, "Error: NS_ERROR_XPC_JS_THREW_STRING");
do_check_eq(content, null);
do_check_eq(warnings.pop(),
"Got exception calling onProgress handler during fetch of " +
"http://localhost:8080/json");
do_test_finished();
next();
}));
}, function (next) {
// Don't quit test harness before server shuts down.