xpcom/glue/HoldDropJSObjects.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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