tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TestInterfaceIterableSingle.cpp (2220B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "mozilla/dom/TestInterfaceIterableSingle.h"
      8 
      9 #include "mozilla/dom/BindingUtils.h"
     10 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
     11 #include "nsPIDOMWindow.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceIterableSingle, mParent)
     16 
     17 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceIterableSingle)
     18 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceIterableSingle)
     19 
     20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceIterableSingle)
     21  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     22  NS_INTERFACE_MAP_ENTRY(nsISupports)
     23 NS_INTERFACE_MAP_END
     24 
     25 TestInterfaceIterableSingle::TestInterfaceIterableSingle(
     26    nsPIDOMWindowInner* aParent)
     27    : mParent(aParent) {
     28  for (int i = 0; i < 3; ++i) {
     29    mValues.AppendElement(i);
     30  }
     31 }
     32 
     33 // static
     34 already_AddRefed<TestInterfaceIterableSingle>
     35 TestInterfaceIterableSingle::Constructor(const GlobalObject& aGlobal,
     36                                         ErrorResult& aRv) {
     37  nsCOMPtr<nsPIDOMWindowInner> window =
     38      do_QueryInterface(aGlobal.GetAsSupports());
     39  if (!window) {
     40    aRv.Throw(NS_ERROR_FAILURE);
     41    return nullptr;
     42  }
     43 
     44  RefPtr<TestInterfaceIterableSingle> r =
     45      new TestInterfaceIterableSingle(window);
     46  return r.forget();
     47 }
     48 
     49 JSObject* TestInterfaceIterableSingle::WrapObject(
     50    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     51  return TestInterfaceIterableSingle_Binding::Wrap(aCx, this, aGivenProto);
     52 }
     53 
     54 nsPIDOMWindowInner* TestInterfaceIterableSingle::GetParentObject() const {
     55  return mParent;
     56 }
     57 
     58 uint32_t TestInterfaceIterableSingle::Length() const {
     59  return mValues.Length();
     60 }
     61 
     62 int32_t TestInterfaceIterableSingle::IndexedGetter(uint32_t aIndex,
     63                                                   bool& aFound) const {
     64  if (aIndex >= mValues.Length()) {
     65    aFound = false;
     66    return 0;
     67  }
     68 
     69  aFound = true;
     70  return mValues[aIndex];
     71 }
     72 
     73 }  // namespace mozilla::dom