Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef vm_SharedArrayObject_h
8 #define vm_SharedArrayObject_h
10 #include "mozilla/Atomics.h"
12 #include "jsapi.h"
13 #include "jsobj.h"
14 #include "jstypes.h"
16 #include "gc/Barrier.h"
17 #include "vm/ArrayBufferObject.h"
19 typedef struct JSProperty JSProperty;
21 namespace js {
23 /*
24 * SharedArrayRawBuffer
25 *
26 * A bookkeeping object always stored immediately before the raw buffer.
27 * The buffer itself is mmap()'d and refcounted.
28 * SharedArrayBufferObjects and AsmJS code may hold references.
29 *
30 * |<------ sizeof ------>|<- length ->|
31 *
32 * | waste | SharedArrayRawBuffer | data array | waste |
33 */
34 class SharedArrayRawBuffer
35 {
36 private:
37 mozilla::Atomic<uint32_t, mozilla::ReleaseAcquire> refcount;
38 uint32_t length;
40 protected:
41 SharedArrayRawBuffer(uint8_t *buffer, uint32_t length)
42 : refcount(1), length(length)
43 {
44 JS_ASSERT(buffer == dataPointer());
45 }
47 public:
48 static SharedArrayRawBuffer *New(uint32_t length);
50 inline uint8_t *dataPointer() const {
51 return ((uint8_t *)this) + sizeof(SharedArrayRawBuffer);
52 }
54 inline uint32_t byteLength() const {
55 return length;
56 }
58 void addReference();
59 void dropReference();
60 };
62 /*
63 * SharedArrayBufferObject
64 *
65 * When transferred to a WebWorker, the buffer is not neutered on the parent side,
66 * and both child and parent reference the same buffer.
67 */
68 class SharedArrayBufferObject : public ArrayBufferObject
69 {
70 static bool byteLengthGetterImpl(JSContext *cx, CallArgs args);
72 public:
73 static const Class class_;
74 static const Class protoClass;
76 // Slot used for storing a pointer to the SharedArrayRawBuffer.
77 static const uint8_t RAWBUF_SLOT = ArrayBufferObject::RESERVED_SLOTS;
79 static const uint8_t RESERVED_SLOTS = ArrayBufferObject::RESERVED_SLOTS + 1;
81 static bool class_constructor(JSContext *cx, unsigned argc, Value *vp);
83 // Create a SharedArrayBufferObject with a new SharedArrayRawBuffer.
84 static JSObject *New(JSContext *cx, uint32_t length);
86 // Create a SharedArrayBufferObject using an existing SharedArrayRawBuffer.
87 static JSObject *New(JSContext *cx, SharedArrayRawBuffer *buffer);
89 static bool byteLengthGetter(JSContext *cx, unsigned argc, Value *vp);
91 static void Finalize(FreeOp *fop, JSObject *obj);
93 void acceptRawBuffer(SharedArrayRawBuffer *buffer);
94 void dropRawBuffer();
96 SharedArrayRawBuffer *rawBufferObject() const;
97 uint8_t *dataPointer() const;
98 uint32_t byteLength() const;
99 };
101 bool
102 IsSharedArrayBuffer(HandleValue v);
104 } // namespace js
106 #endif // vm_SharedArrayObject_h