Sat, 03 Jan 2015 20:18:00 +0100
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 | #include "frontend/ParseMaps-inl.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "jscntxt.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "frontend/FullParseHandler.h" |
michael@0 | 12 | #include "frontend/SyntaxParseHandler.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace js; |
michael@0 | 15 | using namespace js::frontend; |
michael@0 | 16 | |
michael@0 | 17 | void |
michael@0 | 18 | ParseMapPool::checkInvariants() |
michael@0 | 19 | { |
michael@0 | 20 | /* |
michael@0 | 21 | * Having all values be of the same size permits us to easily reuse the |
michael@0 | 22 | * allocated space for each of the map types. |
michael@0 | 23 | */ |
michael@0 | 24 | JS_STATIC_ASSERT(sizeof(Definition *) == sizeof(jsatomid)); |
michael@0 | 25 | JS_STATIC_ASSERT(sizeof(Definition *) == sizeof(DefinitionList)); |
michael@0 | 26 | JS_STATIC_ASSERT(sizeof(AtomDefnMap::Entry) == sizeof(AtomIndexMap::Entry)); |
michael@0 | 27 | JS_STATIC_ASSERT(sizeof(AtomDefnMap::Entry) == sizeof(AtomDefnListMap::Entry)); |
michael@0 | 28 | JS_STATIC_ASSERT(sizeof(AtomMapT::Entry) == sizeof(AtomDefnListMap::Entry)); |
michael@0 | 29 | /* Ensure that the HasTable::clear goes quickly via memset. */ |
michael@0 | 30 | JS_STATIC_ASSERT(mozilla::IsPod<AtomIndexMap::WordMap::Entry>::value); |
michael@0 | 31 | JS_STATIC_ASSERT(mozilla::IsPod<AtomDefnListMap::WordMap::Entry>::value); |
michael@0 | 32 | JS_STATIC_ASSERT(mozilla::IsPod<AtomDefnMap::WordMap::Entry>::value); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | void |
michael@0 | 36 | ParseMapPool::purgeAll() |
michael@0 | 37 | { |
michael@0 | 38 | for (void **it = all.begin(), **end = all.end(); it != end; ++it) |
michael@0 | 39 | js_delete<AtomMapT>(asAtomMap(*it)); |
michael@0 | 40 | |
michael@0 | 41 | all.clearAndFree(); |
michael@0 | 42 | recyclable.clearAndFree(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void * |
michael@0 | 46 | ParseMapPool::allocateFresh() |
michael@0 | 47 | { |
michael@0 | 48 | size_t newAllLength = all.length() + 1; |
michael@0 | 49 | if (!all.reserve(newAllLength) || !recyclable.reserve(newAllLength)) |
michael@0 | 50 | return nullptr; |
michael@0 | 51 | |
michael@0 | 52 | AtomMapT *map = js_new<AtomMapT>(); |
michael@0 | 53 | if (!map) |
michael@0 | 54 | return nullptr; |
michael@0 | 55 | |
michael@0 | 56 | all.infallibleAppend(map); |
michael@0 | 57 | return (void *) map; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | DefinitionList::Node * |
michael@0 | 61 | DefinitionList::allocNode(ExclusiveContext *cx, LifoAlloc &alloc, uintptr_t head, Node *tail) |
michael@0 | 62 | { |
michael@0 | 63 | Node *result = alloc.new_<Node>(head, tail); |
michael@0 | 64 | if (!result) |
michael@0 | 65 | js_ReportOutOfMemory(cx); |
michael@0 | 66 | return result; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | #ifdef DEBUG |
michael@0 | 70 | template <typename ParseHandler> |
michael@0 | 71 | void |
michael@0 | 72 | AtomDecls<ParseHandler>::dump() |
michael@0 | 73 | { |
michael@0 | 74 | for (AtomDefnListRange r = map->all(); !r.empty(); r.popFront()) { |
michael@0 | 75 | fprintf(stderr, "atom: "); |
michael@0 | 76 | js_DumpAtom(r.front().key()); |
michael@0 | 77 | const DefinitionList &dlist = r.front().value(); |
michael@0 | 78 | for (DefinitionList::Range dr = dlist.all(); !dr.empty(); dr.popFront()) { |
michael@0 | 79 | fprintf(stderr, " defn: %p\n", (void *) dr.front<ParseHandler>()); |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | void |
michael@0 | 85 | DumpAtomDefnMap(const AtomDefnMapPtr &map) |
michael@0 | 86 | { |
michael@0 | 87 | if (map->empty()) { |
michael@0 | 88 | fprintf(stderr, "empty\n"); |
michael@0 | 89 | return; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | for (AtomDefnRange r = map->all(); !r.empty(); r.popFront()) { |
michael@0 | 93 | fprintf(stderr, "atom: "); |
michael@0 | 94 | js_DumpAtom(r.front().key()); |
michael@0 | 95 | fprintf(stderr, "defn: %p\n", (void *) r.front().value().get<FullParseHandler>()); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | #endif |
michael@0 | 99 | |
michael@0 | 100 | template <typename ParseHandler> |
michael@0 | 101 | bool |
michael@0 | 102 | AtomDecls<ParseHandler>::addShadow(JSAtom *atom, typename ParseHandler::DefinitionNode defn) |
michael@0 | 103 | { |
michael@0 | 104 | AtomDefnListAddPtr p = map->lookupForAdd(atom); |
michael@0 | 105 | if (!p) |
michael@0 | 106 | return map->add(p, atom, DefinitionList(ParseHandler::definitionToBits(defn))); |
michael@0 | 107 | |
michael@0 | 108 | return p.value().pushFront<ParseHandler>(cx, alloc, defn); |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | void |
michael@0 | 112 | frontend::InitAtomMap(frontend::AtomIndexMap *indices, HeapPtrAtom *atoms) |
michael@0 | 113 | { |
michael@0 | 114 | if (indices->isMap()) { |
michael@0 | 115 | typedef AtomIndexMap::WordMap WordMap; |
michael@0 | 116 | const WordMap &wm = indices->asMap(); |
michael@0 | 117 | for (WordMap::Range r = wm.all(); !r.empty(); r.popFront()) { |
michael@0 | 118 | JSAtom *atom = r.front().key(); |
michael@0 | 119 | jsatomid index = r.front().value(); |
michael@0 | 120 | JS_ASSERT(index < indices->count()); |
michael@0 | 121 | atoms[index].init(atom); |
michael@0 | 122 | } |
michael@0 | 123 | } else { |
michael@0 | 124 | for (const AtomIndexMap::InlineElem *it = indices->asInline(), *end = indices->inlineEnd(); |
michael@0 | 125 | it != end; ++it) { |
michael@0 | 126 | JSAtom *atom = it->key; |
michael@0 | 127 | if (!atom) |
michael@0 | 128 | continue; |
michael@0 | 129 | JS_ASSERT(it->value < indices->count()); |
michael@0 | 130 | atoms[it->value].init(atom); |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | template class js::frontend::AtomDecls<FullParseHandler>; |
michael@0 | 136 | template class js::frontend::AtomDecls<SyntaxParseHandler>; |