js/src/jsalloc.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 /*
     8  * JS allocation policies.
     9  *
    10  * The allocators here are for system memory with lifetimes which are not
    11  * managed by the GC. See the comment at the top of vm/MallocProvider.h.
    12  */
    14 #ifndef jsalloc_h
    15 #define jsalloc_h
    17 #include "js/TypeDecls.h"
    18 #include "js/Utility.h"
    20 namespace js {
    22 class ContextFriendFields;
    24 /* Policy for using system memory functions and doing no error reporting. */
    25 class SystemAllocPolicy
    26 {
    27   public:
    28     void *malloc_(size_t bytes) { return js_malloc(bytes); }
    29     void *calloc_(size_t bytes) { return js_calloc(bytes); }
    30     void *realloc_(void *p, size_t oldBytes, size_t bytes) { return js_realloc(p, bytes); }
    31     void free_(void *p) { js_free(p); }
    32     void reportAllocOverflow() const {}
    33 };
    35 /*
    36  * Allocation policy that calls the system memory functions and reports errors
    37  * to the context. Since the JSContext given on construction is stored for
    38  * the lifetime of the container, this policy may only be used for containers
    39  * whose lifetime is a shorter than the given JSContext.
    40  *
    41  * FIXME bug 647103 - rewrite this in terms of temporary allocation functions,
    42  * not the system ones.
    43  */
    44 class TempAllocPolicy
    45 {
    46     ContextFriendFields *const cx_;
    48     /*
    49      * Non-inline helper to call JSRuntime::onOutOfMemory with minimal
    50      * code bloat.
    51      */
    52     JS_FRIEND_API(void *) onOutOfMemory(void *p, size_t nbytes);
    54   public:
    55     TempAllocPolicy(JSContext *cx) : cx_((ContextFriendFields *) cx) {} // :(
    56     TempAllocPolicy(ContextFriendFields *cx) : cx_(cx) {}
    58     void *malloc_(size_t bytes) {
    59         void *p = js_malloc(bytes);
    60         if (MOZ_UNLIKELY(!p))
    61             p = onOutOfMemory(nullptr, bytes);
    62         return p;
    63     }
    65     void *calloc_(size_t bytes) {
    66         void *p = js_calloc(bytes);
    67         if (MOZ_UNLIKELY(!p))
    68             p = onOutOfMemory(nullptr, bytes);
    69         return p;
    70     }
    72     void *realloc_(void *p, size_t oldBytes, size_t bytes) {
    73         void *p2 = js_realloc(p, bytes);
    74         if (MOZ_UNLIKELY(!p2))
    75             p2 = onOutOfMemory(p2, bytes);
    76         return p2;
    77     }
    79     void free_(void *p) {
    80         js_free(p);
    81     }
    83     JS_FRIEND_API(void) reportAllocOverflow() const;
    84 };
    86 } /* namespace js */
    88 #endif /* jsalloc_h */

mercurial