mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 521258 - Catch exceptions in template ChannelListener class to avoid hangs, r=jwalden
This commit is contained in:
parent
b6bf90ea7a
commit
805435bdcf
@ -60,49 +60,64 @@ ChannelListener.prototype = {
|
||||
},
|
||||
|
||||
onStartRequest: function(request, context) {
|
||||
if (this._got_onstartrequest)
|
||||
do_throw("Got second onStartRequest event!");
|
||||
this._got_onstartrequest = true;
|
||||
try {
|
||||
if (this._got_onstartrequest)
|
||||
do_throw("Got second onStartRequest event!");
|
||||
this._got_onstartrequest = true;
|
||||
|
||||
request.QueryInterface(Components.interfaces.nsIChannel);
|
||||
this._contentLen = request.contentLength;
|
||||
if (this._contentLen == -1)
|
||||
do_throw("Content length is unknown in onStartRequest!");
|
||||
request.QueryInterface(Components.interfaces.nsIChannel);
|
||||
this._contentLen = request.contentLength;
|
||||
if (this._contentLen == -1)
|
||||
do_throw("Content length is unknown in onStartRequest!");
|
||||
} catch (ex) {
|
||||
do_throw("Error in onStartRequest: " + ex);
|
||||
}
|
||||
},
|
||||
|
||||
onDataAvailable: function(request, context, stream, offset, count) {
|
||||
if (!this._got_onstartrequest)
|
||||
do_throw("onDataAvailable without onStartRequest event!");
|
||||
if (this._got_onstoprequest)
|
||||
do_throw("onDataAvailable after onStopRequest event!");
|
||||
if (!request.isPending())
|
||||
do_throw("request reports itself as not pending from onDataAvailable!");
|
||||
if (this._flags & CL_EXPECT_FAILURE)
|
||||
do_throw("Got data despite expecting a failure");
|
||||
try {
|
||||
if (!this._got_onstartrequest)
|
||||
do_throw("onDataAvailable without onStartRequest event!");
|
||||
if (this._got_onstoprequest)
|
||||
do_throw("onDataAvailable after onStopRequest event!");
|
||||
if (!request.isPending())
|
||||
do_throw("request reports itself as not pending from onDataAvailable!");
|
||||
if (this._flags & CL_EXPECT_FAILURE)
|
||||
do_throw("Got data despite expecting a failure");
|
||||
|
||||
this._buffer = this._buffer.concat(read_stream(stream, count));
|
||||
this._buffer = this._buffer.concat(read_stream(stream, count));
|
||||
} catch (ex) {
|
||||
do_throw("Error in onDataAvailable: " + ex);
|
||||
}
|
||||
},
|
||||
|
||||
onStopRequest: function(request, context, status) {
|
||||
if (!this._got_onstartrequest)
|
||||
do_throw("onStopRequest without onStartRequest event!");
|
||||
if (this._got_onstoprequest)
|
||||
do_throw("Got second onStopRequest event!");
|
||||
this._got_onstoprequest = true;
|
||||
var success = Components.isSuccessCode(status);
|
||||
if ((this._flags & CL_EXPECT_FAILURE) && success)
|
||||
do_throw("Should have failed to load URL (status is " + status.toString(16) + ")");
|
||||
else if (!(this._flags & CL_EXPECT_FAILURE) && !success)
|
||||
do_throw("Failed to load URL: " + status.toString(16));
|
||||
if (status != request.status)
|
||||
do_throw("request.status does not match status arg to onStopRequest!");
|
||||
if (request.isPending())
|
||||
do_throw("request reports itself as pending from onStopRequest!");
|
||||
if (!(this._flags & CL_EXPECT_FAILURE) &&
|
||||
!(this._flags & CL_EXPECT_GZIP) &&
|
||||
this._contentLen != -1)
|
||||
do_check_eq(this._buffer.length, this._contentLen)
|
||||
|
||||
this._closure(request, this._buffer, this._closurectx);
|
||||
try {
|
||||
if (!this._got_onstartrequest)
|
||||
do_throw("onStopRequest without onStartRequest event!");
|
||||
if (this._got_onstoprequest)
|
||||
do_throw("Got second onStopRequest event!");
|
||||
this._got_onstoprequest = true;
|
||||
var success = Components.isSuccessCode(status);
|
||||
if ((this._flags & CL_EXPECT_FAILURE) && success)
|
||||
do_throw("Should have failed to load URL (status is " + status.toString(16) + ")");
|
||||
else if (!(this._flags & CL_EXPECT_FAILURE) && !success)
|
||||
do_throw("Failed to load URL: " + status.toString(16));
|
||||
if (status != request.status)
|
||||
do_throw("request.status does not match status arg to onStopRequest!");
|
||||
if (request.isPending())
|
||||
do_throw("request reports itself as pending from onStopRequest!");
|
||||
if (!(this._flags & CL_EXPECT_FAILURE) &&
|
||||
!(this._flags & CL_EXPECT_GZIP) &&
|
||||
this._contentLen != -1)
|
||||
do_check_eq(this._buffer.length, this._contentLen)
|
||||
} catch (ex) {
|
||||
do_throw("Error in onStopRequest: " + ex);
|
||||
}
|
||||
try {
|
||||
this._closure(request, this._buffer, this._closurectx);
|
||||
} catch (ex) {
|
||||
do_throw("Error in closure function: " + ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user