Bug 1653011 - Simplify and make WeakPtr<Derived> usable and compact. r=froydnj,sg,geckoview-reviewers,jgilbert,kvark,snorp

Having two classes in the inheritance chain inherit from SupportsWeakPtr
now won't compile, but you can use WeakPtr<Derived> when any base class
inherits from SupportsWeakPtr.

Differential Revision: https://phabricator.services.mozilla.com/D83674
This commit is contained in:
Emilio Cobos Álvarez 2020-07-23 14:51:46 +00:00
parent 37c68db147
commit ff61891772
63 changed files with 135 additions and 330 deletions

View File

@ -513,8 +513,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
Nullable<WindowProxyHolder> GetWindow();
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(BrowsingContext)
NS_DECL_NSILOADCONTEXT

View File

@ -120,7 +120,7 @@ class nsDocShell final : public nsDocLoader,
public nsILoadContext,
public nsINetworkInterceptController,
public nsIDeprecationWarner,
public mozilla::SupportsWeakPtr<nsDocShell> {
public mozilla::SupportsWeakPtr {
public:
enum InternalLoad : uint32_t {
INTERNAL_LOAD_FLAGS_NONE = 0x0,
@ -179,7 +179,6 @@ class nsDocShell final : public nsDocLoader,
nsWeakPtr mWeakPtr;
};
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocShell, nsDocLoader)
NS_DECL_NSIDOCSHELL

View File

@ -469,7 +469,7 @@ class Document : public nsINode,
public nsIApplicationCacheContainer,
public nsStubMutationObserver,
public DispatcherTrait,
public SupportsWeakPtr<Document> {
public SupportsWeakPtr {
friend class DocumentOrShadowRoot;
protected:
@ -494,8 +494,6 @@ class Document : public nsINode,
*/
static void Shutdown();
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Document)
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS

View File

@ -14,11 +14,9 @@
namespace mozilla {
namespace dom {
class PlacesWeakCallbackWrapper final
: public nsWrapperCache,
public SupportsWeakPtr<PlacesWeakCallbackWrapper> {
class PlacesWeakCallbackWrapper final : public nsWrapperCache,
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlacesWeakCallbackWrapper)
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PlacesWeakCallbackWrapper)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(PlacesWeakCallbackWrapper)

View File

@ -56,7 +56,7 @@ namespace dom {
// is never deleted before its Selections.
class Selection final : public nsSupportsWeakReference,
public nsWrapperCache,
public SupportsWeakPtr<Selection> {
public SupportsWeakPtr {
protected:
virtual ~Selection();
@ -67,8 +67,6 @@ class Selection final : public nsSupportsWeakReference,
explicit Selection(SelectionType aSelectionType,
nsFrameSelection* aFrameSelection);
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Selection)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Selection)

View File

@ -953,6 +953,8 @@ void nsRange::RegisterSelection(Selection& aSelection) {
RegisterClosestCommonInclusiveAncestor(commonAncestor);
}
Selection* nsRange::GetSelection() const { return mSelection; }
void nsRange::UnregisterSelection() {
mSelection = nullptr;

View File

@ -105,7 +105,7 @@ class nsRange final : public mozilla::dom::AbstractRange,
/**
* Returns pointer to a Selection if the range is associated with a Selection.
*/
mozilla::dom::Selection* GetSelection() const { return mSelection; }
mozilla::dom::Selection* GetSelection() const;
/**
* Return true if this range was generated.

View File

@ -392,7 +392,7 @@ class WebGLProgramJS final : public nsWrapperCache, public webgl::ObjectJS {
class WebGLQueryJS final : public nsWrapperCache,
public webgl::ObjectJS,
public SupportsWeakPtr<WebGLQueryJS> {
public SupportsWeakPtr {
friend class ClientWebGLContext;
friend class webgl::AvailabilityRunnable;
@ -402,7 +402,6 @@ class WebGLQueryJS final : public nsWrapperCache,
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLQueryJS)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLQueryJS)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLQueryJS)
explicit WebGLQueryJS(const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl) {}
@ -492,7 +491,7 @@ class WebGLShaderJS final : public nsWrapperCache, public webgl::ObjectJS {
class WebGLSyncJS final : public nsWrapperCache,
public webgl::ObjectJS,
public SupportsWeakPtr<WebGLSyncJS> {
public SupportsWeakPtr {
friend class ClientWebGLContext;
friend class webgl::AvailabilityRunnable;
@ -502,7 +501,6 @@ class WebGLSyncJS final : public nsWrapperCache,
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLSyncJS)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLSyncJS)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLSyncJS)
explicit WebGLSyncJS(const ClientWebGLContext& webgl)
: webgl::ObjectJS(webgl) {}
@ -705,15 +703,12 @@ struct TexImageSourceAdapter final : public TexImageSource {
*/
class ClientWebGLContext final : public nsICanvasRenderingContextInternal,
public nsWrapperCache,
public SupportsWeakPtr<ClientWebGLContext> {
public SupportsWeakPtr {
friend class webgl::AvailabilityRunnable;
friend class webgl::ObjectJS;
friend class webgl::ProgramKeepAlive;
friend class webgl::ShaderKeepAlive;
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ClientWebGLContext)
// ----------------------------- Lifetime and DOM ---------------------------
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS

View File

@ -66,7 +66,7 @@ struct LockedOutstandingContexts final {
* nsICanvasRenderingContextInternal DOM class. That is the
* ClientWebGLContext.
*/
class HostWebGLContext final : public SupportsWeakPtr<HostWebGLContext> {
class HostWebGLContext final : public SupportsWeakPtr {
friend class WebGLContext;
friend class WebGLMemoryTracker;
@ -77,8 +77,6 @@ class HostWebGLContext final : public SupportsWeakPtr<HostWebGLContext> {
}
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HostWebGLContext)
struct RemotingData final {
dom::WebGLParent& mParent;
UniquePtr<HostWebGLCommandSinkP> mCommandSinkP;

View File

@ -305,13 +305,12 @@ class SyncConsumerActor : public AsyncConsumerActor<Derived> {
};
template <typename _Actor>
class IpdlProducer final : public SupportsWeakPtr<IpdlProducer<_Actor>> {
class IpdlProducer final : public SupportsWeakPtr {
nsTArray<uint8_t> mSerializedData;
WeakPtr<_Actor> mActor;
uint64_t mId;
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(IpdlProducer<_Actor>)
using Actor = _Actor;
using SelfType = IpdlProducer<Actor>;
@ -443,9 +442,8 @@ class IpdlProducer final : public SupportsWeakPtr<IpdlProducer<_Actor>> {
};
template <typename _Actor>
class IpdlConsumer final : public SupportsWeakPtr<IpdlConsumer<_Actor>> {
class IpdlConsumer final : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(IpdlConsumer<_Actor>)
using Actor = _Actor;
using SelfType = IpdlConsumer<Actor>;

View File

@ -51,7 +51,7 @@ class PcqConsumer;
* }
* Implementations of abstract methods will typically just forward to IProtocol.
*/
class PcqActor : public SupportsWeakPtr<PcqActor> {
class PcqActor : public SupportsWeakPtr {
// The IProtocol part of `this`.
IProtocol* mProtocol;
@ -82,8 +82,6 @@ class PcqActor : public SupportsWeakPtr<PcqActor> {
}
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PcqActor)
Shmem::SharedMemory* LookupSharedMemory(int32_t aId) {
return mProtocol->LookupSharedMemory(aId);
}

View File

@ -32,15 +32,12 @@ struct FlushedCmdInfo final {
size_t flushedCmdBytes = 0;
};
class WebGLChild final : public PWebGLChild,
public SupportsWeakPtr<WebGLChild> {
class WebGLChild final : public PWebGLChild, public SupportsWeakPtr {
const WeakPtr<ClientWebGLContext> mContext;
webgl::RaiiShmem mPendingCmdsShmem;
size_t mPendingCmdsPos = 0;
FlushedCmdInfo mFlushedCmdInfo;
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLChild)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGLChild, override);
using OtherSideActor = WebGLParent;

View File

@ -203,7 +203,7 @@ struct BufferAndIndex final {
////////////////////////////////////////////////////////////////////////////////
class WebGLContext : public VRefCounted, public SupportsWeakPtr<WebGLContext> {
class WebGLContext : public VRefCounted, public SupportsWeakPtr {
friend class ScopedDrawCallWrapper;
friend class ScopedDrawWithTransformFeedback;
friend class ScopedFakeVertexAttrib0;
@ -319,8 +319,6 @@ class WebGLContext : public VRefCounted, public SupportsWeakPtr<WebGLContext> {
mutable FuncScope* mFuncScope = nullptr;
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContext)
static RefPtr<WebGLContext> Create(HostWebGLContext&,
const webgl::InitContextDesc&,
webgl::InitContextResult* out);

View File

@ -14,14 +14,11 @@
namespace mozilla {
class WebGLContext;
class WebGLContextLossHandler final
: public SupportsWeakPtr<WebGLContextLossHandler> {
class WebGLContextLossHandler final : public SupportsWeakPtr {
RefPtr<Runnable> mRunnable;
Atomic<bool> mTimerIsScheduled;
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLContextLossHandler)
explicit WebGLContextLossHandler(WebGLContext* webgl);
~WebGLContextLossHandler();

View File

@ -129,11 +129,10 @@ class WebGLFBAttachPoint final {
};
class WebGLFramebuffer final : public WebGLContextBoundObject,
public SupportsWeakPtr<WebGLFramebuffer>,
public SupportsWeakPtr,
public CacheInvalidator {
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLFramebuffer, override)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLFramebuffer)
const GLuint mGLName;
bool mHasBeenBound = false;

View File

@ -22,12 +22,11 @@ class SurfaceDescriptor;
namespace dom {
class WebGLParent : public PWebGLParent, public SupportsWeakPtr<WebGLParent> {
class WebGLParent : public PWebGLParent, public SupportsWeakPtr {
friend PWebGLParent;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGLParent, override);
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLParent)
using OtherSideActor = WebGLChild;
mozilla::ipc::IPCResult RecvInitialize(

View File

@ -89,12 +89,11 @@ struct LocationInfo final {
// -
struct LinkedProgramInfo final : public RefCounted<LinkedProgramInfo>,
public SupportsWeakPtr<LinkedProgramInfo>,
public SupportsWeakPtr,
public CacheInvalidator {
friend class mozilla::WebGLProgram;
MOZ_DECLARE_REFCOUNTED_TYPENAME(LinkedProgramInfo)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(LinkedProgramInfo)
//////

View File

@ -64,10 +64,9 @@ using mozilla::Unused; // <snicker>
using namespace mozilla;
using namespace mozilla::dom;
class nsGeolocationRequest final
: public ContentPermissionRequestBase,
public nsIGeolocationUpdate,
public SupportsWeakPtr<nsGeolocationRequest> {
class nsGeolocationRequest final : public ContentPermissionRequestBase,
public nsIGeolocationUpdate,
public SupportsWeakPtr {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIGEOLOCATIONUPDATE
@ -86,8 +85,6 @@ class nsGeolocationRequest final
MOZ_CAN_RUN_SCRIPT NS_IMETHOD Cancel(void) override;
MOZ_CAN_RUN_SCRIPT NS_IMETHOD Allow(JS::HandleValue choices) override;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsGeolocationRequest)
void Shutdown();
// MOZ_CAN_RUN_SCRIPT_BOUNDARY is OK here because we're always called from a

View File

@ -88,10 +88,8 @@ class HTMLCanvasElementObserver final : public nsIObserver,
* will be given a copy of the just-painted canvas.
* All FrameCaptureListeners get the same copy.
*/
class FrameCaptureListener : public SupportsWeakPtr<FrameCaptureListener> {
class FrameCaptureListener : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(FrameCaptureListener)
FrameCaptureListener() : mFrameCaptureRequested(false) {}
/*
@ -119,7 +117,7 @@ class FrameCaptureListener : public SupportsWeakPtr<FrameCaptureListener> {
class HTMLCanvasElement final : public nsGenericHTMLElement,
public CanvasRenderingContextHelper,
public SupportsWeakPtr<HTMLCanvasElement> {
public SupportsWeakPtr {
enum { DEFAULT_CANVAS_WIDTH = 300, DEFAULT_CANVAS_HEIGHT = 150 };
typedef layers::CanvasRenderer CanvasRenderer;
@ -141,9 +139,6 @@ class HTMLCanvasElement final : public nsGenericHTMLElement,
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLCanvasElement,
nsGenericHTMLElement)
// WeakPtr
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLCanvasElement)
// WebIDL
uint32_t Height() {
return GetUnsignedIntAttr(nsGkAtoms::height, DEFAULT_CANVAS_HEIGHT);

View File

@ -103,7 +103,7 @@ enum class StreamCaptureBehavior : uint8_t {
class HTMLMediaElement : public nsGenericHTMLElement,
public MediaDecoderOwner,
public PrincipalChangeObserver<MediaStreamTrack>,
public SupportsWeakPtr<HTMLMediaElement>,
public SupportsWeakPtr,
public nsStubMutationObserver {
public:
typedef mozilla::TimeStamp TimeStamp;
@ -134,7 +134,6 @@ class HTMLMediaElement : public nsGenericHTMLElement,
RefPtr<DOMMediaStream> mFinishWhenEndedAttrStream;
};
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLMediaElement)
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
CORSMode GetCORSMode() { return mCORSMode; }

View File

@ -131,13 +131,11 @@ class HTMLInputElement;
class RestoreSelectionState;
class TextControlState final : public SupportsWeakPtr<TextControlState> {
class TextControlState final : public SupportsWeakPtr {
public:
typedef dom::Element Element;
typedef dom::HTMLInputElement HTMLInputElement;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(TextControlState)
static TextControlState* Construct(TextControlElement* aOwningElement);
// Note that this does not run script actually because of `sHasShutDown`

View File

@ -233,13 +233,11 @@ class HangMonitoredProcess final : public nsIHangReport {
};
class HangMonitorParent : public PProcessHangMonitorParent,
public SupportsWeakPtr<HangMonitorParent> {
public SupportsWeakPtr {
public:
explicit HangMonitorParent(ProcessHangMonitor* aMonitor);
~HangMonitorParent() override;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HangMonitorParent)
void Bind(Endpoint<PProcessHangMonitorParent>&& aEndpoint);
mozilla::ipc::IPCResult RecvHangEvidence(const HangData& aHangData) override;

View File

@ -49,7 +49,7 @@ class OverlayImage;
*/
class DOMMediaStream : public DOMEventTargetHelper,
public RelativeTimeline,
public SupportsWeakPtr<DOMMediaStream> {
public SupportsWeakPtr {
typedef dom::MediaStreamTrack MediaStreamTrack;
typedef dom::AudioStreamTrack AudioStreamTrack;
typedef dom::VideoStreamTrack VideoStreamTrack;
@ -58,8 +58,6 @@ class DOMMediaStream : public DOMEventTargetHelper,
public:
typedef dom::MediaTrackConstraints MediaTrackConstraints;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(DOMMediaStream)
class TrackListener {
public:
virtual ~TrackListener() = default;

View File

@ -292,12 +292,11 @@ void MediaManager::CallOnSuccess(GetUserMediaSuccessCallback& aCallback,
* only from main thread, to ensure that garbage- and cycle-collected objects
* don't hold a reference to it during late shutdown.
*/
class SourceListener : public SupportsWeakPtr<SourceListener> {
class SourceListener : public SupportsWeakPtr {
public:
typedef MozPromise<bool /* aIgnored */, RefPtr<MediaMgrError>, true>
SourceListenerPromise;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(SourceListener)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(
SourceListener)

View File

@ -54,10 +54,8 @@ class MediaStreamTrackSource : public nsISupports {
NS_DECL_CYCLE_COLLECTION_CLASS(MediaStreamTrackSource)
public:
class Sink : public SupportsWeakPtr<Sink> {
class Sink : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackSource::Sink)
/**
* Must be constant throughout the Sink's lifetime.
*
@ -345,11 +343,8 @@ class BasicTrackSource : public MediaStreamTrackSource {
* Base class that consumers of a MediaStreamTrack can use to get notifications
* about state changes in the track.
*/
class MediaStreamTrackConsumer
: public SupportsWeakPtr<MediaStreamTrackConsumer> {
class MediaStreamTrackConsumer : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackConsumer)
/**
* Called when the track's readyState transitions to "ended".
* Unlike the "ended" event exposed to script this is called for any reason,
@ -400,8 +395,7 @@ class MediaStreamTrackConsumer
* (*) is a copy of A's mInputTrack
*/
// clang-format on
class MediaStreamTrack : public DOMEventTargetHelper,
public SupportsWeakPtr<MediaStreamTrack> {
class MediaStreamTrack : public DOMEventTargetHelper, public SupportsWeakPtr {
// PeerConnection and friends need to know our owning DOMStream and track id.
friend class mozilla::PeerConnectionImpl;
friend class mozilla::PeerConnectionMedia;
@ -423,8 +417,6 @@ class MediaStreamTrack : public DOMEventTargetHelper,
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrack,
DOMEventTargetHelper)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrack)
nsPIDOMWindowInner* GetParentObject() const { return mWindow; }
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

View File

@ -50,14 +50,13 @@ typedef uint32_t PromiseId;
// Note: its addref/release is not (and can't be) thread safe!
class MediaKeys final : public nsIDocumentActivity,
public nsWrapperCache,
public SupportsWeakPtr<MediaKeys>,
public SupportsWeakPtr,
public DecoderDoctorLifeLogger<MediaKeys> {
~MediaKeys();
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaKeys)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaKeys)
// We want to listen to the owning document so we can shutdown if it goes
// inactive.
NS_DECL_NSIDOCUMENTACTIVITY

View File

@ -42,14 +42,13 @@ class MediaStreamTrackAudioSourceNodeEngine final : public AudioNodeEngine {
class MediaStreamTrackAudioSourceNode
: public AudioNode,
public PrincipalChangeObserver<MediaStreamTrack>,
public SupportsWeakPtr<MediaStreamTrackAudioSourceNode> {
public SupportsWeakPtr {
public:
static already_AddRefed<MediaStreamTrackAudioSourceNode> Create(
AudioContext& aContext,
const MediaStreamTrackAudioSourceOptions& aOptions, ErrorResult& aRv);
NS_DECL_ISUPPORTS_INHERITED
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackAudioSourceNode)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrackAudioSourceNode,
AudioNode)

View File

@ -53,9 +53,8 @@ LogModule* GetSpeechRecognitionLog();
class SpeechRecognition final : public DOMEventTargetHelper,
public nsIObserver,
public DOMMediaStream::TrackListener,
public SupportsWeakPtr<SpeechRecognition> {
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(SpeechRecognition)
explicit SpeechRecognition(nsPIDOMWindowInner* aOwnerWindow);
NS_DECL_ISUPPORTS_INHERITED

View File

@ -77,16 +77,14 @@ class nsNPAPITimer {
bool needUnschedule;
};
class nsNPAPIPluginInstance final
: public nsIAudioChannelAgentCallback,
public mozilla::SupportsWeakPtr<nsNPAPIPluginInstance> {
class nsNPAPIPluginInstance final : public nsIAudioChannelAgentCallback,
public mozilla::SupportsWeakPtr {
private:
typedef mozilla::PluginLibrary PluginLibrary;
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsNPAPIPluginInstance)
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK

View File

@ -93,11 +93,9 @@ void PluginWindowEvent::Init(WeakPtr<nsPluginNativeWindowWin> aRef, HWND aWnd,
* nsPluginNativeWindow Windows specific class declaration
*/
class nsPluginNativeWindowWin
: public nsPluginNativeWindow,
public SupportsWeakPtr<nsPluginNativeWindowWin> {
class nsPluginNativeWindowWin : public nsPluginNativeWindow,
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPluginNativeWindowWin)
nsPluginNativeWindowWin();
virtual nsresult CallSetWindow(

View File

@ -19,13 +19,12 @@ class Promise;
class PresentationAvailability final
: public DOMEventTargetHelper,
public nsIPresentationAvailabilityListener,
public SupportsWeakPtr<PresentationAvailability> {
public SupportsWeakPtr {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationAvailability,
DOMEventTargetHelper)
NS_DECL_NSIPRESENTATIONAVAILABILITYLISTENER
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PresentationAvailability)
static already_AddRefed<PresentationAvailability> Create(
nsPIDOMWindowInner* aWindow, const nsTArray<nsString>& aUrls,

View File

@ -22,18 +22,16 @@ namespace dom {
class Blob;
class PresentationConnectionList;
class PresentationConnection final
: public DOMEventTargetHelper,
public nsIPresentationSessionListener,
public nsIRequest,
public SupportsWeakPtr<PresentationConnection> {
class PresentationConnection final : public DOMEventTargetHelper,
public nsIPresentationSessionListener,
public nsIRequest,
public SupportsWeakPtr {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationConnection,
DOMEventTargetHelper)
NS_DECL_NSIPRESENTATIONSESSIONLISTENER
NS_DECL_NSIREQUEST
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PresentationConnection)
static already_AddRefed<PresentationConnection> Create(
nsPIDOMWindowInner* aWindow, const nsAString& aId, const nsAString& aUrl,

View File

@ -35,7 +35,7 @@ class PromiseInit;
class PromiseNativeHandler;
class PromiseDebugging;
class Promise : public SupportsWeakPtr<Promise> {
class Promise : public SupportsWeakPtr {
friend class PromiseTask;
friend class PromiseWorkerProxy;
friend class PromiseWorkerProxyRunnable;
@ -43,7 +43,6 @@ class Promise : public SupportsWeakPtr<Promise> {
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Promise)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(Promise)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Promise)
enum PropagateUserInteraction {
eDontPropagateUserInteraction,

View File

@ -25,8 +25,7 @@ struct WGPUTextureViewDescriptor;
struct TextureInfo;
typedef MozPromise<RawId, Maybe<ipc::ResponseRejectReason>, true> RawIdPromise;
class WebGPUChild final : public PWebGPUChild,
public SupportsWeakPtr<WebGPUChild> {
class WebGPUChild final : public PWebGPUChild {
public:
friend class layers::CompositorBridgeChild;

View File

@ -24,13 +24,11 @@ struct PostMessageOptions;
struct WorkerOptions;
class WorkerPrivate;
class Worker : public DOMEventTargetHelper, public SupportsWeakPtr<Worker> {
class Worker : public DOMEventTargetHelper, public SupportsWeakPtr {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Worker,
DOMEventTargetHelper)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Worker)
static already_AddRefed<Worker> Constructor(const GlobalObject& aGlobal,
const nsAString& aScriptURL,
const WorkerOptions& aOptions,

View File

@ -29,9 +29,8 @@ class Text;
* composition string, modifying the composition string or its IME selection
* ranges and commit or cancel the composition.
*/
class CompositionTransaction final
: public EditTransactionBase,
public SupportsWeakPtr<CompositionTransaction> {
class CompositionTransaction final : public EditTransactionBase,
public SupportsWeakPtr {
protected:
CompositionTransaction(EditorBase& aEditorBase,
const nsAString& aStringToInsert,
@ -54,8 +53,6 @@ class CompositionTransaction final
EditorBase& aEditorBase, const nsAString& aStringToInsert,
const EditorDOMPointInText& aPointToInsert);
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(CompositionTransaction)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CompositionTransaction,
EditTransactionBase)

View File

@ -22,9 +22,8 @@ class EditorBase;
* transactions it has absorbed.
*/
class PlaceholderTransaction final
: public EditAggregateTransaction,
public SupportsWeakPtr<PlaceholderTransaction> {
class PlaceholderTransaction final : public EditAggregateTransaction,
public SupportsWeakPtr {
protected:
PlaceholderTransaction(EditorBase& aEditorBase, nsStaticAtom& aName,
Maybe<SelectionState>&& aSelState);
@ -48,8 +47,6 @@ class PlaceholderTransaction final
return transaction.forget();
}
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PlaceholderTransaction)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTransaction,

View File

@ -189,10 +189,8 @@ enum class GLRenderer {
Other
};
class GLContext : public GenericAtomicRefCounted,
public SupportsWeakPtr<GLContext> {
class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
static MOZ_THREAD_LOCAL(uintptr_t) sCurrentContext;
const GLContextDesc mDesc;

View File

@ -15,14 +15,12 @@
namespace mozilla {
namespace gl {
class DepthAndStencilBuffer final
: public SupportsWeakPtr<DepthAndStencilBuffer> {
class DepthAndStencilBuffer final : public SupportsWeakPtr {
const WeakPtr<GLContext> mWeakGL;
const gfx::IntSize mSize;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DepthAndStencilBuffer)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(DepthAndStencilBuffer)
const GLuint mDepthRB;
const GLuint mStencilRB;

View File

@ -363,14 +363,12 @@ class ImageContainerListener final {
* synchronously updates the shared state to point to the new image and the old
* image is immediately released (not true in Normal or Asynchronous modes).
*/
class ImageContainer final : public SupportsWeakPtr<ImageContainer> {
class ImageContainer final : public SupportsWeakPtr {
friend class ImageContainerChild;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageContainer)
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ImageContainer)
enum Mode { SYNCHRONOUS = 0x0, ASYNCHRONOUS = 0x01 };
static const uint64_t sInvalidAsyncContainerId = 0;

View File

@ -98,14 +98,12 @@ struct CompositorAnimationIdsForEpoch {
nsTArray<uint64_t> mIds;
};
class WebRenderBridgeParent final
: public PWebRenderBridgeParent,
public CompositorVsyncSchedulerOwner,
public CompositableParentManager,
public layers::FrameRecorder,
public SupportsWeakPtr<WebRenderBridgeParent> {
class WebRenderBridgeParent final : public PWebRenderBridgeParent,
public CompositorVsyncSchedulerOwner,
public CompositableParentManager,
public layers::FrameRecorder,
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebRenderBridgeParent)
WebRenderBridgeParent(CompositorBridgeParentBase* aCompositorBridge,
const wr::PipelineId& aPipelineId,
widget::CompositorWidget* aWidget,

View File

@ -27,10 +27,8 @@ namespace image {
* possible. In the long term, it would be ideal to get to a place where we can
* just use the imgINotificationObserver interface internally as well.
*/
class IProgressObserver : public SupportsWeakPtr<IProgressObserver> {
class IProgressObserver : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(IProgressObserver)
// Subclasses may or may not be XPCOM classes, so we just require that they
// implement AddRef and Release.
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING

View File

@ -99,11 +99,10 @@ class ObserverTable : public nsDataHashtable<nsPtrHashKey<IProgressObserver>,
* argument, and the notifications will be replayed to the observer
* asynchronously.
*/
class ProgressTracker : public mozilla::SupportsWeakPtr<ProgressTracker> {
class ProgressTracker : public mozilla::SupportsWeakPtr {
virtual ~ProgressTracker() {}
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ProgressTracker)
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ProgressTracker)
ProgressTracker();

View File

@ -158,7 +158,7 @@ class ImageMetadata;
class SourceBuffer;
class RasterImage final : public ImageResource,
public SupportsWeakPtr<RasterImage>
public SupportsWeakPtr
#ifdef DEBUG
,
public imgIContainerDebug
@ -168,7 +168,6 @@ class RasterImage final : public ImageResource,
virtual ~RasterImage();
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(RasterImage)
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_IMGICONTAINER
#ifdef DEBUG

View File

@ -3300,8 +3300,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
inherits.append(Inherit(p.managerInterfaceType(), viz='public'))
if hasAsyncReturns:
inherits.append(Inherit(Type('SupportsWeakPtr', T=ExprVar(self.clsname)),
viz='public'))
inherits.append(Inherit(Type('SupportsWeakPtr'), viz='public'))
self.hdrfile.addthing(CppDirective('include', '"mozilla/WeakPtr.h"'))
if ptype.isToplevel() and self.side == 'parent':
@ -3315,15 +3314,6 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
inherits=inherits,
abstract=True)
if hasAsyncReturns:
self.cls.addstmts([
Label.PUBLIC,
Whitespace('', indent=True),
ExprCall(ExprVar('MOZ_DECLARE_WEAKREFERENCE_TYPENAME'),
[ExprVar(self.clsname)]),
Whitespace.NL
])
self.cls.addstmt(Label.PRIVATE)
friends = _FindFriends().findFriends(ptype)
if ptype.isManaged():

View File

@ -19,10 +19,9 @@
class SandboxPrivate : public nsIGlobalObject,
public nsIScriptObjectPrincipal,
public nsSupportsWeakReference,
public mozilla::SupportsWeakPtr<SandboxPrivate>,
public mozilla::SupportsWeakPtr,
public nsWrapperCache {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(SandboxPrivate);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(SandboxPrivate,
nsIGlobalObject)

View File

@ -126,8 +126,7 @@ class nsRootPresContext;
// An interface for presentation contexts. Presentation contexts are
// objects that provide an outer context for a presentation shell.
class nsPresContext : public nsISupports,
public mozilla::SupportsWeakPtr<nsPresContext> {
class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
public:
using Encoding = mozilla::Encoding;
template <typename T>
@ -140,7 +139,6 @@ class nsPresContext : public nsISupports,
NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL
NS_DECL_CYCLE_COLLECTION_CLASS(nsPresContext)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsPresContext)
enum nsPresContextType {
eContext_Galley, // unpaginated screen presentation

View File

@ -2460,6 +2460,8 @@ void nsRefreshDriver::SetThrottled(bool aThrottled) {
}
}
nsPresContext* nsRefreshDriver::GetPresContext() const { return mPresContext; }
/*static*/
void nsRefreshDriver::PVsyncActorCreated(VsyncChild* aVsyncChild) {
MOZ_ASSERT(NS_IsMainThread());

View File

@ -333,7 +333,7 @@ class nsRefreshDriver final : public mozilla::layers::TransactionIdAllocator,
/**
* Return the prescontext we were initialized with
*/
nsPresContext* GetPresContext() const { return mPresContext; }
nsPresContext* GetPresContext() const;
/**
* PBackgroundChild actor is created asynchronously in content process.

View File

@ -51,8 +51,7 @@ class CSSStyleRuleDeclaration final : public nsDOMCSSDeclaration {
RefPtr<DeclarationBlock> mDecls;
};
class CSSStyleRule final : public BindingStyleRule,
public SupportsWeakPtr<CSSStyleRule> {
class CSSStyleRule final : public BindingStyleRule, public SupportsWeakPtr {
public:
CSSStyleRule(already_AddRefed<RawServoStyleRule> aRawRule, StyleSheet* aSheet,
css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);
@ -62,8 +61,6 @@ class CSSStyleRule final : public BindingStyleRule,
css::Rule)
bool IsCCLeaf() const final MOZ_MUST_OVERRIDE;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(CSSStyleRule)
uint32_t GetSelectorCount() override;
nsresult GetSelectorText(uint32_t aSelectorIndex, nsAString& aText) override;
nsresult GetSpecificity(uint32_t aSelectorIndex,

View File

@ -39,8 +39,6 @@ static_assert(eAuthorSheetFeatures == 0 && eUserSheetFeatures == 1 &&
"in SheetLoadData::mParsingMode");
class SheetLoadData final : public PreloaderBase,
// FIXME(bug 1653011): This is a bit unfortunate.
public SupportsWeakPtr<SheetLoadData>,
public nsIRunnable,
public nsIThreadObserver {
using MediaMatched = dom::LinkStyle::MediaMatched;

View File

@ -16,10 +16,6 @@
*
* PLEASE NOTE: This weak pointer implementation is not thread-safe.
*
* Note that when deriving from SupportsWeakPtr you should add
* MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ClassName) to the public section of your
* class, where ClassName is the name of your class.
*
* The overhead of WeakPtr is that accesses to 'Foo' becomes an additional
* dereference, and an additional heap allocated pointer sized object shared
* between all of the WeakPtrs.
@ -27,11 +23,10 @@
* Example of usage:
*
* // To have a class C support weak pointers, inherit from
* // SupportsWeakPtr<C>.
* class C : public SupportsWeakPtr<C>
* // SupportsWeakPtr
* class C : public SupportsWeakPtr
* {
* public:
* MOZ_DECLARE_WEAKREFERENCE_TYPENAME(C)
* int mNum;
* void act();
* };
@ -62,6 +57,9 @@
*
* The API was loosely inspired by Chromium's weak_ptr.h:
* http://src.chromium.org/svn/trunk/src/base/memory/weak_ptr.h
*
* Note that multiple base classes inheriting from SupportsWeakPtr is not
* currently supported. We could support it if needed though.
*/
#ifndef mozilla_WeakPtr_h
@ -85,7 +83,7 @@
#if defined(MOZILLA_INTERNAL_API) && \
defined(MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED)
// Weak referencing is not implemeted as thread safe. When a WeakPtr
// Weak referencing is not implemented as thread safe. When a WeakPtr
// is created or dereferenced on thread A but the real object is just
// being Released() on thread B, there is a possibility of a race
// when the proxy object (detail::WeakReference) is notified about
@ -110,11 +108,11 @@
_owningThread.emplace(); \
} \
} while (false)
# define MOZ_WEAKPTR_ASSERT_THREAD_SAFETY() \
do { \
if (_owningThread.isSome() && !_owningThread.ref().IsCurrentThread()) { \
WeakPtrTraits<T>::AssertSafeToAccessFromNonOwningThread(); \
} \
# define MOZ_WEAKPTR_ASSERT_THREAD_SAFETY() \
do { \
MOZ_DIAGNOSTIC_ASSERT( \
!_owningThread || _owningThread->IsCurrentThread(), \
"WeakPtr accessed from multiple threads"); \
} while (false)
# define MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED(that) \
(that)->AssertThreadSafety();
@ -149,47 +147,26 @@ namespace mozilla {
template <typename T>
class WeakPtr;
template <typename T>
class SupportsWeakPtr;
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
# define MOZ_DECLARE_WEAKREFERENCE_TYPENAME(T) \
static const char* weakReferenceTypeName() { \
return "WeakReference<" #T ">"; \
}
#else
# define MOZ_DECLARE_WEAKREFERENCE_TYPENAME(T)
#endif
template <class T>
struct WeakPtrTraits {
static void AssertSafeToAccessFromNonOwningThread() {
MOZ_DIAGNOSTIC_ASSERT(false, "WeakPtr accessed from multiple threads");
}
};
namespace detail {
// This can live beyond the lifetime of the class derived from
// SupportsWeakPtr.
template <class T>
class WeakReference : public ::mozilla::RefCounted<WeakReference<T>> {
class WeakReference : public ::mozilla::RefCounted<WeakReference> {
public:
explicit WeakReference(T* p) : mPtr(p) {
explicit WeakReference(const SupportsWeakPtr* p)
: mPtr(const_cast<SupportsWeakPtr*>(p)) {
MOZ_WEAKPTR_INIT_THREAD_SAFETY_CHECK();
}
T* get() const {
SupportsWeakPtr* get() const {
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY();
return mPtr;
}
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
const char* typeName() const {
// The first time this is called mPtr is null, so don't
// invoke any methods on mPtr.
return T::weakReferenceTypeName();
}
const char* typeName() const { return "WeakReference"; }
size_t typeSize() const { return sizeof(*this); }
#endif
@ -198,62 +175,53 @@ class WeakReference : public ::mozilla::RefCounted<WeakReference<T>> {
#endif
private:
friend class mozilla::SupportsWeakPtr<T>;
friend class mozilla::SupportsWeakPtr;
void detach() {
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY();
mPtr = nullptr;
}
T* MOZ_NON_OWNING_REF mPtr;
SupportsWeakPtr* MOZ_NON_OWNING_REF mPtr;
MOZ_WEAKPTR_DECLARE_THREAD_SAFETY_CHECK
};
} // namespace detail
template <typename T>
class SupportsWeakPtr {
using WeakReference = detail::WeakReference;
protected:
~SupportsWeakPtr() {
static_assert(std::is_base_of<SupportsWeakPtr<T>, T>::value,
"T must derive from SupportsWeakPtr<T>");
DetachWeakPtr();
}
protected:
void DetachWeakPtr() {
if (mSelfReferencingWeakPtr) {
mSelfReferencingWeakPtr.mRef->detach();
if (mSelfReferencingWeakReference) {
mSelfReferencingWeakReference->detach();
}
}
private:
const WeakPtr<T>& SelfReferencingWeakPtr() {
if (!mSelfReferencingWeakPtr) {
mSelfReferencingWeakPtr.mRef =
new detail::WeakReference<T>(static_cast<T*>(this));
WeakReference* SelfReferencingWeakReference() const {
if (!mSelfReferencingWeakReference) {
mSelfReferencingWeakReference = new WeakReference(this);
} else {
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED(mSelfReferencingWeakPtr.mRef);
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED(mSelfReferencingWeakReference);
}
return mSelfReferencingWeakPtr;
return mSelfReferencingWeakReference.get();
}
const WeakPtr<const T>& SelfReferencingWeakPtr() const {
const WeakPtr<T>& p =
const_cast<SupportsWeakPtr*>(this)->SelfReferencingWeakPtr();
return reinterpret_cast<const WeakPtr<const T>&>(p);
}
template <typename U>
friend class WeakPtr;
friend class WeakPtr<T>;
friend class WeakPtr<const T>;
WeakPtr<T> mSelfReferencingWeakPtr;
mutable RefPtr<WeakReference> mSelfReferencingWeakReference;
};
template <typename T>
class WeakPtr {
typedef detail::WeakReference<T> WeakReference;
using NonConstT = std::remove_const_t<T>;
using WeakReference = detail::WeakReference;
public:
WeakPtr& operator=(const WeakPtr& aOther) {
@ -283,27 +251,12 @@ class WeakPtr {
return *this;
}
WeakPtr& operator=(SupportsWeakPtr<NonConstT> const* aOther) {
WeakPtr& operator=(const T* aOther) {
// We must make sure the reference we have now is safe to be dereferenced
// before we throw it away.
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED_IF(mRef);
if (aOther) {
*this = aOther->SelfReferencingWeakPtr();
} else if (!mRef || mRef->get()) {
// Ensure that mRef is dereferenceable in the uninitialized state.
mRef = new WeakReference(nullptr);
}
// The thread safety check happens inside SelfReferencingWeakPtr
// or is initialized in the WeakReference constructor.
return *this;
}
WeakPtr& operator=(SupportsWeakPtr<NonConstT>* aOther) {
// We must make sure the reference we have now is safe to be dereferenced
// before we throw it away.
MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED_IF(mRef);
if (aOther) {
*this = aOther->SelfReferencingWeakPtr();
mRef = aOther->SelfReferencingWeakReference();
} else if (!mRef || mRef->get()) {
// Ensure that mRef is dereferenceable in the uninitialized state.
mRef = new WeakReference(nullptr);
@ -318,17 +271,16 @@ class WeakPtr {
// Ensure that mRef is dereferenceable in the uninitialized state.
WeakPtr() : mRef(new WeakReference(nullptr)) {}
operator T*() const { return mRef->get(); }
T& operator*() const { return *mRef->get(); }
T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN { return mRef->get(); }
T* get() const { return mRef->get(); }
explicit operator bool() const { return mRef->get(); }
T* get() const { return static_cast<T*>(mRef->get()); }
operator T*() const { return get(); }
T& operator*() const { return *get(); }
T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN { return get(); }
~WeakPtr() { MOZ_WEAKPTR_ASSERT_THREAD_SAFETY_DELEGATED(mRef); }
private:
friend class SupportsWeakPtr<T>;
friend class SupportsWeakPtr;
explicit WeakPtr(const RefPtr<WeakReference>& aOther) : mRef(aOther) {}

View File

@ -12,18 +12,15 @@ using mozilla::WeakPtr;
static char IamB[] = "B";
static char IamC[] = "C";
static char IamD[] = "D";
static char IamE[] = "E";
class B : public SupportsWeakPtr<B> {
class B : public SupportsWeakPtr {
public:
char const* whoAmI() const { return IamB; }
};
// To have a class C support weak pointers, inherit from SupportsWeakPtr<C>.
class C : public SupportsWeakPtr<C> {
// To have a class C support weak pointers, inherit from SupportsWeakPtr.
class C : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(C)
int mNum;
C() : mNum(0) {}
@ -43,17 +40,11 @@ class C : public SupportsWeakPtr<C> {
bool isConst() const { return true; }
};
// Supports weakptr for two base classes (B and C) and itself (D)
class D : public B, public C, public SupportsWeakPtr<D> {
public:
char const* whoAmI() const { return IamD; }
};
// Derived from a class that supports weakptr, but doesn't implement itself
// To check upcast works as expected
class E : public D {
class D : public B {
public:
char const* whoAmI() const { return IamE; }
char const* whoAmI() const { return IamD; }
};
bool isConst(C*) { return false; }
@ -136,38 +127,19 @@ int main() {
delete c2;
MOZ_RELEASE_ASSERT(!w2, "Deleting an object should clear WeakPtr's to it.");
// Testing multiple base classes weak pointer support
// Check that we correctly upcast to the base class supporting weakptr
D* d = new D;
WeakPtr<D> dd = d;
WeakPtr<const D> ddconst = d;
WeakPtr<C> dc = d;
WeakPtr<const C> dcconst = d;
WeakPtr<B> db = d;
WeakPtr<const B> dbconst = d;
MOZ_RELEASE_ASSERT(dd->whoAmI() == IamD);
MOZ_RELEASE_ASSERT(ddconst->whoAmI() == IamD);
MOZ_RELEASE_ASSERT(dc->whoAmI() == IamC);
MOZ_RELEASE_ASSERT(dcconst->whoAmI() == IamC);
// You should be able to use WeakPtr<D> even if it's a base class which
// implements SupportsWeakPtr.
WeakPtr<D> weakd = d;
MOZ_RELEASE_ASSERT(db->whoAmI() == IamB);
MOZ_RELEASE_ASSERT(dbconst->whoAmI() == IamB);
MOZ_RELEASE_ASSERT(weakd.get() == db.get());
delete d;
MOZ_RELEASE_ASSERT(!dd);
MOZ_RELEASE_ASSERT(!ddconst);
MOZ_RELEASE_ASSERT(!dc);
MOZ_RELEASE_ASSERT(!dcconst);
MOZ_RELEASE_ASSERT(!db);
MOZ_RELEASE_ASSERT(!dbconst);
// Check that we correctly upcast to the base class supporting weakptr
E* e = new E;
WeakPtr<D> ed = e;
MOZ_RELEASE_ASSERT(ed->whoAmI() == IamD);
delete e;
MOZ_RELEASE_ASSERT(!ed);
MOZ_RELEASE_ASSERT(!weakd);
}

View File

@ -31,9 +31,8 @@ class Http2Decompressor;
class Http2Stream : public nsAHttpSegmentReader,
public nsAHttpSegmentWriter,
public SupportsWeakPtr<Http2Stream> {
public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(Http2Stream)
NS_DECL_NSAHTTPSEGMENTREADER
NS_DECL_NSAHTTPSEGMENTWRITER

View File

@ -130,11 +130,8 @@ class DataChannelConnection final : public net::NeckoTargetHolder
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DataChannelConnection)
class DataConnectionListener
: public SupportsWeakPtr<DataConnectionListener> {
class DataConnectionListener : public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(
DataChannelConnection::DataConnectionListener)
virtual ~DataConnectionListener() = default;
// Called when a new DataChannel has been opened by the other side.

View File

@ -36,11 +36,10 @@ class WebExtensionContentScript;
class WebExtensionPolicy final : public nsISupports,
public nsWrapperCache,
public SupportsWeakPtr<WebExtensionPolicy> {
public SupportsWeakPtr {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WebExtensionPolicy)
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebExtensionPolicy)
using ScriptArray = nsTArray<RefPtr<WebExtensionContentScript>>;

View File

@ -110,11 +110,10 @@ struct ChannelHolder {
class WebRequestChannelEntry;
class ChannelWrapper final : public DOMEventTargetHelper,
public SupportsWeakPtr<ChannelWrapper>,
public SupportsWeakPtr,
public LinkedListElement<ChannelWrapper>,
private detail::ChannelHolder {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ChannelWrapper)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ChannelWrapper,
DOMEventTargetHelper)

View File

@ -14,12 +14,10 @@
namespace mozilla {
namespace places {
class INativePlacesEventCallback
: public SupportsWeakPtr<INativePlacesEventCallback> {
class INativePlacesEventCallback : public SupportsWeakPtr {
public:
typedef dom::Sequence<OwningNonNull<dom::PlacesEvent>> PlacesEventSequence;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(INativePlacesEventCallback)
NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
virtual void HandlePlacesEvent(const PlacesEventSequence& aEvents) = 0;

View File

@ -183,10 +183,8 @@ class nsOfflineManifestItem : public nsOfflineCacheUpdateItem {
nsCString mOldManifestHashValue;
};
class nsOfflineCacheUpdateOwner
: public mozilla::SupportsWeakPtr<nsOfflineCacheUpdateOwner> {
class nsOfflineCacheUpdateOwner : public mozilla::SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsOfflineCacheUpdateOwner)
virtual ~nsOfflineCacheUpdateOwner() {}
virtual nsresult UpdateFinished(nsOfflineCacheUpdate* aUpdate) = 0;
};

View File

@ -39,10 +39,8 @@ class Document;
*
* This class is designed to be used only on the main thread.
*/
class PreloaderBase : public SupportsWeakPtr<PreloaderBase>,
public nsISupports {
class PreloaderBase : public SupportsWeakPtr, public nsISupports {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PreloaderBase)
PreloaderBase() = default;
// Called by resource loaders to register this preload in the document's

View File

@ -53,19 +53,18 @@ namespace jni {
* a single thread. To attach a Java instance to a C++ instance, pass in a
* mozilla::SupportsWeakPtr pointer to the C++ class (i.e. MyClass*).
*
* class MyClass : public SupportsWeakPtr<MyClass>
* class MyClass : public SupportsWeakPtr
* , public MyJavaClass::Natives<MyClass>
* {
* // ...
*
* public:
* MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MyClass)
* using MyJavaClass::Natives<MyClass>::DisposeNative;
*
* void AttachTo(const MyJavaClass::LocalRef& instance)
* {
* MyJavaClass::Natives<MyClass>::AttachNative(
* instance, static_cast<SupportsWeakPtr<MyClass>*>(this));
* instance, static_cast<SupportsWeakPtr*>(this));
*
* // "instance" does NOT own "this", so the C++ object
* // lifetime is separate from the Java object lifetime.
@ -128,7 +127,7 @@ enum NativePtrType { OWNING, WEAK, REFPTR };
template <class Impl>
class NativePtrPicker {
template <class I>
static std::enable_if_t<std::is_base_of<SupportsWeakPtr<I>, I>::value,
static std::enable_if_t<std::is_base_of<SupportsWeakPtr, I>::value,
char (&)[NativePtrType::WEAK]>
Test(char);
@ -768,7 +767,7 @@ class NativeImpl {
protected:
// Associate a C++ instance with a Java instance.
static void AttachNative(const typename Cls::LocalRef& instance,
SupportsWeakPtr<Impl>* ptr) {
SupportsWeakPtr* ptr) {
static_assert(NativePtrPicker<Impl>::value == NativePtrType::WEAK,
"Use another AttachNative for non-WeakPtr usage");
return NativePtr<Impl>::Set(instance, static_cast<Impl*>(ptr));

View File

@ -296,7 +296,7 @@ class nsWindow::NativePtr<Impl>::Locked final : private MutexAutoLock {
class nsWindow::GeckoViewSupport final
: public GeckoSession::Window::Natives<GeckoViewSupport>,
public SupportsWeakPtr<GeckoViewSupport> {
public SupportsWeakPtr {
nsWindow& window;
// We hold a WeakRef because we want to allow the
@ -307,9 +307,6 @@ class nsWindow::GeckoViewSupport final
public:
typedef GeckoSession::Window::Natives<GeckoViewSupport> Base;
typedef SupportsWeakPtr<GeckoViewSupport> SupportsWeakPtr;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GeckoViewSupport);
template <typename Functor>
static void OnNativeCall(Functor&& aCall) {

View File

@ -27,10 +27,8 @@ namespace {
* Note that the MessageLoop owns this object and will delete it after it calls
* Run(). Tread lightly.
*/
class MessageLoopIdleTask : public Runnable,
public SupportsWeakPtr<MessageLoopIdleTask> {
class MessageLoopIdleTask : public Runnable, public SupportsWeakPtr {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MessageLoopIdleTask)
MessageLoopIdleTask(nsIRunnable* aTask, uint32_t aEnsureRunsAfterMS);
NS_IMETHOD Run() override;