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 FontFaceSetIterator::FontFaceSetIterator(FontFaceSet
* aFontFaceSet
,
18 : mFontFaceSet(aFontFaceSet
),
20 mIsKeyAndValue(aIsKeyAndValue
) {
21 MOZ_COUNT_CTOR(FontFaceSetIterator
);
24 FontFaceSetIterator::~FontFaceSetIterator() {
25 MOZ_COUNT_DTOR(FontFaceSetIterator
);
28 bool FontFaceSetIterator::WrapObject(JSContext
* aCx
,
29 JS::Handle
<JSObject
*> aGivenProto
,
30 JS::MutableHandle
<JSObject
*> aReflector
) {
31 return FontFaceSetIterator_Binding::Wrap(aCx
, this, aGivenProto
, aReflector
);
34 void FontFaceSetIterator::Next(JSContext
* aCx
,
35 FontFaceSetIteratorResult
& aResult
,
42 // Skip over non-Author origin fonts (GetFontFaceAt returns nullptr
45 while (!(face
= mFontFaceSet
->GetFontFaceAt(mNextIndex
++))) {
46 if (mNextIndex
>= mFontFaceSet
->SizeIncludingNonAuthorOrigins()) {
47 break; // this iterator is done
52 aResult
.mValue
.setUndefined();
54 mFontFaceSet
= nullptr;
58 JS::Rooted
<JS::Value
> value(aCx
);
59 if (!ToJSValue(aCx
, face
, &value
)) {
60 aRv
.Throw(NS_ERROR_FAILURE
);
65 JS::RootedValueArray
<2> values(aCx
);
69 JS::Rooted
<JSObject
*> array(aCx
);
70 array
= JS::NewArrayObject(aCx
, values
);
72 aResult
.mValue
.setObject(*array
);
75 aResult
.mValue
= value
;
78 aResult
.mDone
= false;
82 } // namespace mozilla