xpcom/glue/HoldDropJSObjects.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/HoldDropJSObjects.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,71 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_HoldDropJSObjects_h
    1.11 +#define mozilla_HoldDropJSObjects_h
    1.12 +
    1.13 +#include "mozilla/TypeTraits.h"
    1.14 +#include "nsCycleCollectionParticipant.h"
    1.15 +
    1.16 +class nsISupports;
    1.17 +class nsScriptObjectTracer;
    1.18 +
    1.19 +// Only HoldJSObjects and DropJSObjects should be called directly.
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace cyclecollector {
    1.23 +
    1.24 +// These methods are defined in nsCycleCollector.cpp
    1.25 +void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer);
    1.26 +void HoldJSObjectsImpl(nsISupports* aHolder);
    1.27 +void DropJSObjectsImpl(void* aHolder);
    1.28 +void DropJSObjectsImpl(nsISupports* aHolder);
    1.29 +
    1.30 +} // namespace cyclecollector
    1.31 +
    1.32 +
    1.33 +template<class T, bool isISupports=IsBaseOf<nsISupports, T>::value>
    1.34 +struct HoldDropJSObjectsHelper
    1.35 +{
    1.36 +  static void Hold(T* aHolder)
    1.37 +  {
    1.38 +    cyclecollector::HoldJSObjectsImpl(aHolder, NS_CYCLE_COLLECTION_PARTICIPANT(T));
    1.39 +  }
    1.40 +  static void Drop(T* aHolder)
    1.41 +  {
    1.42 +    cyclecollector::DropJSObjectsImpl(aHolder);
    1.43 +  }
    1.44 +};
    1.45 +
    1.46 +template<class T>
    1.47 +struct HoldDropJSObjectsHelper<T, true>
    1.48 +{
    1.49 +  static void Hold(T* aHolder)
    1.50 +  {
    1.51 +    cyclecollector::HoldJSObjectsImpl(ToSupports(aHolder));
    1.52 +  }
    1.53 +  static void Drop(T* aHolder)
    1.54 +  {
    1.55 +    cyclecollector::DropJSObjectsImpl(ToSupports(aHolder));
    1.56 +  }
    1.57 +};
    1.58 +
    1.59 +
    1.60 +template<class T>
    1.61 +void HoldJSObjects(T* aHolder)
    1.62 +{
    1.63 +  HoldDropJSObjectsHelper<T>::Hold(aHolder);
    1.64 +}
    1.65 +
    1.66 +template<class T>
    1.67 +void DropJSObjects(T* aHolder)
    1.68 +{
    1.69 +  HoldDropJSObjectsHelper<T>::Drop(aHolder);
    1.70 +}
    1.71 +
    1.72 +} // namespace mozilla
    1.73 +
    1.74 +#endif // mozilla_HoldDropJSObjects_h

mercurial