Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / streams / StreamUtils.cpp
blob15ad80867da5c4af5836623dc9285543361274d8
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 "StreamUtils.h"
7 #include <cmath>
8 #include "mozilla/dom/QueuingStrategyBinding.h"
10 namespace mozilla::dom {
12 // Streams Spec: 7.4
13 // https://streams.spec.whatwg.org/#validate-and-normalize-high-water-mark
14 double ExtractHighWaterMark(const QueuingStrategy& aStrategy,
15 double aDefaultHWM, mozilla::ErrorResult& aRv) {
16 // Step 1.
17 if (!aStrategy.mHighWaterMark.WasPassed()) {
18 return aDefaultHWM;
21 // Step 2.
22 double highWaterMark = aStrategy.mHighWaterMark.Value();
24 // Step 3.
25 if (std::isnan(highWaterMark) || highWaterMark < 0) {
26 aRv.ThrowRangeError("Invalid highWaterMark");
27 return 0.0;
30 // Step 4.
31 return highWaterMark;
34 } // namespace mozilla::dom