tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StreamUtils.cpp (931B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "StreamUtils.h"
      6 
      7 #include <cmath>
      8 
      9 #include "mozilla/dom/QueuingStrategyBinding.h"
     10 
     11 namespace mozilla::dom {
     12 
     13 // Streams Spec: 7.4
     14 // https://streams.spec.whatwg.org/#validate-and-normalize-high-water-mark
     15 double ExtractHighWaterMark(const QueuingStrategy& aStrategy,
     16                            double aDefaultHWM, mozilla::ErrorResult& aRv) {
     17  // Step 1.
     18  if (!aStrategy.mHighWaterMark.WasPassed()) {
     19    return aDefaultHWM;
     20  }
     21 
     22  // Step 2.
     23  double highWaterMark = aStrategy.mHighWaterMark.Value();
     24 
     25  // Step 3.
     26  if (std::isnan(highWaterMark) || highWaterMark < 0) {
     27    aRv.ThrowRangeError("Invalid highWaterMark");
     28    return 0.0;
     29  }
     30 
     31  // Step 4.
     32  return highWaterMark;
     33 }
     34 
     35 }  // namespace mozilla::dom