Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/FontFaceSetIterator.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 "mozilla/dom/FontFaceSetIterator.h"
8
9
namespace mozilla {
10
namespace dom {
11
12
NS_IMPL_CYCLE_COLLECTION(FontFaceSetIterator, mFontFaceSet)
13
14
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(FontFaceSetIterator, AddRef)
15
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(FontFaceSetIterator, Release)
16
17
FontFaceSetIterator::FontFaceSetIterator(FontFaceSet* aFontFaceSet,
18
                                         bool aIsKeyAndValue)
19
  : mFontFaceSet(aFontFaceSet)
20
  , mNextIndex(0)
21
  , mIsKeyAndValue(aIsKeyAndValue)
22
0
{
23
0
  MOZ_COUNT_CTOR(FontFaceSetIterator);
24
0
}
25
26
FontFaceSetIterator::~FontFaceSetIterator()
27
0
{
28
0
  MOZ_COUNT_DTOR(FontFaceSetIterator);
29
0
}
30
31
bool
32
FontFaceSetIterator::WrapObject(JSContext* aCx,
33
                                JS::Handle<JSObject*> aGivenProto,
34
                                JS::MutableHandle<JSObject*> aReflector)
35
0
{
36
0
  return FontFaceSetIterator_Binding::Wrap(aCx, this, aGivenProto, aReflector);
37
0
}
38
39
void
40
FontFaceSetIterator::Next(JSContext* aCx, FontFaceSetIteratorResult& aResult,
41
                          ErrorResult& aRv)
42
0
{
43
0
  if (!mFontFaceSet) {
44
0
    aResult.mDone = true;
45
0
    return;
46
0
  }
47
0
48
0
  FontFace* face = mFontFaceSet->GetFontFaceAt(mNextIndex++);
49
0
50
0
  if (!face) {
51
0
    aResult.mValue.setUndefined();
52
0
    aResult.mDone = true;
53
0
    mFontFaceSet = nullptr;
54
0
    return;
55
0
  }
56
0
57
0
  JS::Rooted<JS::Value> value(aCx);
58
0
  if (!ToJSValue(aCx, face, &value)) {
59
0
    aRv.Throw(NS_ERROR_FAILURE);
60
0
    return;
61
0
  }
62
0
63
0
  if (mIsKeyAndValue) {
64
0
    JS::AutoValueArray<2> values(aCx);
65
0
    values[0].set(value);
66
0
    values[1].set(value);
67
0
68
0
    JS::Rooted<JSObject*> array(aCx);
69
0
    array = JS_NewArrayObject(aCx, values);
70
0
    if (array) {
71
0
      aResult.mValue.setObject(*array);
72
0
    }
73
0
  } else {
74
0
    aResult.mValue = value;
75
0
  }
76
0
77
0
  aResult.mDone = false;
78
0
}
79
80
} // namespace dom
81
} // namespace mozilla