v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
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 static constexpr size_t kMaxLength =
257 TypedArray::kMaxByteLength / sizeof(uint16_t);
258
259 public:
261 size_t byte_offset, size_t length);
263 size_t byte_offset, size_t length);
265#ifdef V8_ENABLE_CHECKS
266 CheckCast(value);
267#endif
268 return static_cast<Float16Array*>(value);
269 }
270
271 private:
272 Float16Array();
273 static void CheckCast(Value* obj);
274};
275
280 public:
281 /*
282 * The largest Float32Array size that can be constructed using New.
283 */
284 static constexpr size_t kMaxLength =
285 TypedArray::kMaxByteLength / sizeof(float);
286 static_assert(sizeof(float) == 4);
287
289 size_t byte_offset, size_t length);
291 size_t byte_offset, size_t length);
293#ifdef V8_ENABLE_CHECKS
294 CheckCast(value);
295#endif
296 return static_cast<Float32Array*>(value);
297 }
298
299 private:
300 Float32Array();
301 static void CheckCast(Value* obj);
302};
303
308 public:
309 /*
310 * The largest Float64Array size that can be constructed using New.
311 */
312 static constexpr size_t kMaxLength =
313 TypedArray::kMaxByteLength / sizeof(double);
314 static_assert(sizeof(double) == 8);
315
317 size_t byte_offset, size_t length);
319 size_t byte_offset, size_t length);
321#ifdef V8_ENABLE_CHECKS
322 CheckCast(value);
323#endif
324 return static_cast<Float64Array*>(value);
325 }
326
327 private:
328 Float64Array();
329 static void CheckCast(Value* obj);
330};
331
336 public:
337 /*
338 * The largest BigInt64Array size that can be constructed using New.
339 */
340 static constexpr size_t kMaxLength =
341 TypedArray::kMaxByteLength / sizeof(int64_t);
342 static_assert(sizeof(int64_t) == 8);
343
345 size_t byte_offset, size_t length);
347 size_t byte_offset, size_t length);
349#ifdef V8_ENABLE_CHECKS
350 CheckCast(value);
351#endif
352 return static_cast<BigInt64Array*>(value);
353 }
354
355 private:
357 static void CheckCast(Value* obj);
358};
359
364 public:
365 /*
366 * The largest BigUint64Array size that can be constructed using New.
367 */
368 static constexpr size_t kMaxLength =
369 TypedArray::kMaxByteLength / sizeof(uint64_t);
370 static_assert(sizeof(uint64_t) == 8);
371
373 size_t byte_offset, size_t length);
375 size_t byte_offset, size_t length);
377#ifdef V8_ENABLE_CHECKS
378 CheckCast(value);
379#endif
380 return static_cast<BigUint64Array*>(value);
381 }
382
383 private:
385 static void CheckCast(Value* obj);
386};
387
388} // namespace v8
389
390#endif // INCLUDE_V8_TYPED_ARRAY_H_
static Local< BigInt64Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static V8_INLINE BigInt64Array * Cast(Value *value)
static Local< BigInt64Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE BigUint64Array * Cast(Value *value)
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 Local< Float16Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Float16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Float16Array * Cast(Value *value)
static Local< Float32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Float32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Float32Array * Cast(Value *value)
static V8_INLINE Float64Array * Cast(Value *value)
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 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)
static V8_INLINE Int16Array * Cast(Value *value)
static V8_INLINE Int32Array * Cast(Value *value)
static Local< Int32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Int32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static Local< Int8Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Int8Array * Cast(Value *value)
static Local< Int8Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE TypedArray * Cast(Value *value)
size_t Length()
static Local< Uint16Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Uint16Array * Cast(Value *value)
static Local< Uint16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Uint32Array * Cast(Value *value)
static Local< Uint32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Uint32Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Uint8Array * Cast(Value *value)
static Local< Uint8Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static Local< Uint8Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
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 V8_INLINE Uint8ClampedArray * Cast(Value *value)
#define V8_EXPORT
Definition v8config.h:753
#define V8_INLINE
Definition v8config.h:477