Bug 672796 - Move MOZILLA_GUARD_OBJECT_NOTIFIER_* out of AutoRestore.h; r=khuey
authorMs2ger <ms2ger@gmail.com>
Wed, 16 Nov 2011 08:50:19 +0100
changeset 80342 1193734e020732355fedd3f4801556cd2828c82e
parent 80341 6ae59761dc37b3075d53e8af31f9b703db4ac461
child 80343 4adf065b48a6ba795e084d09e988860ff318ddfb
push id3404
push userbmo@edmorley.co.uk
push dateWed, 16 Nov 2011 18:08:22 +0000
treeherdermozilla-inbound@9b12fa716210 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs672796
milestone11.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 672796 - Move MOZILLA_GUARD_OBJECT_NOTIFIER_* out of AutoRestore.h; r=khuey
content/base/public/nsContentUtils.h
content/base/public/nsDOMFile.h
content/base/src/nsFrameLoader.cpp
js/src/Makefile.in
js/xpconnect/src/xpcprivate.h
mfbt/GuardObjects.h
toolkit/components/telemetry/Telemetry.h
xpcom/glue/AutoRestore.h
xpcom/glue/Mutex.h
xpcom/proxy/tests/Makefile.in
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -71,23 +71,25 @@ static fp_except_t oldmask = fpsetmask(~
 #include "nsIXPCScriptable.h"
 #include "nsDataHashtable.h"
 #include "nsIScriptRuntime.h"
 #include "nsIScriptGlobalObject.h"
 #include "nsIDOMEvent.h"
 #include "nsTArray.h"
 #include "nsTextFragment.h"
 #include "nsReadableUtils.h"
-#include "mozilla/AutoRestore.h"
 #include "nsINode.h"
 #include "nsHashtable.h"
 #include "nsIDOMNode.h"
 #include "nsHtml5Parser.h"
 #include "nsIFragmentContentSink.h"
 #include "nsMathUtils.h"
+
+#include "mozilla/AutoRestore.h"
+#include "mozilla/GuardObjects.h"
 #include "mozilla/TimeStamp.h"
 
 struct nsNativeKeyEvent; // Don't include nsINativeKeyBindings.h here: it will force strange compilation error!
 
 class nsIDOMScriptObjectFactory;
 class nsIXPConnect;
 class nsIContent;
 class nsIDOMKeyEvent;
--- a/content/base/public/nsDOMFile.h
+++ b/content/base/public/nsDOMFile.h
@@ -44,22 +44,23 @@
 #include "nsIDOMFile.h"
 #include "nsIDOMFileList.h"
 #include "nsIDOMFileError.h"
 #include "nsIInputStream.h"
 #include "nsIJSNativeInitializer.h"
 #include "nsIMutable.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
-#include "mozilla/AutoRestore.h"
 #include "nsString.h"
 #include "nsIXMLHttpRequest.h"
 #include "prmem.h"
 #include "nsAutoPtr.h"
 
+#include "mozilla/GuardObjects.h"
+
 #ifndef PR_UINT64_MAX
 #define PR_UINT64_MAX (~(PRUint64)(0))
 #endif
 
 class nsIFile;
 class nsIInputStream;
 class nsIClassInfo;
 class nsIBlobBuilder;
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -100,26 +100,26 @@
 #include "nsINameSpaceManager.h"
 
 #include "nsThreadUtils.h"
 #include "nsIContentViewer.h"
 #include "nsIView.h"
 
 #include "nsIDOMChromeWindow.h"
 #include "nsInProcessTabChildGlobal.h"
-#include "mozilla/AutoRestore.h"
-#include "mozilla/unused.h"
 
 #include "Layers.h"
 
 #include "ContentParent.h"
 #include "TabParent.h"
-#include "mozilla/layout/RenderFrameParent.h"
+#include "mozilla/GuardObjects.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/unused.h"
 #include "mozilla/dom/Element.h"
-#include "mozilla/Preferences.h"
+#include "mozilla/layout/RenderFrameParent.h"
 
 #include "jsapi.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 using namespace mozilla::layout;
 typedef FrameMetrics::ViewID ViewID;
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -278,16 +278,17 @@ EXPORTS_js = \
 #
 VPATH		+= \
 		$(srcdir)/../../mfbt \
 		$(NULL)
 
 EXPORTS_NAMESPACES += mozilla
 
 EXPORTS_mozilla = \
+		GuardObjects.h \
 		RangedPtr.h \
 		RefPtr.h \
 		Types.h	\
 		Util.h \
 		$(NULL)
 
 ifdef ENABLE_TRACEJIT
 VPATH		+= \
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -91,17 +91,17 @@
 #include "prlong.h"
 #include "prmem.h"
 #include "prenv.h"
 #include "prclist.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsXPIDLString.h"
 #include "nsAutoJSValHolder.h"
-#include "mozilla/AutoRestore.h"
+#include "mozilla/GuardObjects.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "mozilla/Mutex.h"
 #include "nsDataHashtable.h"
 
 #include "nsThreadUtils.h"
 #include "nsIJSContextStack.h"
 #include "nsIJSEngineTelemetryStats.h"
 #include "nsDeque.h"
new file mode 100644
--- /dev/null
+++ b/mfbt/GuardObjects.h
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set ts=8 sw=4 et tw=99 ft=cpp: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
+ *   Ms2ger <ms2ger@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef mozilla_GuardObjects_h
+#define mozilla_GuardObjects_h
+
+#include "mozilla/Types.h"
+#include "mozilla/Util.h"
+
+namespace mozilla {
+  /**
+   * The following classes are designed to cause assertions to detect
+   * inadvertent use of guard objects as temporaries.  In other words,
+   * when we have a guard object whose only purpose is its constructor and
+   * destructor (and is never otherwise referenced), the intended use
+   * might be:
+   *     AutoRestore savePainting(mIsPainting);
+   * but is is easy to accidentally write:
+   *     AutoRestore(mIsPainting);
+   * which compiles just fine, but runs the destructor well before the
+   * intended time.
+   *
+   * They work by adding (#ifdef DEBUG) an additional parameter to the
+   * guard object's constructor, with a default value, so that users of
+   * the guard object's API do not need to do anything.  The default value
+   * of this parameter is a temporary object.  C++ (ISO/IEC 14882:1998),
+   * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a
+   * guarantee that temporaries are destroyed in the reverse of their
+   * construction order, but I actually can't find a statement that that
+   * is true in the general case (beyond the two specific cases mentioned
+   * there).  However, it seems to be true.
+   *
+   * These classes are intended to be used only via the macros immediately
+   * below them:
+   *   MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member
+   *     variable, and should be put where a declaration of a private
+   *     member variable would be placed.
+   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the
+   *     parameters to each constructor of the guard object; it declares
+   *     (ifdef DEBUG) an additional parameter.  (But use the *_ONLY_PARAM
+   *     variant for constructors that take no other parameters.)
+   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in
+   *     the implementation of such constructors when they are not inline.
+   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in
+   *     the implementation of such constructors to pass the parameter to
+   *     a base class that also uses these macros
+   *   MOZILLA_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each
+   *     constructor.  It uses the parameter declared by
+   *     MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM.
+   *
+   * For more details, and examples of using these macros, see
+   * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
+   */
+#ifdef DEBUG
+  class GuardObjectNotifier
+  {
+  private:
+    bool* mStatementDone;
+  public:
+    GuardObjectNotifier() : mStatementDone(NULL) {}
+
+    ~GuardObjectNotifier() {
+      *mStatementDone = true;
+    }
+
+    void SetStatementDone(bool *aStatementDone) {
+      mStatementDone = aStatementDone;
+    }
+  };
+
+  class GuardObjectNotificationReceiver
+  {
+  private:
+    bool mStatementDone;
+  public:
+    GuardObjectNotificationReceiver() : mStatementDone(false) {}
+
+    ~GuardObjectNotificationReceiver() {
+      /*
+       * Assert that the guard object was not used as a temporary.
+       * (Note that this assert might also fire if Init is not called
+       * because the guard object's implementation is not using the
+       * above macros correctly.)
+       */
+      MOZ_ASSERT(mStatementDone);
+    }
+
+    void Init(const GuardObjectNotifier &aNotifier) {
+      /*
+       * aNotifier is passed as a const reference so that we can pass a
+       * temporary, but we really intend it as non-const
+       */
+      const_cast<GuardObjectNotifier&>(aNotifier).
+          SetStatementDone(&mStatementDone);
+    }
+  };
+
+  #define MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER \
+      mozilla::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary;
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM \
+      , const mozilla::GuardObjectNotifier& _notifier = \
+                mozilla::GuardObjectNotifier()
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \
+      const mozilla::GuardObjectNotifier& _notifier = \
+              mozilla::GuardObjectNotifier()
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \
+      , const mozilla::GuardObjectNotifier& _notifier
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \
+      , _notifier
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_INIT \
+      PR_BEGIN_MACRO _mCheckNotUsedAsTemporary.Init(_notifier); PR_END_MACRO
+
+#else /* defined(DEBUG) */
+
+  #define MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT
+  #define MOZILLA_GUARD_OBJECT_NOTIFIER_INIT PR_BEGIN_MACRO PR_END_MACRO
+
+#endif /* !defined(DEBUG) */
+
+} // namespace mozilla
+
+#endif /* mozilla_GuardObjects_h */
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -34,18 +34,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef Telemetry_h__
 #define Telemetry_h__
 
+#include "mozilla/GuardObjects.h"
 #include "mozilla/TimeStamp.h"
-#include "mozilla/AutoRestore.h"
 
 namespace base {
   class Histogram;
 }
 
 namespace mozilla {
 namespace Telemetry {
 
--- a/xpcom/glue/AutoRestore.h
+++ b/xpcom/glue/AutoRestore.h
@@ -35,137 +35,21 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 /* functions for restoring saved values at the end of a C++ scope */
 
 #ifndef mozilla_AutoRestore_h_
 #define mozilla_AutoRestore_h_
 
-#include "prtypes.h"
-#include "nsDebug.h"
+#include "mozilla/GuardObjects.h"
 
 namespace mozilla {
 
   /**
-   * The following classes are designed to cause assertions to detect
-   * inadvertent use of guard objects as temporaries.  In other words,
-   * when we have a guard object whose only purpose is its constructor and
-   * destructor (and is never otherwise referenced), the intended use
-   * might be:
-   *     AutoRestore savePainting(mIsPainting);
-   * but is is easy to accidentally write:
-   *     AutoRestore(mIsPainting);
-   * which compiles just fine, but runs the destructor well before the
-   * intended time.
-   *
-   * They work by adding (#ifdef DEBUG) an additional parameter to the
-   * guard object's constructor, with a default value, so that users of
-   * the guard object's API do not need to do anything.  The default value
-   * of this parameter is a temporary object.  C++ (ISO/IEC 14882:1998),
-   * section 12.2 [class.temporary], clauses 4 and 5 seem to assume a
-   * guarantee that temporaries are destroyed in the reverse of their
-   * construction order, but I actually can't find a statement that that
-   * is true in the general case (beyond the two specific cases mentioned
-   * there).  However, it seems to be true.
-   *
-   * These classes are intended to be used only via the macros immediately
-   * below them:
-   *   MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member
-   *     variable, and should be put where a declaration of a private
-   *     member variable would be placed.
-   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the
-   *     parameters to each constructor of the guard object; it declares
-   *     (ifdef DEBUG) an additional parameter.  (But use the *_ONLY_PARAM
-   *     variant for constructors that take no other parameters.)
-   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in
-   *     the implementation of such constructors when they are not inline.
-   *   MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in
-   *     the implementation of such constructors to pass the parameter to
-   *     a base class that also uses these macros
-   *   MOZILLA_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each
-   *     constructor.  It uses the parameter declared by
-   *     MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM.
-   *
-   * For more details, and examples of using these macros, see
-   * https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla
-   */
-#ifdef DEBUG
-  class GuardObjectNotifier
-  {
-  private:
-    bool* mStatementDone;
-  public:
-    GuardObjectNotifier() : mStatementDone(NULL) {}
-
-    ~GuardObjectNotifier() {
-      *mStatementDone = true;
-    }
-
-    void SetStatementDone(bool *aStatementDone) {
-      mStatementDone = aStatementDone;
-    }
-  };
-
-  class GuardObjectNotificationReceiver
-  {
-  private:
-    bool mStatementDone;
-  public:
-    GuardObjectNotificationReceiver() : mStatementDone(false) {}
-
-    ~GuardObjectNotificationReceiver() {
-      /*
-       * Assert that the guard object was not used as a temporary.
-       * (Note that this assert might also fire if Init is not called
-       * because the guard object's implementation is not using the
-       * above macros correctly.)
-       */
-      NS_ABORT_IF_FALSE(mStatementDone,
-                        "guard object used as temporary");
-    }
-
-    void Init(const GuardObjectNotifier &aNotifier) {
-      /*
-       * aNotifier is passed as a const reference so that we can pass a
-       * temporary, but we really intend it as non-const
-       */
-      const_cast<GuardObjectNotifier&>(aNotifier).
-          SetStatementDone(&mStatementDone);
-    }
-  };
-
-  #define MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER \
-      mozilla::GuardObjectNotificationReceiver _mCheckNotUsedAsTemporary;
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM \
-      , const mozilla::GuardObjectNotifier& _notifier = \
-                mozilla::GuardObjectNotifier()
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM \
-      const mozilla::GuardObjectNotifier& _notifier = \
-              mozilla::GuardObjectNotifier()
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL \
-      , const mozilla::GuardObjectNotifier& _notifier
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT \
-      , _notifier
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_INIT \
-      PR_BEGIN_MACRO _mCheckNotUsedAsTemporary.Init(_notifier); PR_END_MACRO
-
-#else /* defined(DEBUG) */
-
-  #define MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_ONLY_PARAM
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT
-  #define MOZILLA_GUARD_OBJECT_NOTIFIER_INIT PR_BEGIN_MACRO PR_END_MACRO
-
-#endif /* !defined(DEBUG) */
-
-
-  /**
    * Save the current value of a variable and restore it when the object
    * goes out of scope.  For example:
    *   {
    *     AutoRestore<bool> savePainting(mIsPainting);
    *     mIsPainting = true;
    *     
    *     // ... your code here ...
    *
@@ -183,11 +67,11 @@ namespace mozilla {
     AutoRestore(T& aValue MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM)
       : mLocation(aValue), mValue(aValue)
     {
       MOZILLA_GUARD_OBJECT_NOTIFIER_INIT;
     }
     ~AutoRestore() { mLocation = mValue; }
   };
 
-}
+} // namespace mozilla
 
 #endif /* !defined(mozilla_AutoRestore_h_) */
--- a/xpcom/glue/Mutex.h
+++ b/xpcom/glue/Mutex.h
@@ -36,18 +36,18 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_Mutex_h
 #define mozilla_Mutex_h
 
 #include "prlock.h"
 
-#include "mozilla/AutoRestore.h"
 #include "mozilla/BlockingResourceBase.h"
+#include "mozilla/GuardObjects.h"
 
 //
 // Provides:
 //
 //  - Mutex, a non-recursive mutex
 //  - MutexAutoLock, an RAII class for ensuring that Mutexes are properly 
 //    locked and unlocked
 //  - MutexAutoUnlock, complementary sibling to MutexAutoLock
--- a/xpcom/proxy/tests/Makefile.in
+++ b/xpcom/proxy/tests/Makefile.in
@@ -51,11 +51,12 @@ CPPSRCS		= proxytests.cpp \
 XPIDLSRCS	= nsITestProxy.idl
 
 SIMPLE_PROGRAMS	= $(CPPSRCS:.cpp=$(BIN_SUFFIX)) 
 
 LIBS		= \
 		$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
 		$(XPCOM_LIBS) \
 		$(NSPR_LIBS) \
+		$(MOZ_JS_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk