Bug 1267551 (part 10) - Use MOZ_MUST_USE in AutoVectorRooterBase. r=terrence.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 01 Jun 2016 15:49:04 +1000
changeset 339114 ac3c2afcc1d78153c4ace5b41e7c238c4d54ee8d
parent 339113 d66df97e2190f0b1cf345ad2008a8b9967ceed41
child 339115 3cb234c21f033552ac9de149592498ec25643cc6
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1267551
milestone49.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 1267551 (part 10) - Use MOZ_MUST_USE in AutoVectorRooterBase. r=terrence. This patch fixes numerous unchecked calls.
dom/base/nsGlobalWindow.cpp
dom/bindings/BindingUtils.cpp
js/src/frontend/Parser.cpp
js/src/jsapi-tests/testGCMarking.cpp
js/src/jsapi-tests/testMappedArrayBuffer.cpp
js/src/jsapi.h
js/src/proxy/BaseProxyHandler.cpp
js/src/proxy/Proxy.cpp
js/src/vm/ScopeObject.cpp
js/xpconnect/wrappers/FilteringWrapper.cpp
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1088,17 +1088,19 @@ nsOuterWindowProxy::AppendIndexedPropert
                                                JS::AutoIdVector &props) const
 {
   uint32_t length = GetOuterWindow(proxy)->Length();
   MOZ_ASSERT(int32_t(length) >= 0);
   if (!props.reserve(props.length() + length)) {
     return false;
   }
   for (int32_t i = 0; i < int32_t(length); ++i) {
-    props.append(INT_TO_JSID(i));
+    if (!props.append(INT_TO_JSID(i))) {
+      return false;
+    }
   }
 
   return true;
 }
 
 bool
 nsOuterWindowProxy::watch(JSContext *cx, JS::Handle<JSObject*> proxy,
                           JS::Handle<jsid> id, JS::Handle<JSObject*> callable) const
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -3154,19 +3154,25 @@ ForEachHandler(JSContext* aCx, unsigned 
   JS::Rooted<JS::Value>
     maplikeOrSetlikeObj(aCx,
                         js::GetFunctionNativeReserved(&args.callee(),
                                                       FOREACH_MAPLIKEORSETLIKEOBJ_SLOT));
   MOZ_ASSERT(aArgc == 3);
   JS::AutoValueVector newArgs(aCx);
   // Arguments are passed in as value, key, object. Keep value and key, replace
   // object with the maplike/setlike object.
-  newArgs.append(args.get(0));
-  newArgs.append(args.get(1));
-  newArgs.append(maplikeOrSetlikeObj);
+  if (!newArgs.append(args.get(0))) {
+    return false;
+  }
+  if (!newArgs.append(args.get(1))) {
+    return false;
+  }
+  if (!newArgs.append(maplikeOrSetlikeObj)) {
+    return false;
+  }
   JS::Rooted<JS::Value> rval(aCx, JS::UndefinedValue());
   // Now actually call the user specified callback
   return JS::Call(aCx, args.thisv(), callbackFn, newArgs, &rval);
 }
 
 static inline prototypes::ID
 GetProtoIdForNewtarget(JS::Handle<JSObject*> aNewTarget)
 {
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -3003,17 +3003,18 @@ Parser<FullParseHandler>::functionArgsAn
 
         if (!addFreeVariablesFromLazyFunction(fun, pc))
             return false;
 
         PropagateTransitiveParseFlags(funbox, outerpc->sc);
         return true;
     } while (false);
 
-    blockScopes.resize(oldBlockScopesLength);
+    if (!blockScopes.resize(oldBlockScopesLength))
+        return false;
 
     // Continue doing a full parse for this inner function.
     ParseContext<FullParseHandler> funpc(this, pc, pn, funbox, newDirectives);
     if (!funpc.init(*this))
         return false;
 
     if (!functionArgsAndBodyGeneric(inHandling, yieldHandling, pn, fun, kind))
         return false;
