Bug 1190457 - Replace AutoPropertyDescriptorVector with normal Rooted usage; r=jonco
authorTerrence Cole <terrence@mozilla.com>
Mon, 03 Aug 2015 17:30:47 -0700
changeset 287897 30a773d3e4c158eb6bf5a7692db7e64a5d31c44a
parent 287896 685dcd115967a5a3ee505a86d16f87d6864458e4
child 287898 6cc0bc6b707daff1ca9fb66db299d2bb930baa1e
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)
reviewersjonco
bugs1190457
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 1190457 - Replace AutoPropertyDescriptorVector with normal Rooted usage; r=jonco
js/public/TraceableVector.h
js/src/gc/RootMarking.cpp
js/src/jsobj.cpp
js/src/jsobj.h
js/src/jsobjinlines.h
js/src/jspubtd.h
js/src/vm/Debugger.cpp
js/src/vm/ScopeObject.cpp
--- a/js/public/TraceableVector.h
+++ b/js/public/TraceableVector.h
@@ -63,19 +63,22 @@ class TraceableVectorOperations
 
   public:
     const AllocPolicy& allocPolicy() const { return vec().allocPolicy(); }
     size_t length() const { return vec().length(); }
     bool empty() const { return vec().empty(); }
     size_t capacity() const { return vec().capacity(); }
     const T* begin() const { return vec().begin(); }
     const T* end() const { return vec().end(); }
-    const T& operator[](size_t aIndex) const { return vec().operator[](aIndex); }
     const T& back() const { return vec().back(); }
     bool canAppendWithoutRealloc(size_t aNeeded) const { return vec().canAppendWithoutRealloc(); }
+
+    JS::Handle<T> operator[](size_t aIndex) const {
+        return JS::Handle<T>::fromMarkedLocation(&vec().operator[](aIndex));
+    }
 };
 
 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(); }
@@ -84,20 +87,23 @@ class MutableTraceableVectorOperations
   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(); }
 
+    JS::MutableHandle<T> operator[](size_t aIndex) {
+        return JS::MutableHandle<T>::fromMarkedLocation(&vec().operator[](aIndex));
+    }
+
     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); }
     void infallibleGrowByUninitialized(size_t aIncr) { vec().infallibleGrowByUninitialized(aIncr); }
     bool resizeUninitialized(size_t aNewLength) { return vec().resizeUninitialized(aNewLength); }
--- a/js/src/gc/RootMarking.cpp
+++ b/js/src/gc/RootMarking.cpp
@@ -98,24 +98,16 @@ AutoGCRooter::trace(JSTracer* trc)
         return;
 
       case IDARRAY: {
         JSIdArray* ida = static_cast<AutoIdArray*>(this)->idArray;
         TraceRange(trc, ida->length, ida->begin(), "JS::AutoIdArray.idArray");
         return;
       }
 
