CSSNumericArray.cpp (1965B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 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/. */ 6 7 #include "mozilla/dom/CSSNumericArray.h" 8 9 #include "mozilla/Assertions.h" 10 #include "mozilla/dom/CSSNumericArrayBinding.h" 11 #include "mozilla/dom/CSSNumericValue.h" 12 #include "nsCycleCollectionParticipant.h" 13 14 namespace mozilla::dom { 15 16 CSSNumericArray::CSSNumericArray(nsCOMPtr<nsISupports> aParent, 17 nsTArray<RefPtr<CSSNumericValue>> aValues) 18 : mParent(std::move(aParent)), mValues(std::move(aValues)) { 19 MOZ_ASSERT(mParent); 20 } 21 22 NS_IMPL_CYCLE_COLLECTING_ADDREF(CSSNumericArray) 23 NS_IMPL_CYCLE_COLLECTING_RELEASE(CSSNumericArray) 24 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSNumericArray) 25 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 26 NS_INTERFACE_MAP_ENTRY(nsISupports) 27 NS_INTERFACE_MAP_END 28 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CSSNumericArray, mParent, mValues) 29 30 nsISupports* CSSNumericArray::GetParentObject() const { return mParent; } 31 32 JSObject* CSSNumericArray::WrapObject(JSContext* aCx, 33 JS::Handle<JSObject*> aGivenProto) { 34 return CSSNumericArray_Binding::Wrap(aCx, this, aGivenProto); 35 } 36 37 // start of CSSNumericArray Web IDL implementation 38 39 // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssnumericarray-length 40 uint32_t CSSNumericArray::Length() const { return mValues.Length(); } 41 42 // https://drafts.css-houdini.org/css-typed-om-1/#cssnumericarray-indexed-property-getter 43 CSSNumericValue* CSSNumericArray::IndexedGetter(uint32_t aIndex, bool& aFound) { 44 if (aIndex < mValues.Length()) { 45 aFound = true; 46 return mValues[aIndex]; 47 } 48 49 aFound = false; 50 return nullptr; 51 } 52 53 // end of CSSNumericArray Web IDL implementation 54 55 } // namespace mozilla::dom