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/. */
7 #include "mozilla/dom/FontFaceSetIterator.h"
9 #include "js/Array.h" // JS::NewArrayObject
14 NS_IMPL_CYCLE_COLLECTION(FontFaceSetIterator
, mFontFaceSet
)
16 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(FontFaceSetIterator
, AddRef
)
17 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(FontFaceSetIterator
, Release
)
19 FontFaceSetIterator::FontFaceSetIterator(FontFaceSet
* aFontFaceSet
,
21 : mFontFaceSet(aFontFaceSet
),
23 mIsKeyAndValue(aIsKeyAndValue
) {
24 MOZ_COUNT_CTOR(FontFaceSetIterator
);
27 FontFaceSetIterator::~FontFaceSetIterator() {
28 MOZ_COUNT_DTOR(FontFaceSetIterator
);
31 bool FontFaceSetIterator::WrapObject(JSContext
* aCx
,
32 JS::Handle
<JSObject
*> aGivenProto
,
33 JS::MutableHandle
<JSObject
*> aReflector
) {
34 return FontFaceSetIterator_Binding::Wrap(aCx
, this, aGivenProto
, aReflector
);
37 void FontFaceSetIterator::Next(JSContext
* aCx
,
38 FontFaceSetIteratorResult
& aResult
,
45 FontFace
* face
= mFontFaceSet
->GetFontFaceAt(mNextIndex
++);
48 aResult
.mValue
.setUndefined();
50 mFontFaceSet
= nullptr;
54 JS::Rooted
<JS::Value
> value(aCx
);
55 if (!ToJSValue(aCx
, face
, &value
)) {
56 aRv
.Throw(NS_ERROR_FAILURE
);
61 JS::RootedValueArray
<2> values(aCx
);
65 JS::Rooted
<JSObject
*> array(aCx
);
66 array
= JS::NewArrayObject(aCx
, values
);
68 aResult
.mValue
.setObject(*array
);
71 aResult
.mValue
= value
;
74 aResult
.mDone
= false;
78 } // namespace mozilla