Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsJSThingHashtable_h__
7 #define nsJSThingHashtable_h__
9 #include "nsHashKeys.h"
10 #include "nsBaseHashtable.h"
12 namespace JS {
13 template <class T>
14 class Heap;
15 } /* namespace JS */
17 /**
18 * A wrapper for hash keys that sets ALLOW_MEMMOVE to false.
19 *
20 * This is used in the implementation of nsJSThingHashtable and is not intended
21 * to be used directly.
22 *
23 * It is necessary for hash tables containing JS::Heap<T> values as these must
24 * be copied rather than memmoved.
25 */
26 template<class T>
27 class nsHashKeyDisallowMemmove : public T
28 {
29 public:
30 nsHashKeyDisallowMemmove(const T& key) : T(key) {}
31 enum { ALLOW_MEMMOVE = false };
32 };
35 /**
36 * Templated hashtable class for use on the heap where the values are JS GC things.
37 *
38 * Storing JS GC thing pointers on the heap requires wrapping them in a
39 * JS::Heap<T>, and this class takes care of that while presenting an interface
40 * in terms of the wrapped type T.
41 *
42 * For example, to store a hashtable mapping strings to JSObject pointers, you
43 * can declare a data member like this:
44 *
45 * nsJSThingHashtable<nsStringHashKey, JSObject*> mStringToObjectMap;
46 *
47 * See nsBaseHashtable for complete declaration
48 * @param KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h
49 * for a complete specification.
50 * @param DataType the datatype being wrapped, must be a JS GC thing.
51 * @see nsInterfaceHashtable, nsClassHashtable
52 */
53 template<class KeyClass,class DataType>
54 class nsJSThingHashtable :
55 public nsBaseHashtable<nsHashKeyDisallowMemmove<KeyClass>, JS::Heap<DataType>, DataType>
56 { };
58 #endif // nsJSThingHashtable_h__