Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #include "mozilla/dom/TestInterfaceIterableSingle.h"
6 : #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
7 : #include "nsPIDOMWindow.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceIterableSingle, mParent)
14 :
15 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceIterableSingle)
16 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceIterableSingle)
17 :
18 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceIterableSingle)
19 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
21 0 : NS_INTERFACE_MAP_END
22 :
23 0 : TestInterfaceIterableSingle::TestInterfaceIterableSingle(nsPIDOMWindowInner* aParent)
24 0 : : mParent(aParent)
25 : {
26 0 : for (int i = 0; i < 3; ++i) {
27 0 : mValues.AppendElement(i);
28 : }
29 0 : }
30 :
31 : //static
32 : already_AddRefed<TestInterfaceIterableSingle>
33 0 : TestInterfaceIterableSingle::Constructor(const GlobalObject& aGlobal,
34 : ErrorResult& aRv)
35 : {
36 0 : nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
37 0 : if (!window) {
38 0 : aRv.Throw(NS_ERROR_FAILURE);
39 0 : return nullptr;
40 : }
41 :
42 0 : RefPtr<TestInterfaceIterableSingle> r = new TestInterfaceIterableSingle(window);
43 0 : return r.forget();
44 : }
45 :
46 : JSObject*
47 0 : TestInterfaceIterableSingle::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
48 : {
49 0 : return TestInterfaceIterableSingleBinding::Wrap(aCx, this, aGivenProto);
50 : }
51 :
52 : nsPIDOMWindowInner*
53 0 : TestInterfaceIterableSingle::GetParentObject() const
54 : {
55 0 : return mParent;
56 : }
57 :
58 : uint32_t
59 0 : TestInterfaceIterableSingle::Length() const
60 : {
61 0 : return mValues.Length();
62 : }
63 :
64 : int32_t
65 0 : TestInterfaceIterableSingle::IndexedGetter(uint32_t aIndex, bool& aFound) const
66 : {
67 0 : if (aIndex >= mValues.Length()) {
68 0 : aFound = false;
69 0 : return 0;
70 : }
71 :
72 0 : aFound = true;
73 0 : return mValues[aIndex];
74 : }
75 :
76 : } // namespace dom
77 9 : } // namespace mozilla
|