tools/profiler/JSStreamWriter.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: 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 JSSTREAMWRITER_H
     7 #define JSSTREAMWRITER_H
     9 #include <ostream>
    10 #include <stdlib.h>
    11 #include "nsDeque.h"
    13 class JSStreamWriter
    14 {
    15 public:
    16   JSStreamWriter(std::ostream& aStream);
    17   ~JSStreamWriter();
    19   void BeginObject();
    20   void EndObject();
    21   void BeginArray();
    22   void EndArray();
    23   void Name(const char *name);
    24   void Value(int value);
    25   void Value(double value);
    26   void Value(const char *value, size_t valueLength);
    27   void Value(const char *value);
    28   template <typename T>
    29   void NameValue(const char *aName, T aValue)
    30   {
    31     Name(aName);
    32     Value(aValue);
    33   }
    35 private:
    36   std::ostream& mStream;
    37   bool mNeedsComma;
    38   bool mNeedsName;
    40   nsDeque mStack;
    42   // This class can't be copied
    43   JSStreamWriter(const JSStreamWriter&);
    44   JSStreamWriter& operator=(const JSStreamWriter&);
    46   void* operator new(size_t);
    47   void* operator new[](size_t);
    48   void operator delete(void*) {
    49     // Since JSStreamWriter has a virtual destructor the compiler
    50     // has to provide a destructor in the object file that will call
    51     // operate delete in case there is a derived class since its
    52     // destructor won't know how to free this instance.
    53     abort();
    54   }
    55   void operator delete[](void*);
    56 };
    58 #endif

mercurial