xpcom/glue/HoldDropJSObjects.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef mozilla_HoldDropJSObjects_h
     8 #define mozilla_HoldDropJSObjects_h
    10 #include "mozilla/TypeTraits.h"
    11 #include "nsCycleCollectionParticipant.h"
    13 class nsISupports;
    14 class nsScriptObjectTracer;
    16 // Only HoldJSObjects and DropJSObjects should be called directly.
    18 namespace mozilla {
    19 namespace cyclecollector {
    21 // These methods are defined in nsCycleCollector.cpp
    22 void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer);
    23 void HoldJSObjectsImpl(nsISupports* aHolder);
    24 void DropJSObjectsImpl(void* aHolder);
    25 void DropJSObjectsImpl(nsISupports* aHolder);
    27 } // namespace cyclecollector
    30 template<class T, bool isISupports=IsBaseOf<nsISupports, T>::value>
    31 struct HoldDropJSObjectsHelper
    32 {
    33   static void Hold(T* aHolder)
    34   {
    35     cyclecollector::HoldJSObjectsImpl(aHolder, NS_CYCLE_COLLECTION_PARTICIPANT(T));
    36   }
    37   static void Drop(T* aHolder)
    38   {
    39     cyclecollector::DropJSObjectsImpl(aHolder);
    40   }
    41 };
    43 template<class T>
    44 struct HoldDropJSObjectsHelper<T, true>
    45 {
    46   static void Hold(T* aHolder)
    47   {
    48     cyclecollector::HoldJSObjectsImpl(ToSupports(aHolder));
    49   }
    50   static void Drop(T* aHolder)
    51   {
    52     cyclecollector::DropJSObjectsImpl(ToSupports(aHolder));
    53   }
    54 };
    57 template<class T>
    58 void HoldJSObjects(T* aHolder)
    59 {
    60   HoldDropJSObjectsHelper<T>::Hold(aHolder);
    61 }
    63 template<class T>
    64 void DropJSObjects(T* aHolder)
    65 {
    66   HoldDropJSObjectsHelper<T>::Drop(aHolder);
    67 }
    69 } // namespace mozilla
    71 #endif // mozilla_HoldDropJSObjects_h

mercurial