Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / xpcom / base / nsIWeakReference.idl
blob723fa8434439b32c685a170adeb59b32715f0ce1
1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 "nsISupports.idl"
9 %{C++
10 #include "mozilla/Attributes.h"
11 #include "mozilla/MemoryReporting.h"
13 // For MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED.
14 #include "nsDebug.h"
16 #ifdef MOZ_THREAD_SAFETY_OWNERSHIP_CHECKS_SUPPORTED
18 #define MOZ_WEAKREF_DECL_OWNINGTHREAD nsAutoOwningThread _mWeakRefOwningThread;
19 #define MOZ_WEAKREF_ASSERT_OWNINGTHREAD \
20 _mWeakRefOwningThread.AssertOwnership("nsWeakReference not thread-safe")
21 #define MOZ_WEAKREF_ASSERT_OWNINGTHREAD_DELEGATED(that) \
22 (that)->_mWeakRefOwningThread.AssertOwnership("nsWeakReference not thread-safe")
24 #else
26 #define MOZ_WEAKREF_DECL_OWNINGTHREAD
27 #define MOZ_WEAKREF_ASSERT_OWNINGTHREAD do { } while (false)
28 #define MOZ_WEAKREF_ASSERT_OWNINGTHREAD_DELEGATED(that) do { } while (false)
30 #endif
34 native MallocSizeOf(mozilla::MallocSizeOf);
36 /**
37 * An instance of |nsIWeakReference| is a proxy object that cooperates with
38 * its referent to give clients a non-owning, non-dangling reference. Clients
39 * own the proxy, and should generally manage it with an |nsCOMPtr| (see the
40 * type |nsWeakPtr| for a |typedef| name that stands out) as they would any
41 * other XPCOM object. The |QueryReferent| member function provides a
42 * (hopefully short-lived) owning reference on demand, through which clients
43 * can get useful access to the referent, while it still exists.
45 * @version 1.0
46 * @see nsISupportsWeakReference
47 * @see nsWeakReference
48 * @see nsWeakPtr
50 [scriptable, builtinclass, uuid(9188bc85-f92e-11d2-81ef-0060083a0bcf)]
51 interface nsIWeakReference : nsISupports
53 /**
54 * |QueryReferent| queries the referent, if it exists, and like |QueryInterface|, produces
55 * an owning reference to the desired interface. It is designed to look and act exactly
56 * like (a proxied) |QueryInterface|. Don't hold on to the produced interface permanently;
57 * that would defeat the purpose of using a non-owning |nsIWeakReference| in the first place.
59 [binaryname(QueryReferentFromScript)]
60 void QueryReferent( in nsIIDRef uuid, [iid_is(uuid), retval] out nsQIResult result );
62 [notxpcom, nostdcall] size_t sizeOfOnlyThis(in MallocSizeOf aMallocSizeOf);
63 %{C++
64 /**
65 * Returns true if the referring object is alive. Otherwise, false.
67 bool IsAlive() const
69 return !!mObject;
72 nsresult QueryReferent(const nsIID& aIID, void** aInstancePtr);
74 protected:
75 friend class nsSupportsWeakReference;
77 nsIWeakReference(nsISupports* aObject)
78 : mObject(aObject)
82 nsIWeakReference() = delete;
84 MOZ_WEAKREF_DECL_OWNINGTHREAD
86 // The object we're holding a weak reference to.
87 nsISupports* MOZ_NON_OWNING_REF mObject;
92 /**
93 * |nsISupportsWeakReference| is a factory interface which produces appropriate
94 * instances of |nsIWeakReference|. Weak references in this scheme can only be
95 * produced for objects that implement this interface.
97 * @version 1.0
98 * @see nsIWeakReference
99 * @see nsSupportsWeakReference
101 [scriptable, uuid(9188bc86-f92e-11d2-81ef-0060083a0bcf)]
102 interface nsISupportsWeakReference : nsISupports
105 * |GetWeakReference| produces an appropriate instance of |nsIWeakReference|.
106 * As with all good XPCOM `getters', you own the resulting interface and should
107 * manage it with an |nsCOMPtr|.
109 * @see nsIWeakReference
110 * @see nsWeakPtr
111 * @see nsCOMPtr
113 nsIWeakReference GetWeakReference();