|
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 |
|
16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(SpeechRecognitionResultList, mParent, mItems) |
|
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechRecognitionResultList) |
|
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechRecognitionResultList) |
|
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognitionResultList) |
|
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
21 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
22 NS_INTERFACE_MAP_END |
|
23 |
|
24 SpeechRecognitionResultList::SpeechRecognitionResultList(SpeechRecognition* aParent) |
|
25 : mParent(aParent) |
|
26 { |
|
27 SetIsDOMBinding(); |
|
28 } |
|
29 |
|
30 SpeechRecognitionResultList::~SpeechRecognitionResultList() |
|
31 { |
|
32 } |
|
33 |
|
34 nsISupports* |
|
35 SpeechRecognitionResultList::GetParentObject() const |
|
36 { |
|
37 return static_cast<DOMEventTargetHelper*>(mParent.get()); |
|
38 } |
|
39 |
|
40 JSObject* |
|
41 SpeechRecognitionResultList::WrapObject(JSContext* aCx) |
|
42 { |
|
43 return SpeechRecognitionResultListBinding::Wrap(aCx, this); |
|
44 } |
|
45 |
|
46 already_AddRefed<SpeechRecognitionResult> |
|
47 SpeechRecognitionResultList::IndexedGetter(uint32_t aIndex, bool& aPresent) |
|
48 { |
|
49 if (aIndex >= Length()) { |
|
50 aPresent = false; |
|
51 return nullptr; |
|
52 } |
|
53 |
|
54 aPresent = true; |
|
55 return Item(aIndex); |
|
56 } |
|
57 |
|
58 uint32_t |
|
59 SpeechRecognitionResultList::Length() const |
|
60 { |
|
61 return mItems.Length(); |
|
62 } |
|
63 |
|
64 already_AddRefed<SpeechRecognitionResult> |
|
65 SpeechRecognitionResultList::Item(uint32_t aIndex) |
|
66 { |
|
67 nsRefPtr<SpeechRecognitionResult> result = mItems.ElementAt(aIndex); |
|
68 return result.forget(); |
|
69 } |
|
70 } // namespace dom |
|
71 } // namespace mozilla |