SpeechRecognitionResultList.cpp (1947B)
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 "SpeechRecognitionResultList.h" 8 9 #include "SpeechRecognition.h" 10 #include "mozilla/dom/SpeechRecognitionResultListBinding.h" 11 12 namespace mozilla::dom { 13 14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SpeechRecognitionResultList, mParent, 15 mItems) 16 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechRecognitionResultList) 17 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechRecognitionResultList) 18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognitionResultList) 19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 20 NS_INTERFACE_MAP_ENTRY(nsISupports) 21 NS_INTERFACE_MAP_END 22 23 SpeechRecognitionResultList::SpeechRecognitionResultList( 24 SpeechRecognition* aParent) 25 : mParent(aParent) {} 26 27 SpeechRecognitionResultList::~SpeechRecognitionResultList() = default; 28 29 nsISupports* SpeechRecognitionResultList::GetParentObject() const { 30 return static_cast<EventTarget*>(mParent.get()); 31 } 32 33 JSObject* SpeechRecognitionResultList::WrapObject( 34 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 35 return SpeechRecognitionResultList_Binding::Wrap(aCx, this, aGivenProto); 36 } 37 38 already_AddRefed<SpeechRecognitionResult> 39 SpeechRecognitionResultList::IndexedGetter(uint32_t aIndex, bool& aPresent) { 40 if (aIndex >= Length()) { 41 aPresent = false; 42 return nullptr; 43 } 44 45 aPresent = true; 46 return Item(aIndex); 47 } 48 49 uint32_t SpeechRecognitionResultList::Length() const { return mItems.Length(); } 50 51 already_AddRefed<SpeechRecognitionResult> SpeechRecognitionResultList::Item( 52 uint32_t aIndex) { 53 RefPtr<SpeechRecognitionResult> result = mItems.ElementAt(aIndex); 54 return result.forget(); 55 } 56 57 } // namespace mozilla::dom