Bug 1315470: booleans never turn negative. r=jesup
MozReview-Commit-ID: 7XbJd35uMSX
--- a/dom/base/nsDOMDataChannel.cpp
+++ b/dom/base/nsDOMDataChannel.cpp
@@ -352,27 +352,27 @@ nsDOMDataChannel::Send(nsIInputStream* a
if (state == mozilla::DataChannel::CLOSING ||
state == mozilla::DataChannel::CLOSED) {
return;
}
MOZ_ASSERT(state == mozilla::DataChannel::OPEN,
"Unknown state in nsDOMDataChannel::Send");
- int32_t sent;
+ bool sent;
if (aMsgStream) {
sent = mDataChannel->SendBinaryStream(aMsgStream, aMsgLength);
} else {
if (aIsBinary) {
sent = mDataChannel->SendBinaryMsg(aMsgString);
} else {
sent = mDataChannel->SendMsg(aMsgString);
}
}
- if (sent < 0) {
+ if (!sent) {
aRv.Throw(NS_ERROR_FAILURE);
}
}
nsresult
nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
bool aBinary)
{
--- a/netwerk/sctp/datachannel/DataChannel.h
+++ b/netwerk/sctp/datachannel/DataChannel.h
@@ -349,39 +349,39 @@ public:
void SetListener(DataChannelListener *aListener, nsISupports *aContext);
// Send a string
bool SendMsg(const nsACString &aMsg)
{
ENSURE_DATACONNECTION_RET(false);
if (mStream != INVALID_STREAM)
- return (mConnection->SendMsg(mStream, aMsg) > 0);
+ return (mConnection->SendMsg(mStream, aMsg) >= 0);
else
return false;
}
// Send a binary message (TypedArray)
bool SendBinaryMsg(const nsACString &aMsg)
{
ENSURE_DATACONNECTION_RET(false);
if (mStream != INVALID_STREAM)
- return (mConnection->SendBinaryMsg(mStream, aMsg) > 0);
+ return (mConnection->SendBinaryMsg(mStream, aMsg) >= 0);
else
return false;
}
// Send a binary blob
bool SendBinaryStream(nsIInputStream *aBlob, uint32_t msgLen)
{
ENSURE_DATACONNECTION_RET(false);
if (mStream != INVALID_STREAM)
- return (mConnection->SendBlob(mStream, aBlob) > 0);
+ return (mConnection->SendBlob(mStream, aBlob) == 0);
else
return false;
}
uint16_t GetType() { return mPrPolicy; }
bool GetOrdered() { return !(mFlags & DATA_CHANNEL_FLAGS_OUT_OF_ORDER_ALLOWED); }
--- a/testing/web-platform/tests/webrtc/datachannel-emptystring.html
+++ b/testing/web-platform/tests/webrtc/datachannel-emptystring.html
@@ -28,23 +28,23 @@ and ensures that an empty string sent by
var onReceiveChannel = function (event) {
receiveChannel = event.channel;
receiveChannel.onmessage = onReceiveMessage;
};
// When the data channel is open, send an empty string message
// followed by a message that contains the string "done".
- var onSendChannelOpen = function (event) {
+ var onSendChannelOpen = test.step_func(function (event) {
var msgEl = document.getElementById('msg');
sendChannel.send('');
msgEl.innerHTML += 'Sent: [empty string]<br>';
sendChannel.send('done');
msgEl.innerHTML += 'Sent: "done"<br>';
- };
+ });
// Check the messages received on the other side.
// There should be an empty string message followed by a message that
// contains the string "done".
// Pass/Fail the test according to the messages received
var emptyMessageReceived = false;
var onReceiveMessage = test.step_func(function (event) {
var msgEl = document.getElementById('msg');