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