Bug 1698238 return default dictionary from GetUserMediaRequest#getConstraints() if...
[gecko.git] / layout / style / FontFaceSetIterator.cpp
blobd1379f2c702d10a44011aaf8a9a5a44e4e3a39e5
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
11 namespace mozilla {
12 namespace dom {
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,
20 bool aIsKeyAndValue)
21 : mFontFaceSet(aFontFaceSet),
22 mNextIndex(0),
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,
39 ErrorResult& aRv) {
40 if (!mFontFaceSet) {
41 aResult.mDone = true;
42 return;
45 FontFace* face = mFontFaceSet->GetFontFaceAt(mNextIndex++);
47 if (!face) {
48 aResult.mValue.setUndefined();
49 aResult.mDone = true;
50 mFontFaceSet = nullptr;
51 return;
54 JS::Rooted<JS::Value> value(aCx);
55 if (!ToJSValue(aCx, face, &value)) {
56 aRv.Throw(NS_ERROR_FAILURE);
57 return;
60 if (mIsKeyAndValue) {
61 JS::RootedValueArray<2> values(aCx);
62 values[0].set(value);
63 values[1].set(value);
65 JS::Rooted<JSObject*> array(aCx);
66 array = JS::NewArrayObject(aCx, values);
67 if (array) {
68 aResult.mValue.setObject(*array);
70 } else {
71 aResult.mValue = value;
74 aResult.mDone = false;
77 } // namespace dom
78 } // namespace mozilla