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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/ThreadLocal.h"
8 #include "mozilla/dom/quota/StringifyUtils.h"
9 #include "nsTHashSet.h"
13 MOZ_THREAD_LOCAL(nsTHashSet
<Stringifyable
*>*)
14 Stringifyable::sActiveStringifyableInstances
;
17 Atomic
<bool> sStringifyableTLSInitialized(false);
20 void Stringifyable::Stringify(nsACString
& aData
) {
22 aData
.Append("(...)"_ns
);
27 aData
.Append(kStringifyStartInstance
);
29 aData
.Append(kStringifyEndInstance
);
33 /* static */ void Stringifyable::InitTLS() {
34 if (sActiveStringifyableInstances
.init()) {
36 sStringifyableTLSInitialized
= true;
41 bool Stringifyable::IsActive() {
42 MOZ_ASSERT(sStringifyableTLSInitialized
);
43 auto* set
= sActiveStringifyableInstances
.get();
44 return set
&& set
->Contains(this);
47 void Stringifyable::SetActive(bool aIsActive
) {
48 MOZ_ASSERT(sStringifyableTLSInitialized
);
49 auto* myset
= sActiveStringifyableInstances
.get();
50 if (!myset
&& aIsActive
) {
51 myset
= new nsTHashSet
<Stringifyable
*>();
52 sActiveStringifyableInstances
.set(myset
);
59 if (myset
->IsEmpty()) {
60 sActiveStringifyableInstances
.set(nullptr);
66 } // namespace mozilla