LCOV - code coverage report
Current view: top level - js/public - UniquePtr.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 2 100.0 %
Date: 2017-07-14 16:53:18 Functions: 2 24 8.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  * vim: set ts=8 sts=4 et sw=4 tw=99:
       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/. */
       6             : 
       7             : #ifndef js_UniquePtr_h
       8             : #define js_UniquePtr_h
       9             : 
      10             : #include "mozilla/UniquePtr.h"
      11             : 
      12             : #include "js/Utility.h"
      13             : 
      14             : namespace js {
      15             : 
      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>;
      19             : 
      20             : namespace detail {
      21             : 
      22             : template<typename T>
      23             : struct UniqueSelector
      24             : {
      25             :   typedef UniquePtr<T> SingleObject;
      26             : };
      27             : 
      28             : template<typename T>
      29             : struct UniqueSelector<T[]>
      30             : {
      31             :   typedef UniquePtr<T[]> UnknownBound;
      32             : };
      33             : 
      34             : template<typename T, decltype(sizeof(int)) N>
      35             : struct UniqueSelector<T[N]>
      36             : {
      37             :   typedef UniquePtr<T[N]> KnownBound;
      38             : };
      39             : 
      40             : } // namespace detail
      41             : 
      42             : // Replacement for mozilla::MakeUnique that correctly calls js_new and produces
      43             : // a js::UniquePtr.
      44             : template<typename T, typename... Args>
      45             : typename detail::UniqueSelector<T>::SingleObject
      46         158 : MakeUnique(Args&&... aArgs)
      47             : {
      48         158 :   return UniquePtr<T>(js_new<T>(mozilla::Forward<Args>(aArgs)...));
      49             : }
      50             : 
      51             : template<typename T>
      52             : typename detail::UniqueSelector<T>::UnknownBound
      53             : MakeUnique(decltype(sizeof(int)) aN) = delete;
      54             : 
      55             : template<typename T, typename... Args>
      56             : typename detail::UniqueSelector<T>::KnownBound
      57             : MakeUnique(Args&&... aArgs) = delete;
      58             : 
      59             : } // namespace js
      60             : 
      61             : #endif /* js_UniquePtr_h */

Generated by: LCOV version 1.13