js/src/jspropertytree.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 jspropertytree_h
michael@0 8 #define jspropertytree_h
michael@0 9
michael@0 10 #include "jsalloc.h"
michael@0 11 #include "jspubtd.h"
michael@0 12
michael@0 13 #include "js/HashTable.h"
michael@0 14
michael@0 15 namespace js {
michael@0 16
michael@0 17 class Shape;
michael@0 18 struct StackShape;
michael@0 19
michael@0 20 struct ShapeHasher {
michael@0 21 typedef Shape *Key;
michael@0 22 typedef StackShape Lookup;
michael@0 23
michael@0 24 static inline HashNumber hash(const Lookup &l);
michael@0 25 static inline bool match(Key k, const Lookup &l);
michael@0 26 };
michael@0 27
michael@0 28 typedef HashSet<Shape *, ShapeHasher, SystemAllocPolicy> KidsHash;
michael@0 29
michael@0 30 class KidsPointer {
michael@0 31 private:
michael@0 32 enum {
michael@0 33 SHAPE = 0,
michael@0 34 HASH = 1,
michael@0 35 TAG = 1
michael@0 36 };
michael@0 37
michael@0 38 uintptr_t w;
michael@0 39
michael@0 40 public:
michael@0 41 bool isNull() const { return !w; }
michael@0 42 void setNull() { w = 0; }
michael@0 43
michael@0 44 bool isShape() const { return (w & TAG) == SHAPE && !isNull(); }
michael@0 45 Shape *toShape() const {
michael@0 46 JS_ASSERT(isShape());
michael@0 47 return reinterpret_cast<Shape *>(w & ~uintptr_t(TAG));
michael@0 48 }
michael@0 49 void setShape(Shape *shape) {
michael@0 50 JS_ASSERT(shape);
michael@0 51 JS_ASSERT((reinterpret_cast<uintptr_t>(static_cast<Shape *>(shape)) & TAG) == 0);
michael@0 52 w = reinterpret_cast<uintptr_t>(static_cast<Shape *>(shape)) | SHAPE;
michael@0 53 }
michael@0 54
michael@0 55 bool isHash() const { return (w & TAG) == HASH; }
michael@0 56 KidsHash *toHash() const {
michael@0 57 JS_ASSERT(isHash());
michael@0 58 return reinterpret_cast<KidsHash *>(w & ~uintptr_t(TAG));
michael@0 59 }
michael@0 60 void setHash(KidsHash *hash) {
michael@0 61 JS_ASSERT(hash);
michael@0 62 JS_ASSERT((reinterpret_cast<uintptr_t>(hash) & TAG) == 0);
michael@0 63 w = reinterpret_cast<uintptr_t>(hash) | HASH;
michael@0 64 }
michael@0 65
michael@0 66 #ifdef DEBUG
michael@0 67 void checkConsistency(Shape *aKid) const;
michael@0 68 #endif
michael@0 69 };
michael@0 70
michael@0 71 class PropertyTree
michael@0 72 {
michael@0 73 friend class ::JSFunction;
michael@0 74
michael@0 75 JSCompartment *compartment_;
michael@0 76
michael@0 77 bool insertChild(ExclusiveContext *cx, Shape *parent, Shape *child);
michael@0 78
michael@0 79 PropertyTree();
michael@0 80
michael@0 81 public:
michael@0 82 /*
michael@0 83 * Use a lower limit for objects that are accessed using SETELEM (o[x] = y).
michael@0 84 * These objects are likely used as hashmaps and dictionary mode is more
michael@0 85 * efficient in this case.
michael@0 86 */
michael@0 87 enum {
michael@0 88 MAX_HEIGHT = 512,
michael@0 89 MAX_HEIGHT_WITH_ELEMENTS_ACCESS = 128
michael@0 90 };
michael@0 91
michael@0 92 PropertyTree(JSCompartment *comp)
michael@0 93 : compartment_(comp)
michael@0 94 {
michael@0 95 }
michael@0 96
michael@0 97 JSCompartment *compartment() { return compartment_; }
michael@0 98
michael@0 99 Shape *newShape(ExclusiveContext *cx);
michael@0 100 Shape *getChild(ExclusiveContext *cx, Shape *parent, StackShape &child);
michael@0 101 Shape *lookupChild(ThreadSafeContext *cx, Shape *parent, const StackShape &child);
michael@0 102 };
michael@0 103
michael@0 104 } /* namespace js */
michael@0 105
michael@0 106 #endif /* jspropertytree_h */

mercurial