mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-04-02 12:32:55 +00:00
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:
parent
d92c08b875
commit
9a4e830a16
@ -8,10 +8,15 @@
|
|||||||
#ifndef jsgc_root_h__
|
#ifndef jsgc_root_h__
|
||||||
#define jsgc_root_h__
|
#define jsgc_root_h__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include "mozilla/TypeTraits.h"
|
||||||
|
|
||||||
#include "jspubtd.h"
|
#include "jspubtd.h"
|
||||||
|
|
||||||
#include "js/Utility.h"
|
#include "js/Utility.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
namespace js {
|
namespace js {
|
||||||
@ -79,9 +84,11 @@ template <typename T>
|
|||||||
class Handle
|
class Handle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/* Copy handles of different types, with implicit coercion. */
|
/* Creates a handle from a handle of a type convertible to T. */
|
||||||
template <typename S> Handle(Handle<S> handle) {
|
template <typename S>
|
||||||
testAssign<S>();
|
Handle(Handle<S> handle,
|
||||||
|
typename mozilla::EnableIf<mozilla::IsConvertible<S, T>::value, int>::Type dummy = 0)
|
||||||
|
{
|
||||||
ptr = reinterpret_cast<const T *>(handle.address());
|
ptr = reinterpret_cast<const T *>(handle.address());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +109,10 @@ class Handle
|
|||||||
* Construct a handle from an explicitly rooted location. This is the
|
* Construct a handle from an explicitly rooted location. This is the
|
||||||
* normal way to create a handle, and normally happens implicitly.
|
* 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; }
|
const T *address() const { return ptr; }
|
||||||
T value() const { return *ptr; }
|
T value() const { return *ptr; }
|
||||||
@ -114,16 +124,6 @@ class Handle
|
|||||||
Handle() {}
|
Handle() {}
|
||||||
|
|
||||||
const T *ptr;
|
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;
|
typedef Handle<JSObject*> HandleObject;
|
||||||
@ -214,9 +214,9 @@ class Rooted
|
|||||||
|
|
||||||
template<typename T> template <typename S>
|
template<typename T> template <typename S>
|
||||||
inline
|
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());
|
ptr = reinterpret_cast<const T *>(root.address());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user