js/public/WeakMapPtr.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     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
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef js_WeakMapPtr_h
     8 #define js_WeakMapPtr_h
    10 #include "jspubtd.h"
    12 #include "js/TypeDecls.h"
    14 namespace JS {
    16 // A wrapper around the internal C++ representation of SpiderMonkey WeakMaps,
    17 // usable outside the engine.
    18 //
    19 // The supported template specializations are enumerated in WeakMapPtr.cpp. If
    20 // you want to use this class for a different key/value combination, add it to
    21 // the list and the compiler will generate the relevant machinery.
    22 template <typename K, typename V>
    23 class JS_PUBLIC_API(WeakMapPtr)
    24 {
    25   public:
    26     WeakMapPtr() : ptr(nullptr) {};
    27     bool init(JSContext *cx);
    28     bool initialized() { return ptr != nullptr; };
    29     void destroy();
    30     virtual ~WeakMapPtr() { MOZ_ASSERT(!initialized()); }
    31     void trace(JSTracer *tracer);
    33     V lookup(const K &key);
    34     bool put(JSContext *cx, const K &key, const V &value);
    36     static void keyMarkCallback(JSTracer *trc, K key, void *data);
    38   private:
    39     void *ptr;
    41     // WeakMapPtr is neither copyable nor assignable.
    42     WeakMapPtr(const WeakMapPtr &wmp) MOZ_DELETE;
    43     WeakMapPtr &operator=(const WeakMapPtr &wmp) MOZ_DELETE;
    44 };
    46 } /* namespace JS */
    48 #endif  /* js_WeakMapPtr_h */

mercurial