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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef js_Vector_h |
michael@0 | 8 | #define js_Vector_h |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/Vector.h" |
michael@0 | 11 | |
michael@0 | 12 | /* Silence dire "bugs in previous versions of MSVC have been fixed" warnings */ |
michael@0 | 13 | #ifdef _MSC_VER |
michael@0 | 14 | #pragma warning(push) |
michael@0 | 15 | #pragma warning(disable:4345) |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | namespace js { |
michael@0 | 19 | |
michael@0 | 20 | class TempAllocPolicy; |
michael@0 | 21 | |
michael@0 | 22 | // If we had C++11 template aliases, we could just use this: |
michael@0 | 23 | // |
michael@0 | 24 | // template <typename T, |
michael@0 | 25 | // size_t MinInlineCapacity = 0, |
michael@0 | 26 | // class AllocPolicy = TempAllocPolicy> |
michael@0 | 27 | // using Vector = mozilla::Vector<T, MinInlineCapacity, AllocPolicy>; |
michael@0 | 28 | // |
michael@0 | 29 | // ...and get rid of all the CRTP madness in mozilla::Vector(Base). But we |
michael@0 | 30 | // can't because compiler support's not up to snuff. (Template aliases are in |
michael@0 | 31 | // gcc 4.7 and clang 3.0 and are expected to be in MSVC 2013.) Instead, have a |
michael@0 | 32 | // completely separate class inheriting from mozilla::Vector, and throw CRTP at |
michael@0 | 33 | // the problem til things work. |
michael@0 | 34 | // |
michael@0 | 35 | // This workaround presents a couple issues. First, because js::Vector is a |
michael@0 | 36 | // distinct type from mozilla::Vector, overload resolution, method calls, etc. |
michael@0 | 37 | // are affected. *Hopefully* this won't be too bad in practice. (A bunch of |
michael@0 | 38 | // places had to be fixed when mozilla::Vector was introduced, but it wasn't a |
michael@0 | 39 | // crazy number.) Second, mozilla::Vector's interface has to be made subclass- |
michael@0 | 40 | // ready via CRTP -- or rather, via mozilla::VectorBase, which basically no one |
michael@0 | 41 | // should use. :-) Third, we have to redefine the constructors and the non- |
michael@0 | 42 | // inherited operators. Blech. Happily there aren't too many of these, so it |
michael@0 | 43 | // isn't the end of the world. |
michael@0 | 44 | |
michael@0 | 45 | template <typename T, |
michael@0 | 46 | size_t MinInlineCapacity = 0, |
michael@0 | 47 | class AllocPolicy = TempAllocPolicy> |
michael@0 | 48 | class Vector |
michael@0 | 49 | : public mozilla::VectorBase<T, |
michael@0 | 50 | MinInlineCapacity, |
michael@0 | 51 | AllocPolicy, |
michael@0 | 52 | Vector<T, MinInlineCapacity, AllocPolicy> > |
michael@0 | 53 | { |
michael@0 | 54 | typedef typename mozilla::VectorBase<T, MinInlineCapacity, AllocPolicy, Vector> Base; |
michael@0 | 55 | |
michael@0 | 56 | public: |
michael@0 | 57 | Vector(AllocPolicy alloc = AllocPolicy()) : Base(alloc) {} |
michael@0 | 58 | Vector(Vector &&vec) : Base(mozilla::Move(vec)) {} |
michael@0 | 59 | Vector &operator=(Vector &&vec) { |
michael@0 | 60 | return Base::operator=(mozilla::Move(vec)); |
michael@0 | 61 | } |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | } // namespace js |
michael@0 | 65 | |
michael@0 | 66 | #endif /* js_Vector_h */ |