Bug 1121489 - Make it possible to construct a RefPtr from an already_AddRefed; r=froydnj

This will pave the way towards having a MakeAndAddRef function
that returns an already_AddRefed and can be used in graphics code.
This commit is contained in:
Ehsan Akhgari 2015-01-14 10:09:28 -05:00
parent 33c16dc39d
commit 2a911035e1

View File

@ -9,6 +9,7 @@
#ifndef mozilla_RefPtr_h
#define mozilla_RefPtr_h
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/Assertions.h"
#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
@ -235,6 +236,7 @@ public:
RefPtr() : mPtr(0) {}
RefPtr(const RefPtr& aOther) : mPtr(ref(aOther.mPtr)) {}
MOZ_IMPLICIT RefPtr(const TemporaryRef<T>& aOther) : mPtr(aOther.take()) {}
MOZ_IMPLICIT RefPtr(already_AddRefed<T>& aOther) : mPtr(aOther.take()) {}
MOZ_IMPLICIT RefPtr(T* aVal) : mPtr(ref(aVal)) {}
template<typename U>
@ -252,6 +254,11 @@ public:
assign(aOther.take());
return *this;
}
RefPtr& operator=(const already_AddRefed<T>& aOther)
{
assign(aOther.take());
return *this;
}
RefPtr& operator=(T* aVal)
{
assign(ref(aVal));