Bug 1189722 - Fix const methods in MutableTraceableVectorOperations r=terrence

This commit is contained in:
Jon Coppeard 2015-08-03 11:47:11 +01:00
parent 387201c73f
commit ecb3e74e2c
2 changed files with 42 additions and 0 deletions

View File

@ -77,13 +77,19 @@ class MutableTraceableVectorOperations
: public TraceableVectorOperations<Outer, T, Capacity, AllocPolicy, TraceFunc>
{
using Vec = TraceableVector<T, Capacity, AllocPolicy, TraceFunc>;
const Vec& vec() const { return static_cast<const Outer*>(this)->extract(); }
Vec& vec() { return static_cast<Outer*>(this)->extract(); }
public:
const AllocPolicy& allocPolicy() const { return vec().allocPolicy(); }
AllocPolicy& allocPolicy() { return vec().allocPolicy(); }
const T* begin() const { return vec().begin(); }
T* begin() { return vec().begin(); }
const T* end() const { return vec().end(); }
T* end() { return vec().end(); }
const T& operator[](size_t aIndex) const { return vec().operator[](aIndex); }
T& operator[](size_t aIndex) { return vec().operator[](aIndex); }
const T& back() const { return vec().back(); }
T& back() { return vec().back(); }
bool initCapacity(size_t aRequest) { return vec().initCapacity(aRequest); }

View File

@ -271,6 +271,42 @@ BEGIN_TEST(testGCRootedVector)
CHECK(shape);
}
CHECK(receiveConstRefToShapeVector(shapes));
// Ensure rooted converts to handles.
CHECK(receiveHandleToShapeVector(shapes));
CHECK(receiveMutableHandleToShapeVector(&shapes));
return true;
}
bool
receiveConstRefToShapeVector(const JS::Rooted<TraceableVector<Shape*>>& rooted)
{
// Ensure range enumeration works through the reference.
for (auto shape : rooted) {
CHECK(shape);
}
return true;
}
bool
receiveHandleToShapeVector(JS::Handle<TraceableVector<Shape*>> handle)
{
// Ensure range enumeration works through the handle.
for (auto shape : handle) {
CHECK(shape);
}
return true;
}
bool
receiveMutableHandleToShapeVector(JS::MutableHandle<TraceableVector<Shape*>> handle)
{
// Ensure range enumeration works through the handle.
for (auto shape : handle) {
CHECK(shape);
}
return true;
}
END_TEST(testGCRootedVector)