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