tor-browser

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

TestInterfaceMaplikeObject.cpp (2975B)


      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/TestInterfaceMaplikeObject.h"
      8 
      9 #include "mozilla/dom/BindingUtils.h"
     10 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
     11 #include "mozilla/dom/TestInterfaceMaplike.h"
     12 #include "nsPIDOMWindow.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceMaplikeObject, mParent)
     17 
     18 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceMaplikeObject)
     19 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceMaplikeObject)
     20 
     21 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceMaplikeObject)
     22  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     23  NS_INTERFACE_MAP_ENTRY(nsISupports)
     24 NS_INTERFACE_MAP_END
     25 
     26 TestInterfaceMaplikeObject::TestInterfaceMaplikeObject(
     27    nsPIDOMWindowInner* aParent)
     28    : mParent(aParent) {}
     29 
     30 // static
     31 already_AddRefed<TestInterfaceMaplikeObject>
     32 TestInterfaceMaplikeObject::Constructor(const GlobalObject& aGlobal,
     33                                        ErrorResult& aRv) {
     34  nsCOMPtr<nsPIDOMWindowInner> window =
     35      do_QueryInterface(aGlobal.GetAsSupports());
     36  if (!window) {
     37    aRv.Throw(NS_ERROR_FAILURE);
     38    return nullptr;
     39  }
     40 
     41  RefPtr<TestInterfaceMaplikeObject> r = new TestInterfaceMaplikeObject(window);
     42  return r.forget();
     43 }
     44 
     45 JSObject* TestInterfaceMaplikeObject::WrapObject(
     46    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     47  return TestInterfaceMaplikeObject_Binding::Wrap(aCx, this, aGivenProto);
     48 }
     49 
     50 nsPIDOMWindowInner* TestInterfaceMaplikeObject::GetParentObject() const {
     51  return mParent;
     52 }
     53 
     54 void TestInterfaceMaplikeObject::SetInternal(const nsAString& aKey) {
     55  RefPtr<TestInterfaceMaplike> p(new TestInterfaceMaplike(mParent));
     56  ErrorResult rv;
     57  TestInterfaceMaplikeObject_Binding::MaplikeHelpers::Set(this, aKey, *p, rv);
     58 }
     59 
     60 void TestInterfaceMaplikeObject::ClearInternal() {
     61  ErrorResult rv;
     62  TestInterfaceMaplikeObject_Binding::MaplikeHelpers::Clear(this, rv);
     63 }
     64 
     65 bool TestInterfaceMaplikeObject::DeleteInternal(const nsAString& aKey) {
     66  ErrorResult rv;
     67  return TestInterfaceMaplikeObject_Binding::MaplikeHelpers::Delete(this, aKey,
     68                                                                    rv);
     69 }
     70 
     71 bool TestInterfaceMaplikeObject::HasInternal(const nsAString& aKey) {
     72  ErrorResult rv;
     73  return TestInterfaceMaplikeObject_Binding::MaplikeHelpers::Has(this, aKey,
     74                                                                 rv);
     75 }
     76 
     77 already_AddRefed<TestInterfaceMaplike> TestInterfaceMaplikeObject::GetInternal(
     78    const nsAString& aKey, ErrorResult& aRv) {
     79  return TestInterfaceMaplikeObject_Binding::MaplikeHelpers::Get(this, aKey,
     80                                                                 aRv);
     81 }
     82 }  // namespace mozilla::dom