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/. */
10 #include "mozilla/UniquePtr.h"
12 #include "js/Utility.h"
16 // Replacement for mozilla::UniquePtr that defaults to JS::DeletePolicy.
17 template <typename T
, typename D
= JS::DeletePolicy
<T
>>
18 using UniquePtr
= mozilla::UniquePtr
<T
, D
>;
23 struct UniqueSelector
{
24 typedef UniquePtr
<T
> SingleObject
;
28 struct UniqueSelector
<T
[]> {
29 typedef UniquePtr
<T
[]> UnknownBound
;
32 template <typename T
, decltype(sizeof(int)) N
>
33 struct UniqueSelector
<T
[N
]> {
34 typedef UniquePtr
<T
[N
]> KnownBound
;
39 // Replacement for mozilla::MakeUnique that correctly calls js_new and produces
41 template <typename T
, typename
... Args
>
42 typename
detail::UniqueSelector
<T
>::SingleObject
MakeUnique(Args
&&... aArgs
) {
43 return UniquePtr
<T
>(js_new
<T
>(std::forward
<Args
>(aArgs
)...));
47 typename
detail::UniqueSelector
<T
>::UnknownBound
MakeUnique(
48 decltype(sizeof(int)) aN
) = delete;
50 template <typename T
, typename
... Args
>
51 typename
detail::UniqueSelector
<T
>::KnownBound
MakeUnique(Args
&&... aArgs
) =
56 #endif /* js_UniquePtr_h */