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 | #ifndef jsiter_h |
michael@0 | 8 | #define jsiter_h |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | * JavaScript iterators. |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | #include "mozilla/MemoryReporting.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "jscntxt.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "gc/Barrier.h" |
michael@0 | 19 | #include "vm/Stack.h" |
michael@0 | 20 | |
michael@0 | 21 | /* |
michael@0 | 22 | * For cacheable native iterators, whether the iterator is currently active. |
michael@0 | 23 | * Not serialized by XDR. |
michael@0 | 24 | */ |
michael@0 | 25 | #define JSITER_ACTIVE 0x1000 |
michael@0 | 26 | #define JSITER_UNREUSABLE 0x2000 |
michael@0 | 27 | |
michael@0 | 28 | namespace js { |
michael@0 | 29 | |
michael@0 | 30 | struct NativeIterator |
michael@0 | 31 | { |
michael@0 | 32 | HeapPtrObject obj; // Object being iterated. |
michael@0 | 33 | JSObject *iterObj_; // Internal iterator object. |
michael@0 | 34 | HeapPtr<JSFlatString> *props_array; |
michael@0 | 35 | HeapPtr<JSFlatString> *props_cursor; |
michael@0 | 36 | HeapPtr<JSFlatString> *props_end; |
michael@0 | 37 | Shape **shapes_array; |
michael@0 | 38 | uint32_t shapes_length; |
michael@0 | 39 | uint32_t shapes_key; |
michael@0 | 40 | uint32_t flags; |
michael@0 | 41 | |
michael@0 | 42 | private: |
michael@0 | 43 | /* While in compartment->enumerators, these form a doubly linked list. */ |
michael@0 | 44 | NativeIterator *next_; |
michael@0 | 45 | NativeIterator *prev_; |
michael@0 | 46 | |
michael@0 | 47 | public: |
michael@0 | 48 | bool isKeyIter() const { |
michael@0 | 49 | return (flags & JSITER_FOREACH) == 0; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | inline HeapPtr<JSFlatString> *begin() const { |
michael@0 | 53 | return props_array; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | inline HeapPtr<JSFlatString> *end() const { |
michael@0 | 57 | return props_end; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | size_t numKeys() const { |
michael@0 | 61 | return end() - begin(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | JSObject *iterObj() const { |
michael@0 | 65 | return iterObj_; |
michael@0 | 66 | } |
michael@0 | 67 | HeapPtr<JSFlatString> *current() const { |
michael@0 | 68 | JS_ASSERT(props_cursor < props_end); |
michael@0 | 69 | return props_cursor; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | NativeIterator *next() { |
michael@0 | 73 | return next_; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | static inline size_t offsetOfNext() { |
michael@0 | 77 | return offsetof(NativeIterator, next_); |
michael@0 | 78 | } |
michael@0 | 79 | static inline size_t offsetOfPrev() { |
michael@0 | 80 | return offsetof(NativeIterator, prev_); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | void incCursor() { |
michael@0 | 84 | props_cursor = props_cursor + 1; |
michael@0 | 85 | } |
michael@0 | 86 | void link(NativeIterator *other) { |
michael@0 | 87 | /* A NativeIterator cannot appear in the enumerator list twice. */ |
michael@0 | 88 | JS_ASSERT(!next_ && !prev_); |
michael@0 | 89 | JS_ASSERT(flags & JSITER_ENUMERATE); |
michael@0 | 90 | |
michael@0 | 91 | this->next_ = other; |
michael@0 | 92 | this->prev_ = other->prev_; |
michael@0 | 93 | other->prev_->next_ = this; |
michael@0 | 94 | other->prev_ = this; |
michael@0 | 95 | } |
michael@0 | 96 | void unlink() { |
michael@0 | 97 | JS_ASSERT(flags & JSITER_ENUMERATE); |
michael@0 | 98 | |
michael@0 | 99 | next_->prev_ = prev_; |
michael@0 | 100 | prev_->next_ = next_; |
michael@0 | 101 | next_ = nullptr; |
michael@0 | 102 | prev_ = nullptr; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | static NativeIterator *allocateSentinel(JSContext *cx); |
michael@0 | 106 | static NativeIterator *allocateIterator(JSContext *cx, uint32_t slength, |
michael@0 | 107 | const js::AutoIdVector &props); |
michael@0 | 108 | void init(JSObject *obj, JSObject *iterObj, unsigned flags, uint32_t slength, uint32_t key); |
michael@0 | 109 | |
michael@0 | 110 | void mark(JSTracer *trc); |
michael@0 | 111 | |
michael@0 | 112 | static void destroy(NativeIterator *iter) { |
michael@0 | 113 | js_free(iter); |
michael@0 | 114 | } |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | class PropertyIteratorObject : public JSObject |
michael@0 | 118 | { |
michael@0 | 119 | public: |
michael@0 | 120 | static const Class class_; |
michael@0 | 121 | |
michael@0 | 122 | NativeIterator *getNativeIterator() const { |
michael@0 | 123 | return static_cast<js::NativeIterator *>(getPrivate()); |
michael@0 | 124 | } |
michael@0 | 125 | void setNativeIterator(js::NativeIterator *ni) { |
michael@0 | 126 | setPrivate(ni); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | size_t sizeOfMisc(mozilla::MallocSizeOf mallocSizeOf) const; |
michael@0 | 130 | |
michael@0 | 131 | private: |
michael@0 | 132 | static void trace(JSTracer *trc, JSObject *obj); |
michael@0 | 133 | static void finalize(FreeOp *fop, JSObject *obj); |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | class ArrayIteratorObject : public JSObject |
michael@0 | 137 | { |
michael@0 | 138 | public: |
michael@0 | 139 | static const Class class_; |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | class StringIteratorObject : public JSObject |
michael@0 | 143 | { |
michael@0 | 144 | public: |
michael@0 | 145 | static const Class class_; |
michael@0 | 146 | }; |
michael@0 | 147 | |
michael@0 | 148 | bool |
michael@0 | 149 | VectorToIdArray(JSContext *cx, AutoIdVector &props, JSIdArray **idap); |
michael@0 | 150 | |
michael@0 | 151 | bool |
michael@0 | 152 | GetIterator(JSContext *cx, HandleObject obj, unsigned flags, MutableHandleValue vp); |
michael@0 | 153 | |
michael@0 | 154 | JSObject * |
michael@0 | 155 | GetIteratorObject(JSContext *cx, HandleObject obj, unsigned flags); |
michael@0 | 156 | |
michael@0 | 157 | bool |
michael@0 | 158 | VectorToKeyIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props, |
michael@0 | 159 | MutableHandleValue vp); |
michael@0 | 160 | |
michael@0 | 161 | bool |
michael@0 | 162 | VectorToValueIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props, |
michael@0 | 163 | MutableHandleValue vp); |
michael@0 | 164 | |
michael@0 | 165 | /* |
michael@0 | 166 | * Creates either a key or value iterator, depending on flags. For a value |
michael@0 | 167 | * iterator, performs value-lookup to convert the given list of jsids. |
michael@0 | 168 | */ |
michael@0 | 169 | bool |
michael@0 | 170 | EnumeratedIdVectorToIterator(JSContext *cx, HandleObject obj, unsigned flags, AutoIdVector &props, |
michael@0 | 171 | MutableHandleValue vp); |
michael@0 | 172 | |
michael@0 | 173 | /* |
michael@0 | 174 | * Convert the value stored in *vp to its iteration object. The flags should |
michael@0 | 175 | * contain JSITER_ENUMERATE if js::ValueToIterator is called when enumerating |
michael@0 | 176 | * for-in semantics are required, and when the caller can guarantee that the |
michael@0 | 177 | * iterator will never be exposed to scripts. |
michael@0 | 178 | */ |
michael@0 | 179 | bool |
michael@0 | 180 | ValueToIterator(JSContext *cx, unsigned flags, MutableHandleValue vp); |
michael@0 | 181 | |
michael@0 | 182 | bool |
michael@0 | 183 | CloseIterator(JSContext *cx, HandleObject iterObj); |
michael@0 | 184 | |
michael@0 | 185 | bool |
michael@0 | 186 | UnwindIteratorForException(JSContext *cx, js::HandleObject obj); |
michael@0 | 187 | |
michael@0 | 188 | void |
michael@0 | 189 | UnwindIteratorForUncatchableException(JSContext *cx, JSObject *obj); |
michael@0 | 190 | |
michael@0 | 191 | bool |
michael@0 | 192 | IteratorConstructor(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 193 | |
michael@0 | 194 | } /* namespace js */ |
michael@0 | 195 | |
michael@0 | 196 | extern bool |
michael@0 | 197 | js_SuppressDeletedProperty(JSContext *cx, js::HandleObject obj, jsid id); |
michael@0 | 198 | |
michael@0 | 199 | extern bool |
michael@0 | 200 | js_SuppressDeletedElement(JSContext *cx, js::HandleObject obj, uint32_t index); |
michael@0 | 201 | |
michael@0 | 202 | extern bool |
michael@0 | 203 | js_SuppressDeletedElements(JSContext *cx, js::HandleObject obj, uint32_t begin, uint32_t end); |
michael@0 | 204 | |
michael@0 | 205 | /* |
michael@0 | 206 | * IteratorMore() indicates whether another value is available. It might |
michael@0 | 207 | * internally call iterobj.next() and then cache the value until its |
michael@0 | 208 | * picked up by IteratorNext(). The value is cached in the current context. |
michael@0 | 209 | */ |
michael@0 | 210 | extern bool |
michael@0 | 211 | js_IteratorMore(JSContext *cx, js::HandleObject iterobj, js::MutableHandleValue rval); |
michael@0 | 212 | |
michael@0 | 213 | extern bool |
michael@0 | 214 | js_IteratorNext(JSContext *cx, js::HandleObject iterobj, js::MutableHandleValue rval); |
michael@0 | 215 | |
michael@0 | 216 | extern bool |
michael@0 | 217 | js_ThrowStopIteration(JSContext *cx); |
michael@0 | 218 | |
michael@0 | 219 | namespace js { |
michael@0 | 220 | |
michael@0 | 221 | /* |
michael@0 | 222 | * Create an object of the form { value: VALUE, done: DONE }. |
michael@0 | 223 | * ES6 draft from 2013-09-05, section 25.4.3.4. |
michael@0 | 224 | */ |
michael@0 | 225 | extern JSObject * |
michael@0 | 226 | CreateItrResultObject(JSContext *cx, js::HandleValue value, bool done); |
michael@0 | 227 | |
michael@0 | 228 | } /* namespace js */ |
michael@0 | 229 | |
michael@0 | 230 | /* |
michael@0 | 231 | * Generator state codes. |
michael@0 | 232 | */ |
michael@0 | 233 | enum JSGeneratorState |
michael@0 | 234 | { |
michael@0 | 235 | JSGEN_NEWBORN, /* not yet started */ |
michael@0 | 236 | JSGEN_OPEN, /* started by a .next() or .send(undefined) call */ |
michael@0 | 237 | JSGEN_RUNNING, /* currently executing via .next(), etc., call */ |
michael@0 | 238 | JSGEN_CLOSING, /* close method is doing asynchronous return */ |
michael@0 | 239 | JSGEN_CLOSED /* closed, cannot be started or closed again */ |
michael@0 | 240 | }; |
michael@0 | 241 | |
michael@0 | 242 | struct JSGenerator |
michael@0 | 243 | { |
michael@0 | 244 | js::HeapPtrObject obj; |
michael@0 | 245 | JSGeneratorState state; |
michael@0 | 246 | js::InterpreterRegs regs; |
michael@0 | 247 | JSGenerator *prevGenerator; |
michael@0 | 248 | js::InterpreterFrame *fp; |
michael@0 | 249 | js::HeapValue stackSnapshot[1]; |
michael@0 | 250 | }; |
michael@0 | 251 | |
michael@0 | 252 | extern JSObject * |
michael@0 | 253 | js_NewGenerator(JSContext *cx, const js::InterpreterRegs ®s); |
michael@0 | 254 | |
michael@0 | 255 | extern JSObject * |
michael@0 | 256 | js_InitIteratorClasses(JSContext *cx, js::HandleObject obj); |
michael@0 | 257 | |
michael@0 | 258 | #endif /* jsiter_h */ |