LCOV - code coverage report
Current view: top level - xpcom/ds - nsProperties.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 7 43 16.3 %
Date: 2017-07-14 16:53:18 Functions: 8 12 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : #include "nsProperties.h"
       8             : 
       9             : ////////////////////////////////////////////////////////////////////////////////
      10             : 
      11         536 : NS_IMPL_AGGREGATED(nsProperties)
      12          82 : NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties)
      13          82 :   NS_INTERFACE_MAP_ENTRY(nsIProperties)
      14           0 : NS_INTERFACE_MAP_END
      15             : 
      16             : NS_IMETHODIMP
      17           0 : nsProperties::Get(const char* prop, const nsIID& uuid, void** result)
      18             : {
      19           0 :   if (NS_WARN_IF(!prop)) {
      20           0 :     return NS_ERROR_INVALID_ARG;
      21             :   }
      22             : 
      23           0 :   nsCOMPtr<nsISupports> value;
      24           0 :   if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
      25           0 :     return NS_ERROR_FAILURE;
      26             :   }
      27           0 :   return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE;
      28             : }
      29             : 
      30             : NS_IMETHODIMP
      31          41 : nsProperties::Set(const char* prop, nsISupports* value)
      32             : {
      33          41 :   if (NS_WARN_IF(!prop)) {
      34           0 :     return NS_ERROR_INVALID_ARG;
      35             :   }
      36          41 :   Put(prop, value);
      37          41 :   return NS_OK;
      38             : }
      39             : 
      40             : NS_IMETHODIMP
      41           0 : nsProperties::Undefine(const char* prop)
      42             : {
      43           0 :   if (NS_WARN_IF(!prop)) {
      44           0 :     return NS_ERROR_INVALID_ARG;
      45             :   }
      46             : 
      47           0 :   return nsProperties_HashBase::Remove(prop) ? NS_OK : NS_ERROR_FAILURE;
      48             : }
      49             : 
      50             : NS_IMETHODIMP
      51           0 : nsProperties::Has(const char* prop, bool* result)
      52             : {
      53           0 :   if (NS_WARN_IF(!prop)) {
      54           0 :     return NS_ERROR_INVALID_ARG;
      55             :   }
      56             : 
      57           0 :   *result = nsProperties_HashBase::Contains(prop);
      58           0 :   return NS_OK;
      59             : }
      60             : 
      61             : NS_IMETHODIMP
      62           0 : nsProperties::GetKeys(uint32_t* aCount, char*** aKeys)
      63             : {
      64           0 :   if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) {
      65           0 :     return NS_ERROR_INVALID_ARG;
      66             :   }
      67             : 
      68           0 :   uint32_t count = Count();
      69           0 :   char** keys = (char**)moz_xmalloc(count * sizeof(char*));
      70           0 :   uint32_t j = 0;
      71             : 
      72           0 :   for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
      73           0 :     const char* key = iter.Key();
      74           0 :     keys[j] = strdup(key);
      75             : 
      76           0 :     if (!keys[j]) {
      77             :       // Free 'em all
      78           0 :       for (uint32_t i = 0; i < j; i++) {
      79           0 :         free(keys[i]);
      80             :       }
      81           0 :       free(keys);
      82           0 :       return NS_ERROR_OUT_OF_MEMORY;
      83             :     }
      84           0 :     j++;
      85             :   }
      86             : 
      87           0 :   *aCount = count;
      88           0 :   *aKeys = keys;
      89           0 :   return NS_OK;
      90             : }
      91             : 
      92             : ////////////////////////////////////////////////////////////////////////////////

Generated by: LCOV version 1.13