-      case DESCVECTOR: {
-        AutoPropertyDescriptorVector::VectorImpl& descriptors =
-            static_cast<AutoPropertyDescriptorVector*>(this)->vector;
-        for (size_t i = 0, len = descriptors.length(); i < len; i++)
-            descriptors[i].trace(trc);
-        return;
-      }
-
       case VALVECTOR: {
         AutoValueVector::VectorImpl& vector = static_cast<AutoValueVector*>(this)->vector;
         TraceRootRange(trc, vector.length(), vector.begin(), "JS::AutoValueVector.vector");
         return;
       }
 
       case IDVECTOR: {
         AutoIdVector::VectorImpl& vector = static_cast<AutoIdVector*>(this)->vector;
--- a/js/src/jsobj.cpp
+++ b/js/src/jsobj.cpp
@@ -431,41 +431,41 @@ js::CompletePropertyDescriptor(MutableHa
         desc.attributesRef() |= JSPROP_PERMANENT;
     desc.attributesRef() &= ~(JSPROP_IGNORE_PERMANENT | JSPROP_IGNORE_ENUMERATE);
 
     desc.assertComplete();
 }
 
 bool
 js::ReadPropertyDescriptors(JSContext* cx, HandleObject props, bool checkAccessors,
-                            AutoIdVector* ids, AutoPropertyDescriptorVector* descs)
+                            AutoIdVector* ids, MutableHandle<PropertyDescriptorVector> descs)
 {
     if (!GetPropertyKeys(cx, props, JSITER_OWNONLY | JSITER_SYMBOLS, ids))
         return false;
 
     RootedId id(cx);
     for (size_t i = 0, len = ids->length(); i < len; i++) {
         id = (*ids)[i];
         Rooted<PropertyDescriptor> desc(cx);
         RootedValue v(cx);
         if (!GetProperty(cx, props, props, id, &v) ||
             !ToPropertyDescriptor(cx, v, checkAccessors, &desc) ||
-            !descs->append(desc))
+            !descs.append(desc))
         {
             return false;
         }
     }
     return true;
 }
 
 bool
 js::DefineProperties(JSContext* cx, HandleObject obj, HandleObject props)
 {
     AutoIdVector ids(cx);
-    AutoPropertyDescriptorVector descs(cx);
+    Rooted<PropertyDescriptorVector> descs(cx, PropertyDescriptorVector(cx));
     if (!ReadPropertyDescriptors(cx, props, true, &ids, &descs))
         return false;
 
     for (size_t i = 0, len = ids.length(); i < len; i++) {
         if (!DefineProperty(cx, obj, ids[i], descs[i]))
             return false;
     }
 
--- a/js/src/jsobj.h
+++ b/js/src/jsobj.h
@@ -18,27 +18,28 @@
 
 #include "mozilla/MemoryReporting.h"
 
 #include "gc/Barrier.h"
 #include "gc/Marking.h"
 #include "js/Conversions.h"
 #include "js/GCAPI.h"
 #include "js/HeapAPI.h"
+#include "js/TraceableVector.h"
 #include "vm/Shape.h"
 #include "vm/String.h"
 #include "vm/Xdr.h"
 
 namespace JS {
 struct ClassInfo;
 } // namespace JS
 
 namespace js {
 
-typedef AutoVectorRooter<PropertyDescriptor> AutoPropertyDescriptorVector;
+using PropertyDescriptorVector = TraceableVector<PropertyDescriptor>;
 class GCMarker;
 class Nursery;
 
 namespace gc {
 class RelocationOverlay;
 } // namespace gc
 
 inline JSObject*
@@ -1158,17 +1159,17 @@ void
 CompletePropertyDescriptor(MutableHandle<PropertyDescriptor> desc);
 
 /*
  * Read property descriptors from props, as for Object.defineProperties. See
  * ES5 15.2.3.7 steps 3-5.
  */
 extern bool
 ReadPropertyDescriptors(JSContext* cx, HandleObject props, bool checkAccessors,
-                        AutoIdVector* ids, AutoPropertyDescriptorVector* descs);
+                        AutoIdVector* ids, MutableHandle<PropertyDescriptorVector> descs);
 
 /* Read the name using a dynamic lookup on the scopeChain. */
 extern bool
 LookupName(JSContext* cx, HandlePropertyName name, HandleObject scopeChain,
            MutableHandleObject objp, MutableHandleObject pobjp, MutableHandleShape propp);
 
 extern bool
 LookupNameNoGC(JSContext* cx, PropertyName* name, JSObject* scopeChain,
--- a/js/src/jsobjinlines.h
+++ b/js/src/jsobjinlines.h
@@ -617,18 +617,16 @@ inline bool
 IsInternalFunctionObject(JSObject& funobj)
 {
     JSFunction& fun = funobj.as<JSFunction>();
     MOZ_ASSERT_IF(fun.isLambda(),
                   fun.isInterpreted() || fun.isAsmJSNative());
     return fun.isLambda() && fun.isInterpreted() && !fun.environment();
 }
 
-typedef AutoVectorRooter<PropertyDescriptor> AutoPropertyDescriptorVector;
-
 /*
  * Make an object with the specified prototype. If parent is null, it will
  * default to the prototype's global if the prototype is non-null.
  */
 JSObject*
 NewObjectWithGivenTaggedProto(ExclusiveContext* cx, const Class* clasp, Handle<TaggedProto> proto,
                               gc::AllocKind allocKind, NewObjectKind newKind,
                               uint32_t initialShapeFlags = 0);
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -217,17 +217,16 @@ class JS_PUBLIC_API(AutoGCRooter)
      */
     ptrdiff_t tag_;
 
     enum {
         VALARRAY =     -2, /* js::AutoValueArray */
         PARSER =       -3, /* js::frontend::Parser */
         SHAPEVECTOR =  -4, /* js::AutoShapeVector */
         IDARRAY =      -6, /* js::AutoIdArray */
-        DESCVECTOR =   -7, /* js::AutoPropertyDescriptorVector */
         VALVECTOR =   -10, /* js::AutoValueVector */
         IDVECTOR =    -11, /* js::AutoIdVector */
         IDVALVECTOR = -12, /* js::AutoIdValueVector */
         OBJVECTOR =   -14, /* js::AutoObjectVector */
         STRINGVECTOR =-15, /* js::AutoStringVector */
         SCRIPTVECTOR =-16, /* js::AutoScriptVector */
         NAMEVECTOR =  -17, /* js::AutoNameVector */
         HASHABLEVALUE=-18, /* js::HashableValue */
@@ -239,17 +238,16 @@ class JS_PUBLIC_API(AutoGCRooter)
     };
 
     static ptrdiff_t GetTag(const Value& value) { return VALVECTOR; }
     static ptrdiff_t GetTag(const jsid& id) { return IDVECTOR; }
     static ptrdiff_t GetTag(JSObject* obj) { return OBJVECTOR; }
     static ptrdiff_t GetTag(JSScript* script) { return SCRIPTVECTOR; }
     static ptrdiff_t GetTag(JSString* string) { return STRINGVECTOR; }
     static ptrdiff_t GetTag(js::Shape* shape) { return SHAPEVECTOR; }
-    static ptrdiff_t GetTag(const JSPropertyDescriptor& pd) { return DESCVECTOR; }
 
   private:
     AutoGCRooter ** const stackTop;
 
     /* No copy or assignment semantics. */
     AutoGCRooter(AutoGCRooter& ida) = delete;
     void operator=(AutoGCRooter& ida) = delete;
 };
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -7166,17 +7166,17 @@ DebuggerObject_defineProperties(JSContex
         return false;
 
     RootedValue arg(cx, args[0]);
     RootedObject props(cx, ToObject(cx, arg));
     if (!props)
         return false;
 
     AutoIdVector ids(cx);
-    AutoPropertyDescriptorVector descs(cx);
+    Rooted<PropertyDescriptorVector> descs(cx, PropertyDescriptorVector(cx));
     if (!ReadPropertyDescriptors(cx, props, false, &ids, &descs))
         return false;
     size_t n = ids.length();
 
     for (size_t i = 0; i < n; i++) {
         if (!dbg->unwrapPropertyDescriptor(cx, obj, descs[i]))
             return false;
         if (!CheckPropertyDescriptorAccessors(cx, descs[i]))
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -791,17 +791,17 @@ js::XDRStaticBlockObject(XDRState<mode>*
             obj->setAliased(i, aliased);
         }
     } else {
         Rooted<ShapeVector> shapes(cx, ShapeVector(cx));
         if (!shapes.growBy(count))
             return false;
 
         for (Shape::Range<NoGC> r(obj->lastProperty()); !r.empty(); r.popFront())
-            shapes[obj->shapeToIndex(r.front())] = &r.front();
+            shapes[obj->shapeToIndex(r.front())].set(&r.front());
 
         RootedShape shape(cx);
         RootedId propid(cx);
         RootedAtom atom(cx);
         for (unsigned i = 0; i < count; i++) {
             shape = shapes[i];
             MOZ_ASSERT(shape->hasDefaultGetter());
             MOZ_ASSERT(obj->shapeToIndex(*shape) == i);
@@ -844,17 +844,17 @@ CloneStaticBlockObject(JSContext* cx, Ha
     clone->setLocalOffset(srcBlock->localOffset());
 
     /* Shape::Range is reverse order, so build a list in forward order. */
     Rooted<ShapeVector> shapes(cx, ShapeVector(cx));
     if (!shapes.growBy(srcBlock->numVariables()))
         return nullptr;
 
     for (Shape::Range<NoGC> r(srcBlock->lastProperty()); !r.empty(); r.popFront())
-        shapes[srcBlock->shapeToIndex(r.front())] = &r.front();
+        shapes[srcBlock->shapeToIndex(r.front())].set(&r.front());
 
     RootedId id(cx);
     for (Shape* shape : shapes) {
         id = shape->propid();
         unsigned i = srcBlock->shapeToIndex(*shape);
 
         bool redeclared;
         if (!StaticBlockObject::addVar(cx, clone, id, !shape->writable(), i, &redeclared)) {