Merge m-i and f-t to m-c, a=merge
authorPhil Ringnalda <philringnalda@gmail.com>
Sun, 11 Sep 2016 19:30:43 -0700
changeset 313479 cfdb7af3af2e92e95f71ca2f1672bf5433beeb89
parent 313475 8d2a514d0f23060d95b4f705c98ed37baff46422 (current diff)
parent 313478 fa475defd61cd9590a5dfe60ed66c1af06affe0f (diff)
child 313480 3c226fecfb2c1ec6dcc8cb21cb54139660b66be4
child 313482 76b2bc20a727979f7f7c39f81c6f213fff00666d
push id30686
push userphilringnalda@gmail.com
push dateMon, 12 Sep 2016 02:31:08 +0000
treeherdermozilla-central@cfdb7af3af2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone51.0a1
first release with
nightly linux32
cfdb7af3af2e / 51.0a1 / 20160912030421 / files
nightly linux64
cfdb7af3af2e / 51.0a1 / 20160912030421 / files
nightly mac
cfdb7af3af2e / 51.0a1 / 20160912030421 / files
nightly win32
cfdb7af3af2e / 51.0a1 / 20160912030421 / files
nightly win64
cfdb7af3af2e / 51.0a1 / 20160912030421 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge m-i and f-t to m-c, a=merge
--- a/dom/filesystem/GetFilesHelper.cpp
+++ b/dom/filesystem/GetFilesHelper.cpp
@@ -6,16 +6,63 @@
 
 #include "GetFilesHelper.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 
 namespace mozilla {
 namespace dom {
 
+namespace {
+
+// This class is used in the DTOR of GetFilesHelper to release resources in the
+// correct thread.
+class ReleaseRunnable final : public Runnable
+{
+public:
+  static void
+  MaybeReleaseOnMainThread(nsTArray<RefPtr<Promise>>& aPromises,
+                           nsTArray<RefPtr<GetFilesCallback>>& aCallbacks)
+  {
+    if (NS_IsMainThread()) {
+      return;
+    }
+
+    if (!aPromises.IsEmpty() || !aCallbacks.IsEmpty()) {
+      RefPtr<ReleaseRunnable> runnable =
+        new ReleaseRunnable(aPromises, aCallbacks);
+      NS_DispatchToMainThread(runnable);
+    }
+  }
+
+  NS_IMETHOD
+  Run() override
+  {
+    MOZ_ASSERT(NS_IsMainThread());
+
+    mPromises.Clear();
+    mCallbacks.Clear();
+
+    return NS_OK;
+  }
+
+private:
+  ReleaseRunnable(nsTArray<RefPtr<Promise>>& aPromises,
+                  nsTArray<RefPtr<GetFilesCallback>>& aCallbacks)
+  {
+    mPromises.SwapElements(aPromises);
+    mCallbacks.SwapElements(aCallbacks);
+  }
+
+  nsTArray<RefPtr<Promise>> mPromises;
+  nsTArray<RefPtr<GetFilesCallback>> mCallbacks;
+};
+
+} // anonymous
+
 ///////////////////////////////////////////////////////////////////////////////
 // GetFilesHelper Base class
 
 already_AddRefed<GetFilesHelper>
 GetFilesHelper::Create(nsIGlobalObject* aGlobal,
                        const nsTArray<OwningFileOrDirectory>& aFilesOrDirectory,
                        bool aRecursiveFlag, ErrorResult& aRv)
 {
@@ -76,16 +123,21 @@ GetFilesHelper::GetFilesHelper(nsIGlobal
   , mGlobal(aGlobal)
   , mListingCompleted(false)
   , mErrorResult(NS_OK)
   , mMutex("GetFilesHelper::mMutex")
   , mCanceled(false)
 {
 }
 
+GetFilesHelper::~GetFilesHelper()
+{
+  ReleaseRunnable::MaybeReleaseOnMainThread(mPromises, mCallbacks);
+}
+
 void
 GetFilesHelper::AddPromise(Promise* aPromise)
 {
   MOZ_ASSERT(aPromise);
 
   // Still working.
   if (!mListingCompleted) {
     mPromises.AppendElement(aPromise);
--- a/dom/filesystem/GetFilesHelper.h
+++ b/dom/filesystem/GetFilesHelper.h
@@ -94,17 +94,17 @@ public:
 
   // CC methods
   void Unlink();
   void Traverse(nsCycleCollectionTraversalCallback &cb);
 
 protected:
   GetFilesHelper(nsIGlobalObject* aGlobal, bool aRecursiveFlag);
 
-  virtual ~GetFilesHelper() {}
+  virtual ~GetFilesHelper();
 
   void
   SetDirectoryPath(const nsAString& aDirectoryPath)
   {
     mDirectoryPath = aDirectoryPath;
   }
 
   virtual bool
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -5,26 +5,37 @@
 
 /* constants used in the style struct data provided by nsStyleContext */
 
 #ifndef nsStyleConsts_h___
 #define nsStyleConsts_h___
 
 #include "gfxRect.h"
 #include "nsFont.h"
+#include "mozilla/MacroArgs.h" // for MOZ_CONCAT
 #include "X11UndefineNone.h"
 
 // XXX fold this into nsStyleContext and group by nsStyleXXX struct
 
 namespace mozilla {
 namespace css {
 typedef mozilla::Side Side;
 } // namespace css
 
-#define NS_FOR_CSS_SIDES(var_) for (mozilla::css::Side var_ = NS_SIDE_TOP; var_ <= NS_SIDE_LEFT; var_++)
+// Creates a for loop that walks over the four mozilla::css::Side values.
+// We use an int32_t helper variable (instead of a Side) for our loop counter,
+// to avoid triggering undefined behavior just before we exit the loop (at
+// which point the counter is incremented beyond the largest valid Side value).
+#define NS_FOR_CSS_SIDES(var_)                                           \
+  int32_t MOZ_CONCAT(var_,__LINE__) = NS_SIDE_TOP;                       \
+  for (mozilla::css::Side var_;                                          \
+       MOZ_CONCAT(var_,__LINE__) <= NS_SIDE_LEFT &&                      \
+         ((var_ = mozilla::css::Side(MOZ_CONCAT(var_,__LINE__))), true); \
+       MOZ_CONCAT(var_,__LINE__)++)
+
 static inline css::Side operator++(css::Side& side, int) {
     NS_PRECONDITION(side >= NS_SIDE_TOP &&
                     side <= NS_SIDE_LEFT, "Out of range side");
     side = css::Side(side + 1);
     return side;
 }
 
 #define NS_FOR_CSS_FULL_CORNERS(var_) for (int32_t var_ = 0; var_ < 4; ++var_)
--- a/mfbt/MacroArgs.h
+++ b/mfbt/MacroArgs.h
@@ -6,16 +6,20 @@
 
 /*
  * Implements various macros meant to ease the use of variadic macros.
  */
 
 #ifndef mozilla_MacroArgs_h
 #define mozilla_MacroArgs_h
 
+// Concatenates pre-processor tokens in a way that can be used with __LINE__.
+#define MOZ_CONCAT2(x, y) x ## y
+#define MOZ_CONCAT(x, y) MOZ_CONCAT2(x, y)
+
 /*
  * MOZ_PASTE_PREFIX_AND_ARG_COUNT(aPrefix, ...) counts the number of variadic
  * arguments and prefixes it with |aPrefix|. For example:
  *
  *   MOZ_PASTE_PREFIX_AND_ARG_COUNT(, foo, 42) expands to 2
  *   MOZ_PASTE_PREFIX_AND_ARG_COUNT(A, foo, 42, bar) expands to A3
  *
  * You must pass in between 1 and 50 (inclusive) variadic arguments, past