55#ifndef INCLUDE_V8_TYPED_ARRAY_H_
66#define INCLUDE_V8_TYPED_ARRAY_H_
77
8+ #include < limits>
9+
810#include " v8-array-buffer.h" // NOLINT(build/include_directory)
911#include " v8-local-handle.h" // NOLINT(build/include_directory)
1012#include " v8config.h" // NOLINT(build/include_directory)
1113
1214namespace v8 {
1315
14- class SharedArrayBuffer ;
15-
1616/* *
1717 * A base class for an instance of TypedArray series of constructors
1818 * (ES6 draft 15.13.6).
1919 */
2020class V8_EXPORT TypedArray : public ArrayBufferView {
2121 public:
2222 /*
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.
2425 */
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 ;
2942
3043 /* *
3144 * Number of elements in this typed array
@@ -50,6 +63,13 @@ class V8_EXPORT TypedArray : public ArrayBufferView {
5063 */
5164class V8_EXPORT Uint8Array : public TypedArray {
5265 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+
5373 static Local<Uint8Array> New (Local<ArrayBuffer> array_buffer,
5474 size_t byte_offset, size_t length);
5575 static Local<Uint8Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -71,6 +91,13 @@ class V8_EXPORT Uint8Array : public TypedArray {
7191 */
7292class V8_EXPORT Uint8ClampedArray : public TypedArray {
7393 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+
74101 static Local<Uint8ClampedArray> New (Local<ArrayBuffer> array_buffer,
75102 size_t byte_offset, size_t length);
76103 static Local<Uint8ClampedArray> New (
@@ -93,6 +120,13 @@ class V8_EXPORT Uint8ClampedArray : public TypedArray {
93120 */
94121class V8_EXPORT Int8Array : public TypedArray {
95122 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+
96130 static Local<Int8Array> New (Local<ArrayBuffer> array_buffer,
97131 size_t byte_offset, size_t length);
98132 static Local<Int8Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -114,6 +148,13 @@ class V8_EXPORT Int8Array : public TypedArray {
114148 */
115149class V8_EXPORT Uint16Array : public TypedArray {
116150 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+
117158 static Local<Uint16Array> New (Local<ArrayBuffer> array_buffer,
118159 size_t byte_offset, size_t length);
119160 static Local<Uint16Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -135,6 +176,13 @@ class V8_EXPORT Uint16Array : public TypedArray {
135176 */
136177class V8_EXPORT Int16Array : public TypedArray {
137178 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+
138186 static Local<Int16Array> New (Local<ArrayBuffer> array_buffer,
139187 size_t byte_offset, size_t length);
140188 static Local<Int16Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -156,6 +204,13 @@ class V8_EXPORT Int16Array : public TypedArray {
156204 */
157205class V8_EXPORT Uint32Array : public TypedArray {
158206 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+
159214 static Local<Uint32Array> New (Local<ArrayBuffer> array_buffer,
160215 size_t byte_offset, size_t length);
161216 static Local<Uint32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -177,6 +232,13 @@ class V8_EXPORT Uint32Array : public TypedArray {
177232 */
178233class V8_EXPORT Int32Array : public TypedArray {
179234 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+
180242 static Local<Int32Array> New (Local<ArrayBuffer> array_buffer,
181243 size_t byte_offset, size_t length);
182244 static Local<Int32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -198,6 +260,13 @@ class V8_EXPORT Int32Array : public TypedArray {
198260 */
199261class V8_EXPORT Float32Array : public TypedArray {
200262 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+
201270 static Local<Float32Array> New (Local<ArrayBuffer> array_buffer,
202271 size_t byte_offset, size_t length);
203272 static Local<Float32Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -219,6 +288,13 @@ class V8_EXPORT Float32Array : public TypedArray {
219288 */
220289class V8_EXPORT Float64Array : public TypedArray {
221290 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+
222298 static Local<Float64Array> New (Local<ArrayBuffer> array_buffer,
223299 size_t byte_offset, size_t length);
224300 static Local<Float64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -240,6 +316,13 @@ class V8_EXPORT Float64Array : public TypedArray {
240316 */
241317class V8_EXPORT BigInt64Array : public TypedArray {
242318 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+
243326 static Local<BigInt64Array> New (Local<ArrayBuffer> array_buffer,
244327 size_t byte_offset, size_t length);
245328 static Local<BigInt64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
@@ -261,6 +344,13 @@ class V8_EXPORT BigInt64Array : public TypedArray {
261344 */
262345class V8_EXPORT BigUint64Array : public TypedArray {
263346 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+
264354 static Local<BigUint64Array> New (Local<ArrayBuffer> array_buffer,
265355 size_t byte_offset, size_t length);
266356 static Local<BigUint64Array> New (Local<SharedArrayBuffer> shared_array_buffer,
0 commit comments