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
{
19 template <typename T
, bool = std::is_unsigned_v
<T
>>
21 static void Assert(T aInt
) {
22 static_assert(std::is_integral_v
<T
>, "Not an integer!");
23 MOZ_ASSERT(aInt
>= 0);
28 struct IntChecker
<T
, true> {
29 static void Assert(T aInt
) {
30 static_assert(std::is_integral_v
<T
>, "Not an integer!");
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_