Loading...
Searching...
No Matches
v8-typed-array.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_TYPED_ARRAY_H_
6#define INCLUDE_V8_TYPED_ARRAY_H_
7
8#include <limits>
9
10#include "v8-array-buffer.h" // NOLINT(build/include_directory)
11#include "v8-local-handle.h" // NOLINT(build/include_directory)
12#include "v8config.h" // NOLINT(build/include_directory)
13
14namespace v8 {
15
21 public:
22 /*
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.
25 */
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
41 size_t Length();
42
43 V8_INLINE static TypedArray* Cast(Value* value) {
44#ifdef V8_ENABLE_CHECKS
45 CheckCast(value);
46#endif
47 return static_cast<TypedArray*>(value);
48 }
49
50 private:
51 TypedArray();
52 static void CheckCast(Value* obj);
53};
54
59 public:
60 /*
61 * The largest Uint8Array size that can be constructed using New.
62 */
63 static constexpr size_t kMaxLength =
64 TypedArray::kMaxByteLength / sizeof(uint8_t);
65 static_assert(sizeof(uint8_t) == 1);
66
68 size_t byte_offset, size_t length);
70 size_t byte_offset, size_t length);
71 V8_INLINE static Uint8Array* Cast(Value* value) {
72#ifdef V8_ENABLE_CHECKS
73 CheckCast(value);
74#endif
75 return static_cast<Uint8Array*>(value);
76 }
77
78 private:
79 Uint8Array();
80 static void CheckCast(Value* obj);
81};
82
87 public:
88 /*
89 * The largest Uint8ClampedArray size that can be constructed using New.
90 */
91 static constexpr size_t kMaxLength =
92 TypedArray::kMaxByteLength / sizeof(uint8_t);
93 static_assert(sizeof(uint8_t) == 1);
94
96 size_t byte_offset, size_t length);
98 Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
99 size_t length);
101#ifdef V8_ENABLE_CHECKS
102 CheckCast(value);
103#endif
104 return static_cast<Uint8ClampedArray*>(value);
105 }
106
107 private:
109 static void CheckCast(Value* obj);
110};
111
116 public:
117 /*
118 * The largest Int8Array size that can be constructed using New.
119 */
120 static constexpr size_t kMaxLength =
121 TypedArray::kMaxByteLength / sizeof(int8_t);
122 static_assert(sizeof(int8_t) == 1);
123
125 size_t byte_offset, size_t length);
127 size_t byte_offset, size_t length);
128 V8_INLINE static Int8Array* Cast(Value* value) {
129#ifdef V8_ENABLE_CHECKS
130 CheckCast(value);
131#endif
132 return static_cast<Int8Array*>(value);
133 }
134
135 private:
136 Int8Array();
137 static void CheckCast(Value* obj);
138};
139
144 public:
145 /*
146 * The largest Uint16Array size that can be constructed using New.
147 */
148 static constexpr size_t kMaxLength =
149 TypedArray::kMaxByteLength / sizeof(uint16_t);
150 static_assert(sizeof(uint16_t) == 2);
151
153 size_t byte_offset, size_t length);
155 size_t byte_offset, size_t length);
156 V8_INLINE static Uint16Array* Cast(Value* value) {
157#ifdef V8_ENABLE_CHECKS
158 CheckCast(value);
159#endif
160 return static_cast<Uint16Array*>(value);
161 }
162
163 private:
164 Uint16Array();
165 static void CheckCast(Value* obj);
166};
167
172 public:
173 /*
174 * The largest Int16Array size that can be constructed using New.
175 */
176 static constexpr size_t kMaxLength =
177 TypedArray::kMaxByteLength / sizeof(int16_t);
178 static_assert(sizeof(int16_t) == 2);
179
181 size_t byte_offset, size_t length);
183 size_t byte_offset, size_t length);
184 V8_INLINE static Int16Array* Cast(Value* value) {
185#ifdef V8_ENABLE_CHECKS
186 CheckCast(value);
187#endif
188 return static_cast<Int16Array*>(value);
189 }
190
191 private:
192 Int16Array();
193 static void CheckCast(Value* obj);
194};
195
200 public:
201 /*
202 * The largest Uint32Array size that can be constructed using New.
203 */
204 static constexpr size_t kMaxLength =
205 TypedArray::kMaxByteLength / sizeof(uint32_t);
206 static_assert(sizeof(uint32_t) == 4);
207
209 size_t byte_offset, size_t length);
211 size_t byte_offset, size_t length);
212 V8_INLINE static Uint32Array* Cast(Value* value) {
213#ifdef V8_ENABLE_CHECKS
214 CheckCast(value);
215#endif
216 return static_cast<Uint32Array*>(value);
217 }
218
219 private:
220 Uint32Array();
221 static void CheckCast(Value* obj);
222};
223
228 public:
229 /*
230 * The largest Int32Array size that can be constructed using New.
231 */
232 static constexpr size_t kMaxLength =
233 TypedArray::kMaxByteLength / sizeof(int32_t);
234 static_assert(sizeof(int32_t) == 4);
235
237 size_t byte_offset, size_t length);
239 size_t byte_offset, size_t length);
240 V8_INLINE static Int32Array* Cast(Value* value) {
241#ifdef V8_ENABLE_CHECKS
242 CheckCast(value);
243#endif
244 return static_cast<Int32Array*>(value);
245 }
246
247 private:
248 Int32Array();
249 static void CheckCast(Value* obj);
250};
251
256 public:
257 /*
258 * The largest Float32Array size that can be constructed using New.
259 */
260 static constexpr size_t kMaxLength =
261 TypedArray::kMaxByteLength / sizeof(float);
262 static_assert(sizeof(float) == 4);
263
265 size_t byte_offset, size_t length);
267 size_t byte_offset, size_t length);
269#ifdef V8_ENABLE_CHECKS
270 CheckCast(value);
271#endif
272 return static_cast<Float32Array*>(value);
273 }
274
275 private:
276 Float32Array();
277 static void CheckCast(Value* obj);
278};
279
284 public:
285 /*
286 * The largest Float64Array size that can be constructed using New.
287 */
288 static constexpr size_t kMaxLength =
289 TypedArray::kMaxByteLength / sizeof(double);
290 static_assert(sizeof(double) == 8);
291
293 size_t byte_offset, size_t length);
295 size_t byte_offset, size_t length);
297#ifdef V8_ENABLE_CHECKS
298 CheckCast(value);
299#endif
300 return static_cast<Float64Array*>(value);
301 }
302
303 private:
304 Float64Array();
305 static void CheckCast(Value* obj);
306};
307
312 public:
313 /*
314 * The largest BigInt64Array size that can be constructed using New.
315 */
316 static constexpr size_t kMaxLength =
317 TypedArray::kMaxByteLength / sizeof(int64_t);
318 static_assert(sizeof(int64_t) == 8);
319
321 size_t byte_offset, size_t length);
323 size_t byte_offset, size_t length);
325#ifdef V8_ENABLE_CHECKS
326 CheckCast(value);
327#endif
328 return static_cast<BigInt64Array*>(value);
329 }
330
331 private:
333 static void CheckCast(Value* obj);
334};
335
340 public:
341 /*
342 * The largest BigUint64Array size that can be constructed using New.
343 */
344 static constexpr size_t kMaxLength =
345 TypedArray::kMaxByteLength / sizeof(uint64_t);
346 static_assert(sizeof(uint64_t) == 8);
347
349 size_t byte_offset, size_t length);
351 size_t byte_offset, size_t length);
353#ifdef V8_ENABLE_CHECKS
354 CheckCast(value);
355#endif
356 return static_cast<BigUint64Array*>(value);
357 }
358
359 private:
361 static void CheckCast(Value* obj);
362};
363
364} // namespace v8
365
366#endif // INCLUDE_V8_TYPED_ARRAY_H_
Definition: v8-array-buffer.h:351
Definition: v8-typed-array.h:311
static Local< BigInt64Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< BigInt64Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static BigInt64Array * Cast(Value *value)
Definition: v8-typed-array.h:324
Definition: v8-typed-array.h:339
static Local< BigUint64Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< BigUint64Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static BigUint64Array * Cast(Value *value)
Definition: v8-typed-array.h:352
Definition: v8-typed-array.h:255
static Local< Float32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Float32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Float32Array * Cast(Value *value)
Definition: v8-typed-array.h:268
Definition: v8-typed-array.h:283
static Local< Float64Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Float64Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Float64Array * Cast(Value *value)
Definition: v8-typed-array.h:296
Definition: v8-typed-array.h:171
static Int16Array * Cast(Value *value)
Definition: v8-typed-array.h:184
static Local< Int16Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Int16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:227
static Local< Int32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Int32Array * Cast(Value *value)
Definition: v8-typed-array.h:240
static Local< Int32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:115
static Int8Array * Cast(Value *value)
Definition: v8-typed-array.h:128
static Local< Int8Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Int8Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
Definition: v8-local-handle.h:248
Definition: v8-typed-array.h:20
size_t Length()
static TypedArray * Cast(Value *value)
Definition: v8-typed-array.h:43
Definition: v8-typed-array.h:143
static Local< Uint16Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Uint16Array * Cast(Value *value)
Definition: v8-typed-array.h:156
static Local< Uint16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:199
static Uint32Array * Cast(Value *value)
Definition: v8-typed-array.h:212
static Local< Uint32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Uint32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:58
static Uint8Array * Cast(Value *value)
Definition: v8-typed-array.h:71
static Local< Uint8Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Uint8Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:86
static Local< Uint8ClampedArray > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Uint8ClampedArray > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Uint8ClampedArray * Cast(Value *value)
Definition: v8-typed-array.h:100
Definition: v8-value.h:32
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:739
#define V8_INLINE
Definition: v8config.h:466