tor-browser

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

TestInterfaceIterableDouble.cpp (2438B)


      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/TestInterfaceIterableDouble.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(TestInterfaceIterableDouble, mParent)
     16 
     17 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceIterableDouble)
     18 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceIterableDouble)
     19 
     20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceIterableDouble)
     21  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     22  NS_INTERFACE_MAP_ENTRY(nsISupports)
     23 NS_INTERFACE_MAP_END
     24 
     25 TestInterfaceIterableDouble::TestInterfaceIterableDouble(
     26    nsPIDOMWindowInner* aParent)
     27    : mParent(aParent) {
     28  mValues.AppendElement(std::pair<nsString, nsString>(u"a"_ns, u"b"_ns));
     29  mValues.AppendElement(std::pair<nsString, nsString>(u"c"_ns, u"d"_ns));
     30  mValues.AppendElement(std::pair<nsString, nsString>(u"e"_ns, u"f"_ns));
     31 }
     32 
     33 // static
     34 already_AddRefed<TestInterfaceIterableDouble>
     35 TestInterfaceIterableDouble::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<TestInterfaceIterableDouble> r =
     45      new TestInterfaceIterableDouble(window);
     46  return r.forget();
     47 }
     48 
     49 JSObject* TestInterfaceIterableDouble::WrapObject(
     50    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     51  return TestInterfaceIterableDouble_Binding::Wrap(aCx, this, aGivenProto);
     52 }
     53 
     54 nsPIDOMWindowInner* TestInterfaceIterableDouble::GetParentObject() const {
     55  return mParent;
     56 }
     57 
     58 size_t TestInterfaceIterableDouble::GetIterableLength() {
     59  return mValues.Length();
     60 }
     61 
     62 nsAString& TestInterfaceIterableDouble::GetKeyAtIndex(uint32_t aIndex) {
     63  MOZ_ASSERT(aIndex < mValues.Length());
     64  return mValues.ElementAt(aIndex).first;
     65 }
     66 
     67 nsAString& TestInterfaceIterableDouble::GetValueAtIndex(uint32_t aIndex) {
     68  MOZ_ASSERT(aIndex < mValues.Length());
     69  return mValues.ElementAt(aIndex).second;
     70 }
     71 
     72 }  // namespace mozilla::dom