Bug 1267551 (part 1) - Use MOZ_MUST_USE more in jsnum.h. r=jonco.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 27 Apr 2016 17:09:21 +1000
changeset 323619 e791431d1864b4609b43533fe7d4351e192a9e46
parent 323618 146b55a0222202b6eb98f0ead305776d8ae0fc2b
child 323620 4145291190269551381c2d07e06d7c92b85ccb45
push idunknown
push userunknown
push dateunknown
reviewersjonco
bugs1267551
milestone49.0a1
Bug 1267551 (part 1) - Use MOZ_MUST_USE more in jsnum.h. r=jonco.
js/src/jsnum.h
js/src/jsopcode.cpp
--- a/js/src/jsnum.h
+++ b/js/src/jsnum.h
@@ -29,17 +29,17 @@
 #ifndef BUILTIN_CHECKED_ARITHMETIC_SUPPORTED
     #define BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(x) 0
 #endif
 
 namespace js {
 
 class StringBuffer;
 
-extern bool
+extern MOZ_MUST_USE bool
 InitRuntimeNumberState(JSRuntime* rt);
 
 #if !EXPOSE_INTL_API
 extern void
 FinishRuntimeNumberState(JSRuntime* rt);
 #endif
 
 /* Initialize the Number class, returning its prototype object. */
@@ -78,17 +78,17 @@ Int32ToString(ExclusiveContext* cx, int3
 
 extern JSAtom*
 Int32ToAtom(ExclusiveContext* cx, int32_t si);
 
 /*
  * Convert an integer or double (contained in the given value) to a string and
  * append to the given buffer.
  */
-extern bool JS_FASTCALL
+extern MOZ_MUST_USE bool JS_FASTCALL
 NumberValueToStringBuffer(JSContext* cx, const Value& v, StringBuffer& sb);
 
 /* Same as js_NumberToString, different signature. */
 extern JSFlatString*
 NumberToString(JSContext* cx, double d);
 
 extern JSFlatString*
 IndexToString(JSContext* cx, uint32_t index);
@@ -146,47 +146,47 @@ ParseDecimalNumber(const mozilla::Range<
  * digits of the integer in *endp, and return the integer itself in *dp.  If
  * base is 10 or a power of two the returned integer is the closest possible
  * double; otherwise extremely large integers may be slightly inaccurate.
  *
  * If [start, end) does not begin with a number with the specified base,
  * *dp == 0 and *endp == start upon return.
  */
 template <typename CharT>
-extern bool
+extern MOZ_MUST_USE bool
 GetPrefixInteger(ExclusiveContext* cx, const CharT* start, const CharT* end, int base,
                  const CharT** endp, double* dp);
 
 /*
  * This is like GetPrefixInteger, but only deals with base 10, and doesn't have
  * and |endp| outparam.  It should only be used when the characters are known to
  * only contain digits.
  */
-extern bool
+extern MOZ_MUST_USE bool
 GetDecimalInteger(ExclusiveContext* cx, const char16_t* start, const char16_t* end, double* dp);
 
-extern bool
+extern MOZ_MUST_USE bool
 StringToNumber(ExclusiveContext* cx, JSString* str, double* result);
 
 /* ES5 9.3 ToNumber, overwriting *vp with the appropriate number value. */
-MOZ_ALWAYS_INLINE bool
+MOZ_ALWAYS_INLINE MOZ_MUST_USE bool
 ToNumber(JSContext* cx, JS::MutableHandleValue vp)
 {
     if (vp.isNumber())
         return true;
     double d;
     extern JS_PUBLIC_API(bool) ToNumberSlow(JSContext* cx, Value v, double* dp);
     if (!ToNumberSlow(cx, vp, &d))
         return false;
 
     vp.setNumber(d);
     return true;
 }
 
-bool
+MOZ_MUST_USE bool
 num_parseInt(JSContext* cx, unsigned argc, Value* vp);
 
 }  /* namespace js */
 
 /*
  * Similar to strtod except that it replaces overflows with infinities of the
  * correct sign, and underflows with zeros of the correct sign.  Guaranteed to
  * return the closest double number to the given input in dp.
@@ -194,26 +194,26 @@ num_parseInt(JSContext* cx, unsigned arg
  * Also allows inputs of the form [+|-]Infinity, which produce an infinity of
  * the appropriate sign.  The case of the "Infinity" string must match exactly.
  * If the string does not contain a number, set *dEnd to begin and return 0.0
  * in *d.
  *
  * Return false if out of memory.
  */
 template <typename CharT>
-extern bool
+extern MOZ_MUST_USE bool
 js_strtod(js::ExclusiveContext* cx, const CharT* begin, const CharT* end,
           const CharT** dEnd, double* d);
 
 namespace js {
 
-extern bool
+extern MOZ_MUST_USE bool
 num_toString(JSContext* cx, unsigned argc, Value* vp);
 
-extern bool
+extern MOZ_MUST_USE bool
 num_valueOf(JSContext* cx, unsigned argc, Value* vp);
 
 static MOZ_ALWAYS_INLINE bool
 ValueFitsInInt32(const Value& v, int32_t* pi)
 {
     if (v.isInt32()) {
         *pi = v.toInt32();
         return true;
@@ -243,17 +243,17 @@ IsDefinitelyIndex(const Value& v, uint32
         *indexp = uint32_t(i);
         return true;
     }
 
     return false;
 }
 
 /* ES5 9.4 ToInteger. */
-static inline bool
+static MOZ_MUST_USE inline bool
 ToInteger(JSContext* cx, HandleValue v, double* dp)
 {
     if (v.isInt32()) {
         *dp = v.toInt32();
         return true;
     }
     if (v.isDouble()) {
         *dp = v.toDouble();
@@ -268,17 +268,17 @@ ToInteger(JSContext* cx, HandleValue v, 
 
 /* ES6 7.1.15 ToLength, but clamped to the [0,2^32-2] range.  If the
  * return value is false then *overflow will be true iff the value was
  * not clampable to uint32_t range.
  *
  * For JSContext and ExclusiveContext.
  */
 template<typename T>
-bool ToLengthClamped(T* cx, HandleValue v, uint32_t* out, bool* overflow);
+MOZ_MUST_USE bool ToLengthClamped(T* cx, HandleValue v, uint32_t* out, bool* overflow);
 
 /* Convert and range check an index value as for DataView, SIMD, and Atomics
  * operations, eg ES7 24.2.1.1, DataView's GetViewValue():
  *
  *   1. numericIndex = ToNumber(argument)            (may throw TypeError)
  *   2. intIndex = ToInteger(numericIndex)
  *   3. if intIndex != numericIndex throw RangeError
  *
@@ -288,63 +288,63 @@ bool ToLengthClamped(T* cx, HandleValue 
  *   4. if intIndex < 0 or intIndex > 2^53 throw RangeError
  *
  * Return true and set |*index| to the integer value if |argument| is a valid
  * array index argument. Otherwise report an TypeError or RangeError and return
  * false.
  *
  * The returned index will always be in the range 0 <= *index <= 2^53.
  */
-bool ToIntegerIndex(JSContext* cx, JS::HandleValue v, uint64_t* index);
+MOZ_MUST_USE bool ToIntegerIndex(JSContext* cx, JS::HandleValue v, uint64_t* index);
 
-inline bool
+MOZ_MUST_USE inline bool
 SafeAdd(int32_t one, int32_t two, int32_t* res)
 {
 #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_sadd_overflow)
     // Using compiler's builtin function.
     return !__builtin_sadd_overflow(one, two, res);
 #else
     // Use unsigned for the 32-bit operation since signed overflow gets
     // undefined behavior.
     *res = uint32_t(one) + uint32_t(two);
     int64_t ores = (int64_t)one + (int64_t)two;
     return ores == (int64_t)*res;
 #endif
 }
 
-inline bool
+MOZ_MUST_USE inline bool
 SafeSub(int32_t one, int32_t two, int32_t* res)
 {
 #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_ssub_overflow)
     return !__builtin_ssub_overflow(one, two, res);
 #else
     *res = uint32_t(one) - uint32_t(two);
     int64_t ores = (int64_t)one - (int64_t)two;
     return ores == (int64_t)*res;
 #endif
 }
 
-inline bool
+MOZ_MUST_USE inline bool
 SafeMul(int32_t one, int32_t two, int32_t* res)
 {
 #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_smul_overflow)
     return !__builtin_smul_overflow(one, two, res);
 #else
     *res = uint32_t(one) * uint32_t(two);
     int64_t ores = (int64_t)one * (int64_t)two;
     return ores == (int64_t)*res;
 #endif
 }
 
-extern bool
+extern MOZ_MUST_USE bool
 ToNumberSlow(ExclusiveContext* cx, Value v, double* dp);
 
 // Variant of ToNumber which takes an ExclusiveContext instead of a JSContext.
 // ToNumber is part of the API and can't use ExclusiveContext directly.
-MOZ_ALWAYS_INLINE bool
+MOZ_ALWAYS_INLINE MOZ_MUST_USE bool
 ToNumber(ExclusiveContext* cx, const Value& v, double* out)
 {
     if (v.isNumber()) {
         *out = v.toNumber();
         return true;
     }
     return ToNumberSlow(cx, v, out);
 }
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -1711,17 +1711,19 @@ js::GetPCCountScriptSummary(JSContext* c
     JSString* str = JS_NewStringCopyZ(cx, script->filename());
     if (!str || !(str = StringToSource(cx, str)))
         return nullptr;
     if (!buf.append(str))
         return nullptr;
 
     if (!AppendJSONProperty(buf, "line"))
         return nullptr;
-    NumberValueToStringBuffer(cx, Int32Value(script->lineno()), buf);
+    if (!NumberValueToStringBuffer(cx, Int32Value(script->lineno()), buf)) {
+        return nullptr;
+    }
 
     if (script->functionNonDelazifying()) {
         JSAtom* atom = script->functionNonDelazifying()->displayAtom();
         if (atom) {
             if (!AppendJSONProperty(buf, "name"))
                 return nullptr;
             if (!(str = StringToSource(cx, atom)))
                 return nullptr;