Bug 1286459 - Use WeakPtr for deferred references. - r=jrmuizel
MozReview-Commit-ID: IrDMIEy5fd1
--- a/dom/canvas/WebGLTimerQuery.cpp
+++ b/dom/canvas/WebGLTimerQuery.cpp
@@ -58,18 +58,25 @@ WebGLContext*
WebGLTimerQuery::GetParentObject() const
{
return mContext;
}
void
WebGLTimerQuery::QueueAvailablity()
{
- RefPtr<WebGLTimerQuery> self = this;
- NS_DispatchToCurrentThread(NS_NewRunnableFunction([self] { self->mCanBeAvailable = true; }));
+ WeakPtr<WebGLTimerQuery> weakPtr = this;
+
+ const auto fnMakeAvailable = [weakPtr]() { // Copy the WeakPtr.
+ if (weakPtr) {
+ weakPtr->mCanBeAvailable = true;
+ }
+ };
+
+ NS_DispatchToCurrentThread(NS_NewRunnableFunction(fnMakeAvailable));
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTimerQuery)
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLTimerQuery, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLTimerQuery, Release)
} // namespace mozilla
--- a/dom/canvas/WebGLTimerQuery.h
+++ b/dom/canvas/WebGLTimerQuery.h
@@ -13,28 +13,30 @@
namespace mozilla {
class WebGLTimerQuery final
: public nsWrapperCache
, public WebGLRefCountedObject<WebGLTimerQuery>
, public LinkedListElement<WebGLTimerQuery>
, public WebGLContextBoundObject
+ , public SupportsWeakPtr<WebGLTimerQuery>
{
friend class WebGLExtensionDisjointTimerQuery;
public:
const GLenum mGLName;
protected:
GLenum mTarget;
bool mCanBeAvailable;
public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLTimerQuery)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLTimerQuery)
+ MOZ_DECLARE_WEAKREFERENCE_TYPENAME(WebGLTimerQuery)
static WebGLTimerQuery* Create(WebGLContext* webgl);
private:
explicit WebGLTimerQuery(WebGLContext* webgl, GLuint name);
~WebGLTimerQuery();
void Delete();