75 lines
2.2 KiB
Diff
75 lines
2.2 KiB
Diff
From 311de0b6358ba2b8eae20dcc5baf29472a273fc6 Mon Sep 17 00:00:00 2001
|
|
From: Simon Giesecke <sgiesecke@mozilla.com>
|
|
Date: Tue, 3 Dec 2019 15:25:49 +0000
|
|
Subject: [PATCH] Bug 1598164 - Added FlippedOnce class template to help
|
|
reducing statefulness of boolean flags.
|
|
r=dom-workers-and-storage-reviewers,ytausky
|
|
|
|
Differential Revision: https://phabricator.services.mozilla.com/D55080
|
|
|
|
--HG--
|
|
extra : moz-landing-system : lando
|
|
---
|
|
dom/indexedDB/FlippedOnce.h | 39 +++++++++++++++++++++++++++++++++++++
|
|
dom/indexedDB/moz.build | 1 +
|
|
2 files changed, 40 insertions(+)
|
|
create mode 100644 dom/indexedDB/FlippedOnce.h
|
|
|
|
diff --git a/dom/indexedDB/FlippedOnce.h b/dom/indexedDB/FlippedOnce.h
|
|
new file mode 100644
|
|
index 0000000000000..94cd8570a4b6e
|
|
--- /dev/null
|
|
+++ b/dom/indexedDB/FlippedOnce.h
|
|
@@ -0,0 +1,39 @@
|
|
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
+/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
+
|
|
+#ifndef mozilla_dom_indexeddb_flippedonce_h__
|
|
+#define mozilla_dom_indexeddb_flippedonce_h__
|
|
+
|
|
+#include "mozilla/Assertions.h"
|
|
+#include "mozilla/Attributes.h"
|
|
+
|
|
+namespace mozilla {
|
|
+
|
|
+// A state-restricted bool, which can only be flipped once. It isn't required to
|
|
+// be flipped during its lifetime.
|
|
+template <bool Initial>
|
|
+class FlippedOnce {
|
|
+ public:
|
|
+ FlippedOnce(const FlippedOnce&) = delete;
|
|
+ FlippedOnce& operator=(const FlippedOnce&) = delete;
|
|
+
|
|
+ FlippedOnce() = default;
|
|
+
|
|
+ MOZ_IMPLICIT operator bool() const { return mValue; };
|
|
+
|
|
+ void Flip() {
|
|
+ MOZ_ASSERT(mValue == Initial);
|
|
+ EnsureFlipped();
|
|
+ }
|
|
+
|
|
+ void EnsureFlipped() { mValue = !Initial; }
|
|
+
|
|
+ private:
|
|
+ bool mValue = Initial;
|
|
+};
|
|
+} // namespace mozilla
|
|
+
|
|
+#endif
|
|
diff --git a/dom/indexedDB/moz.build b/dom/indexedDB/moz.build
|
|
index 4302528e6847b..5237528963127 100644
|
|
--- a/dom/indexedDB/moz.build
|
|
+++ b/dom/indexedDB/moz.build
|
|
@@ -24,6 +24,7 @@ XPCSHELL_TESTS_MANIFESTS += [
|
|
]
|
|
|
|
EXPORTS.mozilla.dom += [
|
|
+ 'FlippedOnce.h',
|
|
'IDBCursor.h',
|
|
'IDBDatabase.h',
|
|
'IDBEvents.h',
|