Bug 1285649 - Replace an ellipsis function, whose last non-ellipsis argument was subject to integer promotions, with a variadic template function so as not to invoke C++ undefined behavior, because that would be Bad. NOT REVIEWED YET
☠☠ backed out by 1684231d408c ☠ ☠
authorJeff Walden <jwalden@mit.edu>
Wed, 20 Jul 2016 15:06:48 -0700
changeset 346812 1a2627378a0dace519c6e8d6c465f76bc4d8d599
parent 346758 41297feb5186ba68b1899f9776d513b219dce8b4
child 346813 d9d62360b963bd672bb052586e3e1fcd8cb39864
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1285649
milestone50.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 1285649 - Replace an ellipsis function, whose last non-ellipsis argument was subject to integer promotions, with a variadic template function so as not to invoke C++ undefined behavior, because that would be Bad. NOT REVIEWED YET
dom/bindings/BindingUtils.cpp
dom/bindings/ErrorResult.h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -81,25 +81,23 @@ GetErrorMessage(void* aUserRef, const un
 }
 
 uint16_t
 GetErrorArgCount(const ErrNum aErrorNumber)
 {
   return GetErrorMessage(nullptr, aErrorNumber)->argCount;
 }
 
-bool
-ThrowErrorMessage(JSContext* aCx, const ErrNum aErrorNumber, ...)
+void
+binding_detail::ThrowErrorMessage(JSContext* aCx, const unsigned aErrorNumber, ...)
 {
   va_list ap;
   va_start(ap, aErrorNumber);
-  JS_ReportErrorNumberVA(aCx, GetErrorMessage, nullptr,
-                         static_cast<const unsigned>(aErrorNumber), ap);
+  JS_ReportErrorNumberVA(aCx, GetErrorMessage, nullptr, aErrorNumber, ap);
   va_end(ap);
-  return false;
 }
 
 bool
 ThrowInvalidThis(JSContext* aCx, const JS::CallArgs& aArgs,
                  bool aSecurityError, const char* aInterfaceName)
 {
   NS_ConvertASCIItoUTF16 ifaceName(aInterfaceName);
   // This should only be called for DOM methods/getters/setters, which
--- a/dom/bindings/ErrorResult.h
+++ b/dom/bindings/ErrorResult.h
@@ -62,18 +62,28 @@ uint16_t constexpr ErrorFormatNumArgs[] 
 #include "mozilla/dom/Errors.msg"
 #undef MSG_DEF
 };
 #endif
 
 uint16_t
 GetErrorArgCount(const ErrNum aErrorNumber);
 
-bool
-ThrowErrorMessage(JSContext* aCx, const ErrNum aErrorNumber, ...);
+namespace binding_detail {
+void ThrowErrorMessage(JSContext* aCx, const unsigned aErrorNumber, ...);
+} // namespace binding_detail
+
+template<typename... Ts>
+inline bool
+ThrowErrorMessage(JSContext* aCx, const ErrNum aErrorNumber, Ts&&... aArgs)
+{
+  binding_detail::ThrowErrorMessage(aCx, static_cast<const unsigned>(aErrorNumber),
+                                    mozilla::Forward<Ts>(aArgs)...);
+  return false;
+}
 
 struct StringArrayAppender
 {
   static void Append(nsTArray<nsString>& aArgs, uint16_t aCount)
   {
     MOZ_RELEASE_ASSERT(aCount == 0, "Must give at least as many string arguments as are required by the ErrNum.");
   }