Bug 1107639 - Give PersistentRooted<Value> the standard operations on Value r=terrence

This commit is contained in:
Jon Coppeard 2015-01-23 10:23:56 +00:00
parent 3451f6624a
commit 4bb8091dcb
2 changed files with 27 additions and 4 deletions

View File

@ -118,6 +118,9 @@ class MutableHandleBase {};
template <typename T>
class HeapBase {};
template <typename T>
class PersistentRootedBase {};
/*
* js::NullPtr acts like a nullptr pointer in contexts that require a Handle.
*
@ -1098,8 +1101,10 @@ MutableHandle<T>::MutableHandle(PersistentRooted<T> *root)
* marked when the object itself is marked.
*/
template<typename T>
class PersistentRooted : private mozilla::LinkedListElement<PersistentRooted<T>> {
typedef mozilla::LinkedListElement<PersistentRooted<T>> Base;
class PersistentRooted : public js::PersistentRootedBase<T>,
private mozilla::LinkedListElement<PersistentRooted<T>>
{
typedef mozilla::LinkedListElement<PersistentRooted<T>> ListBase;
friend class mozilla::LinkedList<PersistentRooted>;
friend class mozilla::LinkedListElement<PersistentRooted>;
@ -1149,7 +1154,7 @@ class PersistentRooted : private mozilla::LinkedListElement<PersistentRooted<T>>
}
bool initialized() {
return Base::isInList();
return ListBase::isInList();
}
void init(JSContext *cx) {
@ -1175,7 +1180,7 @@ class PersistentRooted : private mozilla::LinkedListElement<PersistentRooted<T>>
void reset() {
if (initialized()) {
set(js::GCMethods<T>::initial());
Base::remove();
ListBase::remove();
}
}

View File

@ -1850,6 +1850,24 @@ class RootedBase<JS::Value> : public MutableValueOperations<JS::Rooted<JS::Value
}
};
/*
* Augment the generic PersistentRooted<T> interface when T = Value with type-querying,
* value-extracting, and mutating operations.
*/
template <>
class PersistentRootedBase<JS::Value> : public MutableValueOperations<JS::PersistentRooted<JS::Value>>
{
friend class ValueOperations<JS::PersistentRooted<JS::Value>>;
const JS::Value * extract() const {
return static_cast<const JS::PersistentRooted<JS::Value>*>(this)->address();
}
friend class MutableValueOperations<JS::PersistentRooted<JS::Value>>;
JS::Value * extractMutable() {
return static_cast<JS::PersistentRooted<JS::Value>*>(this)->address();
}
};
} // namespace js
inline jsval_layout