зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1615481. Throw the right exception from DataChannel.send() when the message is too big. r=jib
Differential Revision: https://phabricator.services.mozilla.com/D62850 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8aff3f59fe
Коммит
d82355eb35
|
@ -3081,13 +3081,17 @@ void DataChannel::SetListener(DataChannelListener* aListener,
|
|||
mListener = aListener;
|
||||
}
|
||||
|
||||
void DataChannel::SendErrnoToErrorResult(int error, ErrorResult& aRv) {
|
||||
void DataChannel::SendErrnoToErrorResult(int error, size_t aMessageSize,
|
||||
ErrorResult& aRv) {
|
||||
switch (error) {
|
||||
case 0:
|
||||
break;
|
||||
case EMSGSIZE:
|
||||
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
||||
case EMSGSIZE: {
|
||||
nsPrintfCString err("Message size (%zu) exceeds maxMessageSize",
|
||||
aMessageSize);
|
||||
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
|
||||
break;
|
||||
|
@ -3173,7 +3177,8 @@ void DataChannel::SendMsg(const nsACString& aMsg, ErrorResult& aRv) {
|
|||
return;
|
||||
}
|
||||
|
||||
SendErrnoToErrorResult(mConnection->SendMsg(mStream, aMsg), aRv);
|
||||
SendErrnoToErrorResult(mConnection->SendMsg(mStream, aMsg), aMsg.Length(),
|
||||
aRv);
|
||||
if (!aRv.Failed()) {
|
||||
IncrementBufferedAmount(aMsg.Length(), aRv);
|
||||
}
|
||||
|
@ -3184,7 +3189,8 @@ void DataChannel::SendBinaryMsg(const nsACString& aMsg, ErrorResult& aRv) {
|
|||
return;
|
||||
}
|
||||
|
||||
SendErrnoToErrorResult(mConnection->SendBinaryMsg(mStream, aMsg), aRv);
|
||||
SendErrnoToErrorResult(mConnection->SendBinaryMsg(mStream, aMsg),
|
||||
aMsg.Length(), aRv);
|
||||
if (!aRv.Failed()) {
|
||||
IncrementBufferedAmount(aMsg.Length(), aRv);
|
||||
}
|
||||
|
@ -3214,7 +3220,8 @@ void DataChannel::SendBinaryBlob(dom::Blob& aBlob, ErrorResult& aRv) {
|
|||
return;
|
||||
}
|
||||
|
||||
SendErrnoToErrorResult(mConnection->SendBlob(mStream, msgStream), aRv);
|
||||
SendErrnoToErrorResult(mConnection->SendBlob(mStream, msgStream), msgLength,
|
||||
aRv);
|
||||
if (!aRv.Failed()) {
|
||||
IncrementBufferedAmount(msgLength, aRv);
|
||||
}
|
||||
|
|
|
@ -449,7 +449,8 @@ class DataChannel {
|
|||
void SetListener(DataChannelListener* aListener, nsISupports* aContext);
|
||||
|
||||
// Helper for send methods that converts POSIX error codes to an ErrorResult.
|
||||
static void SendErrnoToErrorResult(int error, ErrorResult& aRv);
|
||||
static void SendErrnoToErrorResult(int error, size_t aMessageSize,
|
||||
ErrorResult& aRv);
|
||||
|
||||
// Send a string
|
||||
void SendMsg(const nsACString& aMsg, ErrorResult& aRv);
|
||||
|
|
|
@ -313,6 +313,6 @@ promise_test(async t => {
|
|||
// "send" method step 4:
|
||||
// If the byte size of "data" exceeds the value of maxMessageSize, throw
|
||||
// a TypeError.
|
||||
assert_throws_dom('TypeError', () => channel1.send(message));
|
||||
assert_throws_js(TypeError, () => channel1.send(message));
|
||||
}, 'Calling send() up to max size should succeed, above max size should fail');
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче