зеркало из https://github.com/mozilla/gecko-dev.git
Bug 622760: log exceptions thrown in _onProgress callbacks. r=philiKON
This commit is contained in:
Родитель
3e59469096
Коммит
c9a23f8fc5
|
@ -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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче