Bug 1769952 - Fix running raptor on a Win10-64 VM r=sparky
[gecko.git] / dom / streams / StreamUtils.cpp
blob7496372a0b0d724a871b0959d60b69c21d3548a7
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/. */
5 #include "mozilla/dom/StreamUtils.h"
6 #include "mozilla/FloatingPoint.h"
7 #include "mozilla/dom/QueuingStrategyBinding.h"
9 namespace mozilla::dom {
11 // Streams Spec: 7.4
12 // https://streams.spec.whatwg.org/#validate-and-normalize-high-water-mark
13 double ExtractHighWaterMark(const QueuingStrategy& aStrategy,
14 double aDefaultHWM, mozilla::ErrorResult& aRv) {
15 // Step 1.
16 if (!aStrategy.mHighWaterMark.WasPassed()) {
17 return aDefaultHWM;
20 // Step 2.
21 double highWaterMark = aStrategy.mHighWaterMark.Value();
23 // Step 3.
24 if (mozilla::IsNaN(highWaterMark) || highWaterMark < 0) {
25 aRv.ThrowRangeError("Invalid highWaterMark");
26 return 0.0;
29 // Step 4.
30 return highWaterMark;
33 } // namespace mozilla::dom