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 static constexpr size_t kMaxByteLength = ArrayBuffer::kMaxByteLength;
27
28#ifdef V8_ENABLE_SANDBOX
29 static_assert(v8::TypedArray::kMaxByteLength <=
30 v8::internal::kMaxSafeBufferSizeForSandbox);
31#endif
32
37 size_t Length();
38
39 V8_INLINE static TypedArray* Cast(Value* value) {
40#ifdef V8_ENABLE_CHECKS
41 CheckCast(value);
42#endif
43 return static_cast<TypedArray*>(value);
44 }
45
46 private:
47 TypedArray();
48 static void CheckCast(Value* obj);
49};
50
55 public:
56 /*
57 * The largest Uint8Array size that can be constructed using New.
58 */
59 static constexpr size_t kMaxLength =
60 TypedArray::kMaxByteLength / sizeof(uint8_t);
61 static_assert(sizeof(uint8_t) == 1);
62
64 size_t byte_offset, size_t length);
65 V8_INLINE static Uint8Array* Cast(Value* value) {
66#ifdef V8_ENABLE_CHECKS
67 CheckCast(value);
68#endif
69 return static_cast<Uint8Array*>(value);
70 }
71
72 private:
73 Uint8Array();
74 static void CheckCast(Value* obj);
75};
76
81 public:
82 /*
83 * The largest Uint8ClampedArray size that can be constructed using New.
84 */
85 static constexpr size_t kMaxLength =
86 TypedArray::kMaxByteLength / sizeof(uint8_t);
87 static_assert(sizeof(uint8_t) == 1);
88
90 size_t byte_offset, size_t length);
92#ifdef V8_ENABLE_CHECKS
93 CheckCast(value);
94#endif
95 return static_cast<Uint8ClampedArray*>(value);
96 }
97
98 private:
100 static void CheckCast(Value* obj);
101};
102
107 public:
108 /*
109 * The largest Int8Array size that can be constructed using New.
110 */
111 static constexpr size_t kMaxLength =
112 TypedArray::kMaxByteLength / sizeof(int8_t);
113 static_assert(sizeof(int8_t) == 1);
114
116 size_t byte_offset, size_t length);
117 V8_INLINE static Int8Array* Cast(Value* value) {
118#ifdef V8_ENABLE_CHECKS
119 CheckCast(value);
120#endif
121 return static_cast<Int8Array*>(value);
122 }
123
124 private:
125 Int8Array();
126 static void CheckCast(Value* obj);
127};
128
133 public:
134 /*
135 * The largest Uint16Array size that can be constructed using New.
136 */
137 static constexpr size_t kMaxLength =
138 TypedArray::kMaxByteLength / sizeof(uint16_t);
139 static_assert(sizeof(uint16_t) == 2);
140
142 size_t byte_offset, size_t length);
143 V8_INLINE static Uint16Array* Cast(Value* value) {
144#ifdef V8_ENABLE_CHECKS
145 CheckCast(value);
146#endif
147 return static_cast<Uint16Array*>(value);
148 }
149
150 private:
151 Uint16Array();
152 static void CheckCast(Value* obj);
153};
154
159 public:
160 /*
161 * The largest Int16Array size that can be constructed using New.
162 */
163 static constexpr size_t kMaxLength =
164 TypedArray::kMaxByteLength / sizeof(int16_t);
165 static_assert(sizeof(int16_t) == 2);
166
168 size_t byte_offset, size_t length);
169 V8_INLINE static Int16Array* Cast(Value* value) {
170#ifdef V8_ENABLE_CHECKS
171 CheckCast(value);
172#endif
173 return static_cast<Int16Array*>(value);
174 }
175
176 private:
177 Int16Array();
178 static void CheckCast(Value* obj);
179};
180
185 public:
186 /*
187 * The largest Uint32Array size that can be constructed using New.
188 */
189 static constexpr size_t kMaxLength =
190 TypedArray::kMaxByteLength / sizeof(uint32_t);
191 static_assert(sizeof(uint32_t) == 4);
192
194 size_t byte_offset, size_t length);
195 V8_INLINE static Uint32Array* Cast(Value* value) {
196#ifdef V8_ENABLE_CHECKS
197 CheckCast(value);
198#endif
199 return static_cast<Uint32Array*>(value);
200 }
201
202 private:
203 Uint32Array();
204 static void CheckCast(Value* obj);
205};
206
211 public:
212 /*
213 * The largest Int32Array size that can be constructed using New.
214 */
215 static constexpr size_t kMaxLength =
216 TypedArray::kMaxByteLength / sizeof(int32_t);
217 static_assert(sizeof(int32_t) == 4);
218
220 size_t byte_offset, size_t length);
221 V8_INLINE static Int32Array* Cast(Value* value) {
222#ifdef V8_ENABLE_CHECKS
223 CheckCast(value);
224#endif
225 return static_cast<Int32Array*>(value);
226 }
227
228 private:
229 Int32Array();
230 static void CheckCast(Value* obj);
231};
232
237 public:
238 static constexpr size_t kMaxLength =
239 TypedArray::kMaxByteLength / sizeof(uint16_t);
240
242 size_t byte_offset, size_t length);
244#ifdef V8_ENABLE_CHECKS
245 CheckCast(value);
246#endif
247 return static_cast<Float16Array*>(value);
248 }
249
250 private:
251 Float16Array();
252 static void CheckCast(Value* obj);
253};
254
259 public:
260 /*
261 * The largest Float32Array size that can be constructed using New.
262 */
263 static constexpr size_t kMaxLength =
264 TypedArray::kMaxByteLength / sizeof(float);
265 static_assert(sizeof(float) == 4);
266
268 size_t byte_offset, size_t length);
270#ifdef V8_ENABLE_CHECKS
271 CheckCast(value);
272#endif
273 return static_cast<Float32Array*>(value);
274 }
275
276 private:
277 Float32Array();
278 static void CheckCast(Value* obj);
279};
280
285 public:
286 /*
287 * The largest Float64Array size that can be constructed using New.
288 */
289 static constexpr size_t kMaxLength =
290 TypedArray::kMaxByteLength / sizeof(double);
291 static_assert(sizeof(double) == 8);
292
294 size_t byte_offset, size_t length);
296#ifdef V8_ENABLE_CHECKS
297 CheckCast(value);
298#endif
299 return static_cast<Float64Array*>(value);
300 }
301
302 private:
303 Float64Array();
304 static void CheckCast(Value* obj);
305};
306
311 public:
312 /*
313 * The largest BigInt64Array size that can be constructed using New.
314 */
315 static constexpr size_t kMaxLength =
316 TypedArray::kMaxByteLength / sizeof(int64_t);
317 static_assert(sizeof(int64_t) == 8);
318
320 size_t byte_offset, size_t length);
322#ifdef V8_ENABLE_CHECKS
323 CheckCast(value);
324#endif
325 return static_cast<BigInt64Array*>(value);
326 }
327
328 private:
330 static void CheckCast(Value* obj);
331};
332
337 public:
338 /*
339 * The largest BigUint64Array size that can be constructed using New.
340 */
341 static constexpr size_t kMaxLength =
342 TypedArray::kMaxByteLength / sizeof(uint64_t);
343 static_assert(sizeof(uint64_t) == 8);
344
346 size_t byte_offset, size_t length);
348#ifdef V8_ENABLE_CHECKS
349 CheckCast(value);
350#endif
351 return static_cast<BigUint64Array*>(value);
352 }
353
354 private:
356 static void CheckCast(Value* obj);
357};
358
359} // namespace v8
360
361#endif // INCLUDE_V8_TYPED_ARRAY_H_
Definition: v8-array-buffer.h:472
Definition: v8-typed-array.h:310
static Local< BigInt64Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static BigInt64Array * Cast(Value *value)
Definition: v8-typed-array.h:321
Definition: v8-typed-array.h:336
static Local< BigUint64Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static BigUint64Array * Cast(Value *value)
Definition: v8-typed-array.h:347
Definition: v8-typed-array.h:236
static Float16Array * Cast(Value *value)
Definition: v8-typed-array.h:243
static Local< Float16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:258
static Local< Float32Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static Float32Array * Cast(Value *value)
Definition: v8-typed-array.h:269
Definition: v8-typed-array.h:284
static Local< Float64Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static Float64Array * Cast(Value *value)
Definition: v8-typed-array.h:295
Definition: v8-typed-array.h:158
static Int16Array * Cast(Value *value)
Definition: v8-typed-array.h:169
static Local< Int16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:210
static Int32Array * Cast(Value *value)
Definition: v8-typed-array.h:221
static Local< Int32Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:106
static Int8Array * Cast(Value *value)
Definition: v8-typed-array.h:117
static Local< Int8Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-local-handle.h:359
Definition: v8-typed-array.h:20
static constexpr size_t kMaxByteLength
Definition: v8-typed-array.h:26
size_t Length()
static TypedArray * Cast(Value *value)
Definition: v8-typed-array.h:39
Definition: v8-typed-array.h:132
static Uint16Array * Cast(Value *value)
Definition: v8-typed-array.h:143
static Local< Uint16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:184
static Uint32Array * Cast(Value *value)
Definition: v8-typed-array.h:195
static Local< Uint32Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:54
static Local< Uint8Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static Uint8Array * Cast(Value *value)
Definition: v8-typed-array.h:65
Definition: v8-typed-array.h:80
static Local< Uint8ClampedArray > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
static Uint8ClampedArray * Cast(Value *value)
Definition: v8-typed-array.h:91
Definition: v8-value.h:32
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:874
#define V8_INLINE
Definition: v8config.h:518