Bug 1315470: booleans never turn negative. r=jesup draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 07 Nov 2016 15:28:50 -0800
changeset 437970 d1185a0c9131045f5cbb45b7abe41476886e2fb7
parent 437948 fc104971a4db41e38808e6412bc32e1900172f14
child 536780 7786e4b745695221ffae897adf0e33c69544c179
push id35571
push userdrno@ohlmeier.org
push dateSat, 12 Nov 2016 01:09:07 +0000
reviewersjesup
bugs1315470
milestone52.0a1
Bug 1315470: booleans never turn negative. r=jesup MozReview-Commit-ID: 7XbJd35uMSX
dom/base/nsDOMDataChannel.cpp
netwerk/sctp/datachannel/DataChannel.h
testing/web-platform/tests/webrtc/datachannel-emptystring.html
--- 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');