--- a/js/src/jsapi-tests/testGCMarking.cpp
+++ b/js/src/jsapi-tests/testGCMarking.cpp
@@ -124,17 +124,18 @@ BEGIN_TEST(testIncrementalRoots)
         if (!leaf2)
             return false;
         if (!JS_DefineProperty(cx, leafOwner, "leaf2", leaf2, 0))
             return false;
     }
 
     // This is marked during markRuntime
     JS::AutoObjectVector vec(cx);
-    vec.append(root);
+    if (!vec.append(root))
+        return false;
 
     // Tenure everything so intentionally unrooted objects don't move before we
     // can use them.
     cx->minorGC(JS::gcreason::API);
 
     // Release all roots except for the AutoObjectVector.
     obj = root = nullptr;
 
--- a/js/src/jsapi-tests/testMappedArrayBuffer.cpp
+++ b/js/src/jsapi-tests/testMappedArrayBuffer.cpp
@@ -152,17 +152,19 @@ bool TestStealContents()
 bool TestTransferObject()
 {
     JS::RootedObject obj1(cx, CreateNewObject(8, 12));
     CHECK(obj1);
     JS::RootedValue v1(cx, JS::ObjectValue(*obj1));
 
     // Create an Array of transferable values.
     JS::AutoValueVector argv(cx);
-    argv.append(v1);
+    if (!argv.append(v1))
+        return false;
+
     JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::subarray(argv, 0, 1)));
     CHECK(obj);
     JS::RootedValue transferable(cx, JS::ObjectValue(*obj));
 
     JSAutoStructuredCloneBuffer cloned_buffer;
     CHECK(cloned_buffer.write(cx, v1, transferable, nullptr, nullptr));
     JS::RootedValue v2(cx);
     CHECK(cloned_buffer.read(cx, &v2, nullptr, nullptr));
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -119,54 +119,54 @@ class MOZ_RAII AutoVectorRooterBase : pr
     }
 
     typedef T ElementType;
     typedef typename VectorImpl::Range Range;
 
     size_t length() const { return vector.length(); }
     bool empty() const { return vector.empty(); }
 
