Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "mozilla/dom/FontFaceSetIterator.h"
7 :
8 : namespace mozilla {
9 : namespace dom {
10 :
11 0 : NS_IMPL_CYCLE_COLLECTION(FontFaceSetIterator, mFontFaceSet)
12 :
13 0 : NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(FontFaceSetIterator, AddRef)
14 0 : NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(FontFaceSetIterator, Release)
15 :
16 0 : FontFaceSetIterator::FontFaceSetIterator(FontFaceSet* aFontFaceSet,
17 0 : bool aIsKeyAndValue)
18 : : mFontFaceSet(aFontFaceSet)
19 : , mNextIndex(0)
20 0 : , mIsKeyAndValue(aIsKeyAndValue)
21 : {
22 0 : MOZ_COUNT_CTOR(FontFaceSetIterator);
23 0 : }
24 :
25 0 : FontFaceSetIterator::~FontFaceSetIterator()
26 : {
27 0 : MOZ_COUNT_DTOR(FontFaceSetIterator);
28 0 : }
29 :
30 : bool
31 0 : FontFaceSetIterator::WrapObject(JSContext* aCx,
32 : JS::Handle<JSObject*> aGivenProto,
33 : JS::MutableHandle<JSObject*> aReflector)
34 : {
35 0 : return FontFaceSetIteratorBinding::Wrap(aCx, this, aGivenProto, aReflector);
36 : }
37 :
38 : void
39 0 : FontFaceSetIterator::Next(JSContext* aCx, FontFaceSetIteratorResult& aResult,
40 : ErrorResult& aRv)
41 : {
42 0 : if (!mFontFaceSet) {
43 0 : aResult.mDone = true;
44 0 : return;
45 : }
46 :
47 0 : FontFace* face = mFontFaceSet->GetFontFaceAt(mNextIndex++);
48 :
49 0 : if (!face) {
50 0 : aResult.mValue.setUndefined();
51 0 : aResult.mDone = true;
52 0 : mFontFaceSet = nullptr;
53 0 : return;
54 : }
55 :
56 0 : JS::Rooted<JS::Value> value(aCx);
57 0 : if (!ToJSValue(aCx, face, &value)) {
58 0 : aRv.Throw(NS_ERROR_FAILURE);
59 0 : return;
60 : }
61 :
62 0 : if (mIsKeyAndValue) {
63 0 : JS::AutoValueArray<2> values(aCx);
64 0 : values[0].set(value);
65 0 : values[1].set(value);
66 :
67 0 : JS::Rooted<JSObject*> array(aCx);
68 0 : array = JS_NewArrayObject(aCx, values);
69 0 : if (array) {
70 0 : aResult.mValue.setObject(*array);
71 : }
72 : } else {
73 0 : aResult.mValue = value;
74 : }
75 :
76 0 : aResult.mDone = false;
77 : }
78 :
79 : } // namespace dom
80 : } // namespace mozilla
|