1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/src/qsObjectHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=99: */ 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 qsObjectHelper_h 1.11 +#define qsObjectHelper_h 1.12 + 1.13 +#include "xpcObjectHelper.h" 1.14 + 1.15 +#include "nsAutoPtr.h" 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsWrapperCache.h" 1.18 +#include "mozilla/TypeTraits.h" 1.19 + 1.20 +class qsObjectHelper : public xpcObjectHelper 1.21 +{ 1.22 +public: 1.23 + template <class T> 1.24 + inline 1.25 + qsObjectHelper(T *aObject, nsWrapperCache *aCache) 1.26 + : xpcObjectHelper(ToSupports(aObject), ToCanonicalSupports(aObject), 1.27 + aCache) 1.28 + {} 1.29 + 1.30 + template <class T> 1.31 + inline 1.32 + qsObjectHelper(nsCOMPtr<T>& aObject, nsWrapperCache *aCache) 1.33 + : xpcObjectHelper(ToSupports(aObject.get()), 1.34 + ToCanonicalSupports(aObject.get()), aCache) 1.35 + { 1.36 + if (mCanonical) { 1.37 + // Transfer the strong reference. 1.38 + mCanonicalStrong = dont_AddRef(mCanonical); 1.39 + aObject.forget(); 1.40 + } 1.41 + } 1.42 + 1.43 + template <class T> 1.44 + inline 1.45 + qsObjectHelper(nsRefPtr<T>& aObject, nsWrapperCache *aCache) 1.46 + : xpcObjectHelper(ToSupports(aObject.get()), 1.47 + ToCanonicalSupports(aObject.get()), aCache) 1.48 + { 1.49 + if (mCanonical) { 1.50 + // Transfer the strong reference. 1.51 + mCanonicalStrong = dont_AddRef(mCanonical); 1.52 + aObject.forget(); 1.53 + } 1.54 + } 1.55 +}; 1.56 + 1.57 +#endif