mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1186154 - Templatize Rooted's context parameter to reduce copy-and-paste; r=jonco
This commit is contained in:
parent
93162fb8d5
commit
e2f3fcd527
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user