js/src/vm/SharedArrayObject.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 vm_SharedArrayObject_h
michael@0 8 #define vm_SharedArrayObject_h
michael@0 9
michael@0 10 #include "mozilla/Atomics.h"
michael@0 11
michael@0 12 #include "jsapi.h"
michael@0 13 #include "jsobj.h"
michael@0 14 #include "jstypes.h"
michael@0 15
michael@0 16 #include "gc/Barrier.h"
michael@0 17 #include "vm/ArrayBufferObject.h"
michael@0 18
michael@0 19 typedef struct JSProperty JSProperty;
michael@0 20
michael@0 21 namespace js {
michael@0 22
michael@0 23 /*
michael@0 24 * SharedArrayRawBuffer
michael@0 25 *
michael@0 26 * A bookkeeping object always stored immediately before the raw buffer.
michael@0 27 * The buffer itself is mmap()'d and refcounted.
michael@0 28 * SharedArrayBufferObjects and AsmJS code may hold references.
michael@0 29 *
michael@0 30 * |<------ sizeof ------>|<- length ->|
michael@0 31 *
michael@0 32 * | waste | SharedArrayRawBuffer | data array | waste |
michael@0 33 */
michael@0 34 class SharedArrayRawBuffer
michael@0 35 {
michael@0 36 private:
michael@0 37 mozilla::Atomic<uint32_t, mozilla::ReleaseAcquire> refcount;
michael@0 38 uint32_t length;
michael@0 39
michael@0 40 protected:
michael@0 41 SharedArrayRawBuffer(uint8_t *buffer, uint32_t length)
michael@0 42 : refcount(1), length(length)
michael@0 43 {
michael@0 44 JS_ASSERT(buffer == dataPointer());
michael@0 45 }
michael@0 46
michael@0 47 public:
michael@0 48 static SharedArrayRawBuffer *New(uint32_t length);
michael@0 49
michael@0 50 inline uint8_t *dataPointer() const {
michael@0 51 return ((uint8_t *)this) + sizeof(SharedArrayRawBuffer);
michael@0 52 }
michael@0 53
michael@0 54 inline uint32_t byteLength() const {
michael@0 55 return length;
michael@0 56 }
michael@0 57
michael@0 58 void addReference();
michael@0 59 void dropReference();
michael@0 60 };
michael@0 61
michael@0 62 /*
michael@0 63 * SharedArrayBufferObject
michael@0 64 *
michael@0 65 * When transferred to a WebWorker, the buffer is not neutered on the parent side,
michael@0 66 * and both child and parent reference the same buffer.
michael@0 67 */
michael@0 68 class SharedArrayBufferObject : public ArrayBufferObject
michael@0 69 {
michael@0 70 static bool byteLengthGetterImpl(JSContext *cx, CallArgs args);
michael@0 71
michael@0 72 public:
michael@0 73 static const Class class_;
michael@0 74 static const Class protoClass;
michael@0 75
michael@0 76 // Slot used for storing a pointer to the SharedArrayRawBuffer.
michael@0 77 static const uint8_t RAWBUF_SLOT = ArrayBufferObject::RESERVED_SLOTS;
michael@0 78
michael@0 79 static const uint8_t RESERVED_SLOTS = ArrayBufferObject::RESERVED_SLOTS + 1;
michael@0 80
michael@0 81 static bool class_constructor(JSContext *cx, unsigned argc, Value *vp);
michael@0 82
michael@0 83 // Create a SharedArrayBufferObject with a new SharedArrayRawBuffer.
michael@0 84 static JSObject *New(JSContext *cx, uint32_t length);
michael@0 85
michael@0 86 // Create a SharedArrayBufferObject using an existing SharedArrayRawBuffer.
michael@0 87 static JSObject *New(JSContext *cx, SharedArrayRawBuffer *buffer);
michael@0 88
michael@0 89 static bool byteLengthGetter(JSContext *cx, unsigned argc, Value *vp);
michael@0 90
michael@0 91 static void Finalize(FreeOp *fop, JSObject *obj);
michael@0 92
michael@0 93 void acceptRawBuffer(SharedArrayRawBuffer *buffer);
michael@0 94 void dropRawBuffer();
michael@0 95
michael@0 96 SharedArrayRawBuffer *rawBufferObject() const;
michael@0 97 uint8_t *dataPointer() const;
michael@0 98 uint32_t byteLength() const;
michael@0 99 };
michael@0 100
michael@0 101 bool
michael@0 102 IsSharedArrayBuffer(HandleValue v);
michael@0 103
michael@0 104 } // namespace js
michael@0 105
michael@0 106 #endif // vm_SharedArrayObject_h

mercurial