Bug 1890750 - Part 1: Include NATIVE_JIT_ENTRY in FunctionFlags::HasJitEntryFlags...
[gecko.git] / js / public / UniquePtr.h
blobd6bbb9ae610b6a704c8a7d00a985498326aea59b
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 js_UniquePtr_h
8 #define js_UniquePtr_h
10 #include "mozilla/UniquePtr.h"
12 #include "js/Utility.h"
14 namespace js {
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>;
20 namespace detail {
22 template <typename T>
23 struct UniqueSelector {
24 typedef UniquePtr<T> SingleObject;
27 template <typename T>
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;
37 } // namespace detail
39 // Replacement for mozilla::MakeUnique that correctly calls js_new and produces
40 // a js::UniquePtr.
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)...));
46 template <typename T>
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) =
52 delete;
54 } // namespace js
56 #endif /* js_UniquePtr_h */