Bug 1315470: booleans never turn negative. r=jesup
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 07 Nov 2016 15:28:50 -0800
changeset 352379 31b6c03c69f18df000420d218b7b233f739af584
parent 352378 217ae1d5285328611de99e2e48042b19751dbb54
child 352380 d96967030071dd928ed0460c1ec7edcc213b6419
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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');