Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/ds/nsSimpleEnumerator.cpp
Line
Count
Source (jump to first uncovered line)
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 "nsSimpleEnumerator.h"
8
9
#include "mozilla/dom/IteratorResultBinding.h"
10
#include "mozilla/dom/RootedDictionary.h"
11
#include "mozilla/dom/ToJSValue.h"
12
#include "mozilla/ResultExtensions.h"
13
#include "nsContentUtils.h"
14
15
using namespace mozilla;
16
using namespace mozilla::dom;
17
18
namespace {
19
20
class JSEnumerator final : public nsIJSEnumerator
21
{
22
  NS_DECL_ISUPPORTS
23
  NS_DECL_NSIJSENUMERATOR
24
25
  explicit JSEnumerator(nsISimpleEnumerator* aEnumerator, const nsID& aIID)
26
    : mEnumerator(aEnumerator)
27
    , mIID(aIID)
28
0
  {}
29
30
private:
31
0
  ~JSEnumerator() = default;
32
33
  nsCOMPtr<nsISimpleEnumerator> mEnumerator;
34
  const nsID mIID;
35
};
36
37
} // anonymous namespace
38
39
nsresult
40
JSEnumerator::Iterator(nsIJSEnumerator** aResult)
41
0
{
42
0
  RefPtr<JSEnumerator> result(this);
43
0
  result.forget(aResult);
44
0
  return NS_OK;
45
0
}
46
47
nsresult
48
JSEnumerator::Next(JSContext* aCx, JS::MutableHandleValue aResult)
49
0
{
50
0
  RootedDictionary<IteratorResult> result(aCx);
51
0
52
0
  nsCOMPtr<nsISupports> elem;
53
0
  if (NS_FAILED(mEnumerator->GetNext(getter_AddRefs(elem)))) {
54
0
    result.mDone = true;
55
0
  } else {
56
0
    result.mDone = false;
57
0
58
0
    JS::RootedValue value(aCx);
59
0
    MOZ_TRY(nsContentUtils::WrapNative(aCx, elem, &mIID, &value));
60
0
    result.mValue = value;
61
0
  }
62
0
63
0
  if (!ToJSValue(aCx, result, aResult)) {
64
0
    return NS_ERROR_OUT_OF_MEMORY;
65
0
  }
66
0
  return NS_OK;
67
0
}
68
69
NS_IMPL_ISUPPORTS(JSEnumerator, nsIJSEnumerator)
70
71
nsresult
72
nsSimpleEnumerator::Iterator(nsIJSEnumerator **aResult)
73
0
{
74
0
  auto result = MakeRefPtr<JSEnumerator>(this, DefaultInterface());
75
0
  result.forget(aResult);
76
0
  return NS_OK;
77
0
}
78
79
nsresult
80
nsSimpleEnumerator::Entries(const nsIID& aIface, nsIJSEnumerator **aResult)
81
0
{
82
0
  auto result = MakeRefPtr<JSEnumerator>(this, aIface);
83
0
  result.forget(aResult);
84
0
  return NS_OK;
85
0
}
86
87
NS_IMPL_ISUPPORTS(nsSimpleEnumerator, nsISimpleEnumerator, nsISimpleEnumeratorBase)