1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/bindings/RootedDictionary.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ 1.5 +/* vim: set ts=2 sw=2 et tw=79: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_RootedDictionary_h__ 1.11 +#define mozilla_dom_RootedDictionary_h__ 1.12 + 1.13 +#include "mozilla/GuardObjects.h" 1.14 +#include "mozilla/dom/Nullable.h" 1.15 +#include "jsapi.h" 1.16 + 1.17 +namespace mozilla { 1.18 +namespace dom { 1.19 + 1.20 +template<typename T> 1.21 +class MOZ_STACK_CLASS RootedDictionary : public T, 1.22 + private JS::CustomAutoRooter 1.23 +{ 1.24 +public: 1.25 + RootedDictionary(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : 1.26 + T(), 1.27 + JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) 1.28 + { 1.29 + } 1.30 + 1.31 + virtual void trace(JSTracer *trc) MOZ_OVERRIDE 1.32 + { 1.33 + this->TraceDictionary(trc); 1.34 + } 1.35 +}; 1.36 + 1.37 +template<typename T> 1.38 +class MOZ_STACK_CLASS NullableRootedDictionary : public Nullable<T>, 1.39 + private JS::CustomAutoRooter 1.40 +{ 1.41 +public: 1.42 + NullableRootedDictionary(JSContext* cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM) : 1.43 + Nullable<T>(), 1.44 + JS::CustomAutoRooter(cx MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) 1.45 + { 1.46 + } 1.47 + 1.48 + virtual void trace(JSTracer *trc) MOZ_OVERRIDE 1.49 + { 1.50 + if (!this->IsNull()) { 1.51 + this->Value().TraceDictionary(trc); 1.52 + } 1.53 + } 1.54 +}; 1.55 + 1.56 +} // namespace dom 1.57 +} // namespace mozilla 1.58 + 1.59 +#endif /* mozilla_dom_RootedDictionary_h__ */