Bug 1186154 - Templatize Rooted's context parameter to reduce copy-and-paste; r=jonco

This commit is contained in:
Terrence Cole 2015-07-21 12:57:00 -07:00
parent 93162fb8d5
commit e2f3fcd527

View File

@ -643,81 +643,43 @@ class MOZ_STACK_CLASS Rooted : public js::RootedBase<T>
"Rooted takes pointer or Traceable types but not Traceable* type");
/* Note: CX is a subclass of either ContextFriendFields or PerThreadDataFriendFields. */
template <typename CX>
void registerWithRootLists(CX* cx) {
void registerWithRootLists(js::RootLists& roots) {
js::ThingRootKind kind = js::RootKind<T>::rootKind();
this->stack = &cx->roots.stackRoots_[kind];
this->stack = &roots.stackRoots_[kind];
this->prev = *stack;
*stack = reinterpret_cast<Rooted<void*>*>(this);
}
static js::RootLists& rootListsForRootingContext(JSContext* cx) {
return js::ContextFriendFields::get(cx)->roots;
}
static js::RootLists& rootListsForRootingContext(js::ContextFriendFields* cx) {
return cx->roots;
}
static js::RootLists& rootListsForRootingContext(JSRuntime* rt) {
return js::PerThreadDataFriendFields::getMainThread(rt)->roots;
}
static js::RootLists& rootListsForRootingContext(js::PerThreadDataFriendFields* pt) {
return pt->roots;
}
public:
explicit Rooted(JSContext* cx
template <typename RootingContext>
explicit Rooted(const RootingContext& cx
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(js::GCMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(js::ContextFriendFields::get(cx));
registerWithRootLists(rootListsForRootingContext(cx));
}
template <typename S>
Rooted(JSContext* cx, S&& initial
template <typename RootingContext, typename S>
Rooted(const RootingContext& cx, S&& initial
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(mozilla::Forward<S>(initial))
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(js::ContextFriendFields::get(cx));
}
explicit Rooted(js::ContextFriendFields* cx
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(js::GCMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(cx);
}
template <typename S>
Rooted(js::ContextFriendFields* cx, S&& initial
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(mozilla::Forward<S>(initial))
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(cx);
}
explicit Rooted(js::PerThreadDataFriendFields* pt
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(js::GCMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(pt);
}
template <typename S>
Rooted(js::PerThreadDataFriendFields* pt, S&& initial
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(mozilla::Forward<S>(initial))
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(pt);
}
explicit Rooted(JSRuntime* rt
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(js::GCMethods<T>::initial())
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(js::PerThreadDataFriendFields::getMainThread(rt));
}
template <typename S>
Rooted(JSRuntime* rt, S&& initial
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: ptr(mozilla::Forward<S>(initial))
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
registerWithRootLists(js::PerThreadDataFriendFields::getMainThread(rt));
registerWithRootLists(rootListsForRootingContext(cx));
}
~Rooted() {