-    bool append(const T& v) { return vector.append(v); }
-    bool appendN(const T& v, size_t len) { return vector.appendN(v, len); }
-    bool append(const T* ptr, size_t len) { return vector.append(ptr, len); }
-    bool appendAll(const AutoVectorRooterBase<T>& other) {
+    MOZ_MUST_USE bool append(const T& v) { return vector.append(v); }
+    MOZ_MUST_USE bool appendN(const T& v, size_t len) { return vector.appendN(v, len); }
+    MOZ_MUST_USE bool append(const T* ptr, size_t len) { return vector.append(ptr, len); }
+    MOZ_MUST_USE bool appendAll(const AutoVectorRooterBase<T>& other) {
         return vector.appendAll(other.vector);
     }
 
-    bool insert(T* p, const T& val) { return vector.insert(p, val); }
+    MOZ_MUST_USE bool insert(T* p, const T& val) { return vector.insert(p, val); }
 
     /* For use when space has already been reserved. */
     void infallibleAppend(const T& v) { vector.infallibleAppend(v); }
 
     void popBack() { vector.popBack(); }
     T popCopy() { return vector.popCopy(); }
 
-    bool growBy(size_t inc) {
+    MOZ_MUST_USE bool growBy(size_t inc) {
         size_t oldLength = vector.length();
         if (!vector.growByUninitialized(inc))
             return false;
         makeRangeGCSafe(oldLength);
         return true;
     }
 
-    bool resize(size_t newLength) {
+    MOZ_MUST_USE bool resize(size_t newLength) {
         size_t oldLength = vector.length();
         if (newLength <= oldLength) {
             vector.shrinkBy(oldLength - newLength);
             return true;
         }
         if (!vector.growByUninitialized(newLength - oldLength))
             return false;
         makeRangeGCSafe(oldLength);
         return true;
     }
 
     void clear() { vector.clear(); }
 
-    bool reserve(size_t newLength) {
+    MOZ_MUST_USE bool reserve(size_t newLength) {
         return vector.reserve(newLength);
     }
 
     JS::MutableHandle<T> operator[](size_t i) {
         return JS::MutableHandle<T>::fromMarkedLocation(&vector[i]);
     }
     JS::Handle<T> operator[](size_t i) const {
         return JS::Handle<T>::fromMarkedLocation(&vector[i]);
--- a/js/src/proxy/BaseProxyHandler.cpp
+++ b/js/src/proxy/BaseProxyHandler.cpp
@@ -272,17 +272,18 @@ BaseProxyHandler::getOwnEnumerableProper
             return false;
         desc.assertCompleteIfFound();
 
         if (desc.object() && desc.enumerable())
             props[i++].set(id);
     }
 
     MOZ_ASSERT(i <= props.length());
-    props.resize(i);
+    if (!props.resize(i))
+        return false;
 
     return true;
 }
 
 bool
 BaseProxyHandler::enumerate(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const
 {
     assertEnteredPolicy(cx, proxy, JSID_VOID, ENUMERATE);
--- a/js/src/proxy/Proxy.cpp
+++ b/js/src/proxy/Proxy.cpp
@@ -169,18 +169,20 @@ js::AppendUnique(JSContext* cx, AutoIdVe
     for (size_t i = 0; i < others.length(); ++i) {
         bool unique = true;
         for (size_t j = 0; j < base.length(); ++j) {
             if (others[i].get() == base[j]) {
                 unique = false;
                 break;
             }
         }
-        if (unique)
-            uniqueOthers.append(others[i]);
+        if (unique) {
+            if (!uniqueOthers.append(others[i]))
+                return false;
+        }
     }
     return base.appendAll(uniqueOthers);
 }
 
 /* static */ bool
 Proxy::getPrototype(JSContext* cx, HandleObject proxy, MutableHandleObject proto)
 {
     MOZ_ASSERT(proxy->hasDynamicPrototype());
--- a/js/src/vm/ScopeObject.cpp
+++ b/js/src/vm/ScopeObject.cpp
@@ -2314,17 +2314,18 @@ class DebugScopeProxy : public BaseProxy
             size_t j = 0;
             for (size_t i = 0; i < props.length(); i++) {
                 bool inScope;
                 if (!CheckUnscopables(cx, scope, props[i], &inScope))
                     return false;
                 if (inScope)
                     props[j++].set(props[i]);
             }
-            props.resize(j);
+            if (!props.resize(j))
+                return false;
         }
 
         /*
          * Function scopes are optimized to not contain unaliased variables so
          * they must be manually appended here.
          */
         if (isFunctionScope(*scope)) {
             RootedScript script(cx, scope->as<CallObject>().callee().nonLazyScript());
--- a/js/xpconnect/wrappers/FilteringWrapper.cpp
+++ b/js/xpconnect/wrappers/FilteringWrapper.cpp
@@ -24,17 +24,19 @@ Filter(JSContext* cx, HandleObject wrapp
     RootedId id(cx);
     for (size_t n = 0; n < props.length(); ++n) {
         id = props[n];
         if (Policy::check(cx, wrapper, id, Wrapper::GET) || Policy::check(cx, wrapper, id, Wrapper::SET))
             props[w++].set(id);
         else if (JS_IsExceptionPending(cx))
             return false;
     }
-    props.resize(w);
+    if (!props.resize(w))
+        return false;
+
     return true;
 }
 
 template <typename Policy>
 static bool
 FilterPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id, MutableHandle<PropertyDescriptor> desc)
 {
     MOZ_ASSERT(!JS_IsExceptionPending(cx));
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -891,17 +891,19 @@ KeyedHistogram::GetJSKeys(JSContext* cx,
   if (!keys.reserve(mHistogramMap.Count())) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   for (auto iter = mHistogramMap.Iter(); !iter.Done(); iter.Next()) {
     JS::RootedValue jsKey(cx);
     const NS_ConvertUTF8toUTF16 key(iter.Get()->GetKey());
     jsKey.setString(JS_NewUCStringCopyN(cx, key.Data(), key.Length()));
-    keys.append(jsKey);
+    if (!keys.append(jsKey)) {
+      return NS_ERROR_OUT_OF_MEMORY;
+    }
   }
 
   JS::RootedObject jsKeys(cx, JS_NewArrayObject(cx, keys));
   if (!jsKeys) {
     return NS_ERROR_FAILURE;
   }
 
   args.rval().setObject(*jsKeys);