5
5
#ifndef INCLUDE_V8_TYPED_ARRAY_H_
6
6
#define INCLUDE_V8_TYPED_ARRAY_H_
7
7
8
+ #include < limits>
9
+
8
10
#include " v8-array-buffer.h" // NOLINT(build/include_directory)
9
11
#include " v8-local-handle.h" // NOLINT(build/include_directory)
10
12
#include " v8config.h" // NOLINT(build/include_directory)
11
13
12
14
namespace v8 {
13
15
14
- class SharedArrayBuffer ;
15
-
16
16
/* *
17
17
* A base class for an instance of TypedArray series of constructors
18
18
* (ES6 draft 15.13.6).
19
19
*/
20
20
class V8_EXPORT TypedArray : public ArrayBufferView {
21
21
public:
22
22
/*
23
- * The largest typed array size that can be constructed using New.
23
+ * The largest supported typed array byte size. Each subclass defines a
24
+ * type-specific kMaxLength for the maximum length that can be passed to New.
24
25
*/
25
- static constexpr size_t kMaxLength =
26
- internal::kApiSystemPointerSize == 4
27
- ? internal::kSmiMaxValue
28
- : static_cast <size_t >(uint64_t {1 } << 32 );
26
+ #if V8_ENABLE_SANDBOX
27
+ static constexpr size_t kMaxByteLength =
28
+ internal::kMaxSafeBufferSizeForSandbox ;
29
+ #elif V8_HOST_ARCH_32_BIT
30
+ static constexpr size_t kMaxByteLength = std::numeric_limits<int >::max();
31
+ #else
32
+ // The maximum safe integer (2^53 - 1).
33
+ static constexpr size_t kMaxByteLength =
34
+ static_cast <size_t >((uint64_t {1 } << 53 ) - 1 );
35
+ #endif
36
+
37
+ /*
38
+ * Deprecated: Use |kMaxByteLength| or the type-specific |kMaxLength| fields.
39
+ */
40
+ V8_DEPRECATE_SOON (" Use kMaxByteLength" )
41
+ static constexpr size_t kMaxLength = kMaxByteLength ;
29
42
30
43
/* *
31
44
* Number of elements in this typed array
@@ -50,6 +63,13 @@ class V8_EXPORT TypedArray : public ArrayBufferView {
50
63
*/
51
64
class V8_EXPORT Uint8Array : public TypedArray {
52
65
public:
66
+ /*
67
+ * The largest Uint8Array size that can be constructed using New.
68
+ */
69
+ static constexpr size_t kMaxLength =
70
+ TypedArray::kMaxByteLength / sizeof (uint8_t );
71
+ static_assert (sizeof (uint8_t ) == 1 );
72
+
53
73
static Local<Uint8Array> New (Local<ArrayBuffer> array_buffer,
54
74
size_t byte_offset, size_t length);
55
75
static Local<Uint8Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -71,6 +91,13 @@ class V8_EXPORT Uint8Array : public TypedArray {
71
91
*/
72
92
class V8_EXPORT Uint8ClampedArray : public TypedArray {
73
93
public:
94
+ /*
95
+ * The largest Uint8ClampedArray size that can be constructed using New.
96
+ */
97
+ static constexpr size_t kMaxLength =
98
+ TypedArray::kMaxByteLength / sizeof (uint8_t );
99
+ static_assert (sizeof (uint8_t ) == 1 );
100
+
74
101
static Local<Uint8ClampedArray> New (Local<ArrayBuffer> array_buffer,
75
102
size_t byte_offset, size_t length);
76
103
static Local<Uint8ClampedArray> New (
@@ -93,6 +120,13 @@ class V8_EXPORT Uint8ClampedArray : public TypedArray {
93
120
*/
94
121
class V8_EXPORT Int8Array : public TypedArray {
95
122
public:
123
+ /*
124
+ * The largest Int8Array size that can be constructed using New.
125
+ */
126
+ static constexpr size_t kMaxLength =
127
+ TypedArray::kMaxByteLength / sizeof (int8_t );
128
+ static_assert (sizeof (int8_t ) == 1 );
129
+
96
130
static Local<Int8Array> New (Local<ArrayBuffer> array_buffer,
97
131
size_t byte_offset, size_t length);
98
132
static Local<Int8Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -114,6 +148,13 @@ class V8_EXPORT Int8Array : public TypedArray {
114
148
*/
115
149
class V8_EXPORT Uint16Array : public TypedArray {
116
150
public:
151
+ /*
152
+ * The largest Uint16Array size that can be constructed using New.
153
+ */
154
+ static constexpr size_t kMaxLength =
155
+ TypedArray::kMaxByteLength / sizeof (uint16_t );
156
+ static_assert (sizeof (uint16_t ) == 2 );
157
+
117
158
static Local<Uint16Array> New (Local<ArrayBuffer> array_buffer,
118
159
size_t byte_offset, size_t length);
119
160
static Local<Uint16Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -135,6 +176,13 @@ class V8_EXPORT Uint16Array : public TypedArray {
135
176
*/
136
177
class V8_EXPORT Int16Array : public TypedArray {
137
178
public:
179
+ /*
180
+ * The largest Int16Array size that can be constructed using New.
181
+ */
182
+ static constexpr size_t kMaxLength =
183
+ TypedArray::kMaxByteLength / sizeof (int16_t );
184
+ static_assert (sizeof (int16_t ) == 2 );
185
+
138
186
static Local<Int16Array> New (Local<ArrayBuffer> array_buffer,
139
187
size_t byte_offset, size_t length);
140
188
static Local<Int16Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -156,6 +204,13 @@ class V8_EXPORT Int16Array : public TypedArray {
156
204
*/
157
205
class V8_EXPORT Uint32Array : public TypedArray {
158
206
public:
207
+ /*
208
+ * The largest Uint32Array size that can be constructed using New.
209
+ */
210
+ static constexpr size_t kMaxLength =
211
+ TypedArray::kMaxByteLength / sizeof (uint32_t );
212
+ static_assert (sizeof (uint32_t ) == 4 );
213
+
159
214
static Local<Uint32Array> New (Local<ArrayBuffer> array_buffer,
160
215
size_t byte_offset, size_t length);
161
216
static Local<Uint32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -177,6 +232,13 @@ class V8_EXPORT Uint32Array : public TypedArray {
177
232
*/
178
233
class V8_EXPORT Int32Array : public TypedArray {
179
234
public:
235
+ /*
236
+ * The largest Int32Array size that can be constructed using New.
237
+ */
238
+ static constexpr size_t kMaxLength =
239
+ TypedArray::kMaxByteLength / sizeof (int32_t );
240
+ static_assert (sizeof (int32_t ) == 4 );
241
+
180
242
static Local<Int32Array> New (Local<ArrayBuffer> array_buffer,
181
243
size_t byte_offset, size_t length);
182
244
static Local<Int32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -198,6 +260,13 @@ class V8_EXPORT Int32Array : public TypedArray {
198
260
*/
199
261
class V8_EXPORT Float32Array : public TypedArray {
200
262
public:
263
+ /*
264
+ * The largest Float32Array size that can be constructed using New.
265
+ */
266
+ static constexpr size_t kMaxLength =
267
+ TypedArray::kMaxByteLength / sizeof (float );
268
+ static_assert (sizeof (float ) == 4 );
269
+
201
270
static Local<Float32Array> New (Local<ArrayBuffer> array_buffer,
202
271
size_t byte_offset, size_t length);
203
272
static Local<Float32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -219,6 +288,13 @@ class V8_EXPORT Float32Array : public TypedArray {
219
288
*/
220
289
class V8_EXPORT Float64Array : public TypedArray {
221
290
public:
291
+ /*
292
+ * The largest Float64Array size that can be constructed using New.
293
+ */
294
+ static constexpr size_t kMaxLength =
295
+ TypedArray::kMaxByteLength / sizeof (double );
296
+ static_assert (sizeof (double ) == 8 );
297
+
222
298
static Local<Float64Array> New (Local<ArrayBuffer> array_buffer,
223
299
size_t byte_offset, size_t length);
224
300
static Local<Float64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -240,6 +316,13 @@ class V8_EXPORT Float64Array : public TypedArray {
240
316
*/
241
317
class V8_EXPORT BigInt64Array : public TypedArray {
242
318
public:
319
+ /*
320
+ * The largest BigInt64Array size that can be constructed using New.
321
+ */
322
+ static constexpr size_t kMaxLength =
323
+ TypedArray::kMaxByteLength / sizeof (int64_t );
324
+ static_assert (sizeof (int64_t ) == 8 );
325
+
243
326
static Local<BigInt64Array> New (Local<ArrayBuffer> array_buffer,
244
327
size_t byte_offset, size_t length);
245
328
static Local<BigInt64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -261,6 +344,13 @@ class V8_EXPORT BigInt64Array : public TypedArray {
261
344
*/
262
345
class V8_EXPORT BigUint64Array : public TypedArray {
263
346
public:
347
+ /*
348
+ * The largest BigUint64Array size that can be constructed using New.
349
+ */
350
+ static constexpr size_t kMaxLength =
351
+ TypedArray::kMaxByteLength / sizeof (uint64_t );
352
+ static_assert (sizeof (uint64_t ) == 8 );
353
+
264
354
static Local<BigUint64Array> New (Local<ArrayBuffer> array_buffer,
265
355
size_t byte_offset, size_t length);
266
356
static Local<BigUint64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
0 commit comments