Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / bindings / RootedRefPtr.h
blobf5b2323c0f1497547481da345a0039f06d4a173e
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/. */
7 /**
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
14 * templated over.
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"
24 namespace JS {
25 template <typename T>
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) {
30 if (*tp) {
31 (*tp)->Trace(trc);
35 static bool isValid(const RefPtr<T>& v) {
36 return !v || GCPolicy<T>::isValid(*v.get());
39 } // namespace JS
41 namespace js {
42 template <typename T, typename Wrapper>
43 struct WrappedPtrOperations<RefPtr<T>, Wrapper> {
44 operator T*() const { return static_cast<const Wrapper*>(this)->get(); }
46 } // namespace js
48 #endif /* mozilla_RootedRefPtr_h__ */