Bug 1886946: Remove incorrect assertion that buffer is not-pinned. r=sfink
[gecko.git] / dom / quota / AssertionsImpl.h
blob77df103311dc3cb15929a1305e1bf6f608f383b2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_QUOTA_ASSERTIONSIMPL_H_
8 #define DOM_QUOTA_ASSERTIONSIMPL_H_
10 #include "mozilla/dom/quota/Assertions.h"
12 #include <type_traits>
13 #include "mozilla/Assertions.h"
15 namespace mozilla::dom::quota {
17 namespace detail {
19 template <typename T, bool = std::is_unsigned_v<T>>
20 struct IntChecker {
21 static void Assert(T aInt) {
22 static_assert(std::is_integral_v<T>, "Not an integer!");
23 MOZ_ASSERT(aInt >= 0);
27 template <typename T>
28 struct IntChecker<T, true> {
29 static void Assert(T aInt) {
30 static_assert(std::is_integral_v<T>, "Not an integer!");
34 } // namespace detail
36 template <typename T>
37 void AssertNoOverflow(uint64_t aDest, T aArg) {
38 detail::IntChecker<T>::Assert(aDest);
39 detail::IntChecker<T>::Assert(aArg);
40 MOZ_ASSERT(UINT64_MAX - aDest >= uint64_t(aArg));
43 template <typename T, typename U>
44 void AssertNoUnderflow(T aDest, U aArg) {
45 detail::IntChecker<T>::Assert(aDest);
46 detail::IntChecker<T>::Assert(aArg);
47 MOZ_ASSERT(uint64_t(aDest) >= uint64_t(aArg));
50 } // namespace mozilla::dom::quota
52 #endif // DOM_QUOTA_ASSERTIONSIMPL_H_