Bug 1189722 - Fix const methods in MutableTraceableVectorOperations r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 03 Aug 2015 11:47:11 +0100
changeset 287528 c742ac2240c547f045b0da2eda17ec73d811c912
parent 287527 c933c71431c46c0ad3fd62c131a48f2e18707837
child 287529 20e92855a2e77451aefd81c7ecfffdb74ea4346e
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1189722
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1189722 - Fix const methods in MutableTraceableVectorOperations r=terrence
js/public/TraceableVector.h
js/src/jsapi-tests/testGCExactRooting.cpp
--- a/js/public/TraceableVector.h
+++ b/js/public/TraceableVector.h
@@ -72,23 +72,29 @@ class TraceableVectorOperations
     bool canAppendWithoutRealloc(size_t aNeeded) const { return vec().canAppendWithoutRealloc(); }
 };
 
 template <typename Outer, typename T, size_t Capacity, typename AllocPolicy, typename TraceFunc>
 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); }
     bool reserve(size_t aRequest) { return vec().reserve(aRequest); }
     void shrinkBy(size_t aIncr) { vec().shrinkBy(aIncr); }
     bool growBy(size_t aIncr) { return vec().growBy(aIncr); }
     bool resize(size_t aNewLength) { return vec().resize(aNewLength); }
     bool growByUninitialized(size_t aIncr) { return vec().growByUninitialized(aIncr); }
--- a/js/src/jsapi-tests/testGCExactRooting.cpp
+++ b/js/src/jsapi-tests/testGCExactRooting.cpp
@@ -266,16 +266,52 @@ BEGIN_TEST(testGCRootedVector)
         CHECK(match);
     }
 
     // Ensure iterator enumeration works through the rooted.
     for (auto shape : shapes) {
         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)
 
 using ShapeVec = TraceableVector<Shape*>;
 
 static bool
 FillVector(JSContext* cx, MutableHandle<ShapeVec> shapes)