1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * An implementation of Rooted for RefPtr<T>. This works by assuming that T has
9 * a Trace() method defined on it which will trace whatever things inside the T
10 * instance need tracing.
12 * This implementation has one serious drawback: operator= doesn't work right
13 * because it's declared on Rooted directly and expects the type Rooted is
17 #ifndef mozilla_RootedRefPtr_h__
18 #define mozilla_RootedRefPtr_h__
20 #include "mozilla/RefPtr.h"
21 #include "js/GCPolicyAPI.h"
22 #include "js/TypeDecls.h"
26 struct GCPolicy
<RefPtr
<T
>> {
27 static RefPtr
<T
> initial() { return RefPtr
<T
>(); }
29 static void trace(JSTracer
* trc
, RefPtr
<T
>* tp
, const char* name
) {
35 static bool isValid(const RefPtr
<T
>& v
) {
36 return !v
|| GCPolicy
<T
>::isValid(*v
.get());
42 template <typename T
, typename Wrapper
>
43 struct WrappedPtrOperations
<RefPtr
<T
>, Wrapper
> {
44 operator T
*() const { return static_cast<const Wrapper
*>(this)->get(); }
48 #endif /* mozilla_RootedRefPtr_h__ */