Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: set ts=8 sts=2 et sw=2 tw=80:
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/. */
6
7
#ifndef vm_DataViewObject_h
8
#define vm_DataViewObject_h
9
10
#include "mozilla/Attributes.h"
11
12
#include "gc/Barrier.h"
13
#include "js/Class.h"
14
#include "vm/ArrayBufferObject.h"
15
#include "vm/ArrayBufferViewObject.h"
16
#include "vm/JSObject.h"
17
#include "vm/SharedArrayObject.h"
18
19
namespace js {
20
21
// In the DataViewObject, the private slot contains a raw pointer into
22
// the buffer. The buffer may be shared memory and the raw pointer
23
// should not be exposed without sharedness information accompanying
24
// it.
25
26
class DataViewObject : public ArrayBufferViewObject {
27
private:
28
static const ClassSpec classSpec_;
29
30
static JSObject* CreatePrototype(JSContext* cx, JSProtoKey key);
31
32
static bool is(HandleValue v) {
33
return v.isObject() && v.toObject().hasClass(&class_);
34
}
35
36
template <typename NativeType>
37
static SharedMem<uint8_t*> getDataPointer(JSContext* cx,
38
Handle<DataViewObject*> obj,
39
uint64_t offset,
40
bool* isSharedMemory);
41
42
static bool bufferGetterImpl(JSContext* cx, const CallArgs& args);
43
static bool bufferGetter(JSContext* cx, unsigned argc, Value* vp);
44
45
static bool byteLengthGetterImpl(JSContext* cx, const CallArgs& args);
46
static bool byteLengthGetter(JSContext* cx, unsigned argc, Value* vp);
47
48
static bool byteOffsetGetterImpl(JSContext* cx, const CallArgs& args);
49
static bool byteOffsetGetter(JSContext* cx, unsigned argc, Value* vp);
50
51
static bool getAndCheckConstructorArgs(JSContext* cx, HandleObject bufobj,
52
const CallArgs& args,
53
uint32_t* byteOffset,
54
uint32_t* byteLength);
55
static bool constructSameCompartment(JSContext* cx, HandleObject bufobj,
56
const CallArgs& args);
57
static bool constructWrapped(JSContext* cx, HandleObject bufobj,
58
const CallArgs& args);
59
60
static DataViewObject* create(
61
JSContext* cx, uint32_t byteOffset, uint32_t byteLength,
62
Handle<ArrayBufferObjectMaybeShared*> arrayBuffer, HandleObject proto);
63
64
public:
65
static const JSClass class_;
66
static const JSClass protoClass_;
67
68
static Value byteOffsetValue(const DataViewObject* view) {
69
Value v = view->getFixedSlot(BYTEOFFSET_SLOT);
70
MOZ_ASSERT(v.toInt32() >= 0);
71
return v;
72
}
73
74
static Value byteLengthValue(const DataViewObject* view) {
75
Value v = view->getFixedSlot(LENGTH_SLOT);
76
MOZ_ASSERT(v.toInt32() >= 0);
77
return v;
78
}
79
80
uint32_t byteOffset() const { return byteOffsetValue(this).toInt32(); }
81
82
uint32_t byteLength() const { return byteLengthValue(this).toInt32(); }
83
84
static bool construct(JSContext* cx, unsigned argc, Value* vp);
85
86
static bool getInt8Impl(JSContext* cx, const CallArgs& args);
87
static bool fun_getInt8(JSContext* cx, unsigned argc, Value* vp);
88
89
static bool getUint8Impl(JSContext* cx, const CallArgs& args);
90
static bool fun_getUint8(JSContext* cx, unsigned argc, Value* vp);
91
92
static bool getInt16Impl(JSContext* cx, const CallArgs& args);
93
static bool fun_getInt16(JSContext* cx, unsigned argc, Value* vp);
94
95
static bool getUint16Impl(JSContext* cx, const CallArgs& args);
96
static bool fun_getUint16(JSContext* cx, unsigned argc, Value* vp);
97
98
static bool getInt32Impl(JSContext* cx, const CallArgs& args);
99
static bool fun_getInt32(JSContext* cx, unsigned argc, Value* vp);
100
101
static bool getUint32Impl(JSContext* cx, const CallArgs& args);
102
static bool fun_getUint32(JSContext* cx, unsigned argc, Value* vp);
103
104
static bool getBigInt64Impl(JSContext* cx, const CallArgs& args);
105
static bool fun_getBigInt64(JSContext* cx, unsigned argc, Value* vp);
106
107
static bool getBigUint64Impl(JSContext* cx, const CallArgs& args);
108
static bool fun_getBigUint64(JSContext* cx, unsigned argc, Value* vp);
109
110
static bool getFloat32Impl(JSContext* cx, const CallArgs& args);
111
static bool fun_getFloat32(JSContext* cx, unsigned argc, Value* vp);
112
113
static bool getFloat64Impl(JSContext* cx, const CallArgs& args);
114
static bool fun_getFloat64(JSContext* cx, unsigned argc, Value* vp);
115
116
static bool setInt8Impl(JSContext* cx, const CallArgs& args);
117
static bool fun_setInt8(JSContext* cx, unsigned argc, Value* vp);
118
119
static bool setUint8Impl(JSContext* cx, const CallArgs& args);
120
static bool fun_setUint8(JSContext* cx, unsigned argc, Value* vp);
121
122
static bool setInt16Impl(JSContext* cx, const CallArgs& args);
123
static bool fun_setInt16(JSContext* cx, unsigned argc, Value* vp);
124
125
static bool setUint16Impl(JSContext* cx, const CallArgs& args);
126
static bool fun_setUint16(JSContext* cx, unsigned argc, Value* vp);
127
128
static bool setInt32Impl(JSContext* cx, const CallArgs& args);
129
static bool fun_setInt32(JSContext* cx, unsigned argc, Value* vp);
130
131
static bool setUint32Impl(JSContext* cx, const CallArgs& args);
132
static bool fun_setUint32(JSContext* cx, unsigned argc, Value* vp);
133
134
static bool setBigInt64Impl(JSContext* cx, const CallArgs& args);
135
static bool fun_setBigInt64(JSContext* cx, unsigned argc, Value* vp);
136
137
static bool setBigUint64Impl(JSContext* cx, const CallArgs& args);
138
static bool fun_setBigUint64(JSContext* cx, unsigned argc, Value* vp);
139
140
static bool setFloat32Impl(JSContext* cx, const CallArgs& args);
141
static bool fun_setFloat32(JSContext* cx, unsigned argc, Value* vp);
142
143
static bool setFloat64Impl(JSContext* cx, const CallArgs& args);
144
static bool fun_setFloat64(JSContext* cx, unsigned argc, Value* vp);
145
146
template <typename NativeType>
147
static bool read(JSContext* cx, Handle<DataViewObject*> obj,
148
const CallArgs& args, NativeType* val);
149
template <typename NativeType>
150
static bool write(JSContext* cx, Handle<DataViewObject*> obj,
151
const CallArgs& args);
152
153
private:
154
static const JSFunctionSpec methods[];
155
static const JSPropertySpec properties[];
156
};
157
158
} // namespace js
159
160
#endif /* vm_DataViewObject_h */