diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /layout/style/FontFaceSetIterator.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'layout/style/FontFaceSetIterator.cpp')
-rw-r--r-- | layout/style/FontFaceSetIterator.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/layout/style/FontFaceSetIterator.cpp b/layout/style/FontFaceSetIterator.cpp new file mode 100644 index 000000000..74997eb1a --- /dev/null +++ b/layout/style/FontFaceSetIterator.cpp @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/dom/FontFaceSetIterator.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION(FontFaceSetIterator, mFontFaceSet) + +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(FontFaceSetIterator, AddRef) +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(FontFaceSetIterator, Release) + +FontFaceSetIterator::FontFaceSetIterator(FontFaceSet* aFontFaceSet, + bool aIsKeyAndValue) + : mFontFaceSet(aFontFaceSet) + , mNextIndex(0) + , mIsKeyAndValue(aIsKeyAndValue) +{ + MOZ_COUNT_CTOR(FontFaceSetIterator); +} + +FontFaceSetIterator::~FontFaceSetIterator() +{ + MOZ_COUNT_DTOR(FontFaceSetIterator); +} + +bool +FontFaceSetIterator::WrapObject(JSContext* aCx, + JS::Handle<JSObject*> aGivenProto, + JS::MutableHandle<JSObject*> aReflector) +{ + return FontFaceSetIteratorBinding::Wrap(aCx, this, aGivenProto, aReflector); +} + +void +FontFaceSetIterator::Next(JSContext* aCx, FontFaceSetIteratorResult& aResult, + ErrorResult& aRv) +{ + if (!mFontFaceSet) { + aResult.mDone = true; + return; + } + + FontFace* face = mFontFaceSet->GetFontFaceAt(mNextIndex++); + + if (!face) { + aResult.mValue.setUndefined(); + aResult.mDone = true; + mFontFaceSet = nullptr; + return; + } + + JS::Rooted<JS::Value> value(aCx); + if (!ToJSValue(aCx, face, &value)) { + aRv.Throw(NS_ERROR_FAILURE); + return; + } + + if (mIsKeyAndValue) { + JS::AutoValueArray<2> values(aCx); + values[0].set(value); + values[1].set(value); + + JS::Rooted<JSObject*> array(aCx); + array = JS_NewArrayObject(aCx, values); + if (array) { + aResult.mValue.setObject(*array); + } + } else { + aResult.mValue = value; + } + + aResult.mDone = false; +} + +} // namespace dom +} // namespace mozilla |