michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_HoldDropJSObjects_h michael@0: #define mozilla_HoldDropJSObjects_h michael@0: michael@0: #include "mozilla/TypeTraits.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: class nsISupports; michael@0: class nsScriptObjectTracer; michael@0: michael@0: // Only HoldJSObjects and DropJSObjects should be called directly. michael@0: michael@0: namespace mozilla { michael@0: namespace cyclecollector { michael@0: michael@0: // These methods are defined in nsCycleCollector.cpp michael@0: void HoldJSObjectsImpl(void* aHolder, nsScriptObjectTracer* aTracer); michael@0: void HoldJSObjectsImpl(nsISupports* aHolder); michael@0: void DropJSObjectsImpl(void* aHolder); michael@0: void DropJSObjectsImpl(nsISupports* aHolder); michael@0: michael@0: } // namespace cyclecollector michael@0: michael@0: michael@0: template::value> michael@0: struct HoldDropJSObjectsHelper michael@0: { michael@0: static void Hold(T* aHolder) michael@0: { michael@0: cyclecollector::HoldJSObjectsImpl(aHolder, NS_CYCLE_COLLECTION_PARTICIPANT(T)); michael@0: } michael@0: static void Drop(T* aHolder) michael@0: { michael@0: cyclecollector::DropJSObjectsImpl(aHolder); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct HoldDropJSObjectsHelper michael@0: { michael@0: static void Hold(T* aHolder) michael@0: { michael@0: cyclecollector::HoldJSObjectsImpl(ToSupports(aHolder)); michael@0: } michael@0: static void Drop(T* aHolder) michael@0: { michael@0: cyclecollector::DropJSObjectsImpl(ToSupports(aHolder)); michael@0: } michael@0: }; michael@0: michael@0: michael@0: template michael@0: void HoldJSObjects(T* aHolder) michael@0: { michael@0: HoldDropJSObjectsHelper::Hold(aHolder); michael@0: } michael@0: michael@0: template michael@0: void DropJSObjects(T* aHolder) michael@0: { michael@0: HoldDropJSObjectsHelper::Drop(aHolder); michael@0: } michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_HoldDropJSObjects_h