Bug 766347 - Adjust Handle<T> constructors to only accept Rooted<S> or Handle<S> where S is convertible to T. r=luke

--HG--
extra : rebase_source : b0fd1627db78134185402fc1ab59112cc5ffb697
This commit is contained in:
Jeff Walden 2012-06-19 15:01:58 -07:00
Родитель d92c08b875
Коммит 9a4e830a16
1 изменённых файлов: 16 добавлений и 16 удалений

Просмотреть файл

@ -8,10 +8,15 @@
#ifndef jsgc_root_h__
#define jsgc_root_h__
#ifdef __cplusplus
#include "mozilla/TypeTraits.h"
#include "jspubtd.h"
#include "js/Utility.h"
#ifdef __cplusplus
namespace js {
@ -79,9 +84,11 @@ template <typename T>
class Handle
{
public:
/* Copy handles of different types, with implicit coercion. */
template <typename S> Handle(Handle<S> handle) {
testAssign<S>();
/* Creates a handle from a handle of a type convertible to T. */
template <typename S>
Handle(Handle<S> handle,
typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0)
{
ptr = reinterpret_cast<const T *>(handle.address());
}
@ -102,7 +109,10 @@ class Handle
* Construct a handle from an explicitly rooted location. This is the
* normal way to create a handle, and normally happens implicitly.
*/
template <typename S> inline Handle(Rooted<S> &root);
template <typename S>
inline
Handle(Rooted<S> &root,
typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0);
const T *address() const { return ptr; }
T value() const { return *ptr; }
@ -114,16 +124,6 @@ class Handle
Handle() {}
const T *ptr;
template <typename S>
void testAssign() {
#ifdef DEBUG
T a = RootMethods<T>::initial();
S b = RootMethods<S>::initial();
a = b;
(void)a;
#endif
}
};
typedef Handle<JSObject*> HandleObject;
@ -214,9 +214,9 @@ class Rooted
template<typename T> template <typename S>
inline
Handle<T>::Handle(Rooted<S> &root)
Handle<T>::Handle(Rooted<S> &root,
typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy)
{
testAssign<S>();
ptr = reinterpret_cast<const T *>(root.address());
}