Files
tubestation/dom/base/nsCCUncollectableMarker.h
Andrew McCreight 68046e6cc3 Bug 1958292 - Don't use the observer service for forget skippable cleanup. r=smaug
It appears that calling UnmarkGrayStrongObservers while inside an observer can
cause crashes. This will only happen for the forget skippable cleanup, so this
patch splits out a separate cleanup method, adds a new static variable to hold
a pointer to the marker static instance, and adds a new static method to call
the cleanup method on the static instance.

There are no other uses of cycle-collector-forget-skippable so I get rid of it.

Differential Revision: https://phabricator.services.mozilla.com/D246437
2025-04-23 20:24:50 +00:00

51 lines
1.3 KiB
C++

/* -*- 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 nsCCUncollectableMarker_h_
#define nsCCUncollectableMarker_h_
#include "js/TracingAPI.h"
#include "mozilla/Attributes.h"
#include "nsIObserver.h"
class nsCCUncollectableMarker final : public nsIObserver {
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
/**
* Inits a global nsCCUncollectableMarker. Should only be called once.
*/
static nsresult Init();
/**
* Checks if we're collecting during a given generation
*/
static bool InGeneration(uint32_t aGeneration) {
return aGeneration && aGeneration == sGeneration;
}
template <class CCCallback>
static bool InGeneration(CCCallback& aCb, uint32_t aGeneration) {
return InGeneration(aGeneration) && !aCb.WantAllTraces();
}
static void CleanupForForgetSkippable();
static uint32_t sGeneration;
private:
nsCCUncollectableMarker() = default;
~nsCCUncollectableMarker() = default;
nsresult Cleanup(bool aPrepareForCC);
};
namespace mozilla::dom {
void TraceBlackJS(JSTracer* aTrc);
} // namespace mozilla::dom
#endif