tor-browser

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

RootedDictionary.h (1297B)


      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 #ifndef mozilla_dom_RootedDictionary_h__
      8 #define mozilla_dom_RootedDictionary_h__
      9 
     10 #include "jsapi.h"
     11 #include "mozilla/dom/Nullable.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 template <typename T>
     16 class MOZ_RAII RootedDictionary final : public T, private JS::CustomAutoRooter {
     17 public:
     18  template <typename CX>
     19  explicit RootedDictionary(const CX& cx) : T(), JS::CustomAutoRooter(cx) {}
     20 
     21  virtual void trace(JSTracer* trc) override { this->TraceDictionary(trc); }
     22 };
     23 
     24 template <typename T>
     25 class MOZ_RAII NullableRootedDictionary final : public Nullable<T>,
     26                                                private JS::CustomAutoRooter {
     27 public:
     28  template <typename CX>
     29  explicit NullableRootedDictionary(const CX& cx)
     30      : Nullable<T>(), JS::CustomAutoRooter(cx) {}
     31 
     32  virtual void trace(JSTracer* trc) override {
     33    if (!this->IsNull()) {
     34      this->Value().TraceDictionary(trc);
     35    }
     36  }
     37 };
     38 
     39 }  // namespace mozilla::dom
     40 
     41 #endif /* mozilla_dom_RootedDictionary_h__ */