js/src/jshashutil.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.

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 jshashutil_h
michael@0 8 #define jshashutil_h
michael@0 9
michael@0 10 #include "jscntxt.h"
michael@0 11
michael@0 12 namespace js {
michael@0 13
michael@0 14 /*
michael@0 15 * Used to add entries to a js::HashMap or HashSet where the key depends on a GC
michael@0 16 * thing that may be moved by generational collection between the call to
michael@0 17 * lookupForAdd() and relookupOrAdd().
michael@0 18 */
michael@0 19 template <class T>
michael@0 20 struct DependentAddPtr
michael@0 21 {
michael@0 22 typedef typename T::AddPtr AddPtr;
michael@0 23 typedef typename T::Entry Entry;
michael@0 24
michael@0 25 template <class Lookup>
michael@0 26 DependentAddPtr(const ExclusiveContext *cx, const T &table, const Lookup &lookup)
michael@0 27 : addPtr(table.lookupForAdd(lookup))
michael@0 28 #ifdef JSGC_GENERATIONAL
michael@0 29 , originalGcNumber(cx->zone()->gcNumber())
michael@0 30 #endif
michael@0 31 {}
michael@0 32
michael@0 33 template <class KeyInput, class ValueInput>
michael@0 34 bool add(const ExclusiveContext *cx, T &table, const KeyInput &key, const ValueInput &value) {
michael@0 35 #ifdef JSGC_GENERATIONAL
michael@0 36 bool gcHappened = originalGcNumber != cx->zone()->gcNumber();
michael@0 37 if (gcHappened)
michael@0 38 addPtr = table.lookupForAdd(key);
michael@0 39 #endif
michael@0 40 return table.relookupOrAdd(addPtr, key, value);
michael@0 41 }
michael@0 42
michael@0 43 typedef void (DependentAddPtr::* ConvertibleToBool)();
michael@0 44 void nonNull() {}
michael@0 45
michael@0 46 bool found() const { return addPtr.found(); }
michael@0 47 operator ConvertibleToBool() const { return found() ? &DependentAddPtr::nonNull : 0; }
michael@0 48 const Entry &operator*() const { return *addPtr; }
michael@0 49 const Entry *operator->() const { return &*addPtr; }
michael@0 50
michael@0 51 private:
michael@0 52 AddPtr addPtr ;
michael@0 53 #ifdef JSGC_GENERATIONAL
michael@0 54 const uint64_t originalGcNumber;
michael@0 55 #endif
michael@0 56
michael@0 57 DependentAddPtr() MOZ_DELETE;
michael@0 58 DependentAddPtr(const DependentAddPtr&) MOZ_DELETE;
michael@0 59 DependentAddPtr& operator=(const DependentAddPtr&) MOZ_DELETE;
michael@0 60 };
michael@0 61
michael@0 62 } // namespace js
michael@0 63
michael@0 64 #endif

mercurial