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#include <span>
10
11#include "v8-array-buffer.h" // NOLINT(build/include_directory)
12#include "v8-local-handle.h" // NOLINT(build/include_directory)
13#include "v8config.h" // NOLINT(build/include_directory)
14
15namespace v8 {
16
22 public:
23 /*
24 * The largest supported typed array byte size. Each subclass defines a
25 * type-specific kMaxLength for the maximum length that can be passed to New.
26 */
27 static constexpr size_t kMaxByteLength = ArrayBuffer::kMaxByteLength;
28
29#ifdef V8_ENABLE_SANDBOX
30 static_assert(v8::TypedArray::kMaxByteLength <=
31 v8::internal::kMaxSafeBufferSizeForSandbox);
32#endif
33
38 size_t Length();
39
40 V8_INLINE static TypedArray* Cast(Value* value) {
41#ifdef V8_ENABLE_CHECKS
42 CheckCast(value);
43#endif
44 return static_cast<TypedArray*>(value);
45 }
46
47 private:
48 TypedArray();
49 static void CheckCast(Value* obj);
50};
51
56 public:
57 /*
58 * The largest Uint8Array size that can be constructed using New.
59 */
60 static constexpr size_t kMaxLength =
61 TypedArray::kMaxByteLength / sizeof(uint8_t);
62 static_assert(sizeof(uint8_t) == 1);
63
65 size_t byte_offset, size_t length);
72 std::span<const uint8_t> data);
73 V8_INLINE static Uint8Array* Cast(Value* value) {
74#ifdef V8_ENABLE_CHECKS
75 CheckCast(value);
76#endif
77 return static_cast<Uint8Array*>(value);
78 }
79
80 private:
81 Uint8Array();
82 static void CheckCast(Value* obj);
83};
84
89 public:
90 /*
91 * The largest Uint8ClampedArray size that can be constructed using New.
92 */
93 static constexpr size_t kMaxLength =
94 TypedArray::kMaxByteLength / sizeof(uint8_t);
95 static_assert(sizeof(uint8_t) == 1);
96
98 size_t byte_offset, size_t length);
100#ifdef V8_ENABLE_CHECKS
101 CheckCast(value);
102#endif
103 return static_cast<Uint8ClampedArray*>(value);
104 }
105
106 private:
108 static void CheckCast(Value* obj);
109};
110
115 public:
116 /*
117 * The largest Int8Array size that can be constructed using New.
118 */
119 static constexpr size_t kMaxLength =
120 TypedArray::kMaxByteLength / sizeof(int8_t);
121 static_assert(sizeof(int8_t) == 1);
122
124 size_t byte_offset, size_t length);
125 V8_INLINE static Int8Array* Cast(Value* value) {
126#ifdef V8_ENABLE_CHECKS
127 CheckCast(value);
128#endif
129 return static_cast<Int8Array*>(value);
130 }
131
132 private:
133 Int8Array();
134 static void CheckCast(Value* obj);
135};
136
141 public:
142 /*
143 * The largest Uint16Array size that can be constructed using New.
144 */
145 static constexpr size_t kMaxLength =
146 TypedArray::kMaxByteLength / sizeof(uint16_t);
147 static_assert(sizeof(uint16_t) == 2);
148
150 size_t byte_offset, size_t length);
151 V8_INLINE static Uint16Array* Cast(Value* value) {
152#ifdef V8_ENABLE_CHECKS
153 CheckCast(value);
154#endif
155 return static_cast<Uint16Array*>(value);
156 }
157
158 private:
159 Uint16Array();
160 static void CheckCast(Value* obj);
161};
162
167 public:
168 /*
169 * The largest Int16Array size that can be constructed using New.
170 */
171 static constexpr size_t kMaxLength =
172 TypedArray::kMaxByteLength / sizeof(int16_t);
173 static_assert(sizeof(int16_t) == 2);
174
176 size_t byte_offset, size_t length);
177 V8_INLINE static Int16Array* Cast(Value* value) {
178#ifdef V8_ENABLE_CHECKS
179 CheckCast(value);
180#endif
181 return static_cast<Int16Array*>(value);
182 }
183
184 private:
185 Int16Array();
186 static void CheckCast(Value* obj);
187};
188
193 public:
194 /*
195 * The largest Uint32Array size that can be constructed using New.
196 */
197 static constexpr size_t kMaxLength =
198 TypedArray::kMaxByteLength / sizeof(uint32_t);
199 static_assert(sizeof(uint32_t) == 4);
200
202 size_t byte_offset, size_t length);
203 V8_INLINE static Uint32Array* Cast(Value* value) {
204#ifdef V8_ENABLE_CHECKS
205 CheckCast(value);
206#endif
207 return static_cast<Uint32Array*>(value);
208 }
209
210 private:
211 Uint32Array();
212 static void CheckCast(Value* obj);
213};
214
219 public:
220 /*
221 * The largest Int32Array size that can be constructed using New.
222 */
223 static constexpr size_t kMaxLength =
224 TypedArray::kMaxByteLength / sizeof(int32_t);
225 static_assert(sizeof(int32_t) == 4);
226
228 size_t byte_offset, size_t length);
229 V8_INLINE static Int32Array* Cast(Value* value) {
230#ifdef V8_ENABLE_CHECKS
231 CheckCast(value);
232#endif
233 return static_cast<Int32Array*>(value);
234 }
235
236 private:
237 Int32Array();
238 static void CheckCast(Value* obj);
239};
240
245 public:
246 static constexpr size_t kMaxLength =
247 TypedArray::kMaxByteLength / sizeof(uint16_t);
248
250 size_t byte_offset, size_t length);
252#ifdef V8_ENABLE_CHECKS
253 CheckCast(value);
254#endif
255 return static_cast<Float16Array*>(value);
256 }
257
258 private:
259 Float16Array();
260 static void CheckCast(Value* obj);
261};
262
267 public:
268 /*
269 * The largest Float32Array size that can be constructed using New.
270 */
271 static constexpr size_t kMaxLength =
272 TypedArray::kMaxByteLength / sizeof(float);
273 static_assert(sizeof(float) == 4);
274
276 size_t byte_offset, size_t length);
278#ifdef V8_ENABLE_CHECKS
279 CheckCast(value);
280#endif
281 return static_cast<Float32Array*>(value);
282 }
283
284 private:
285 Float32Array();
286 static void CheckCast(Value* obj);
287};
288
293 public:
294 /*
295 * The largest Float64Array size that can be constructed using New.
296 */
297 static constexpr size_t kMaxLength =
298 TypedArray::kMaxByteLength / sizeof(double);
299 static_assert(sizeof(double) == 8);
300
302 size_t byte_offset, size_t length);
304#ifdef V8_ENABLE_CHECKS
305 CheckCast(value);
306#endif
307 return static_cast<Float64Array*>(value);
308 }
309
310 private:
311 Float64Array();
312 static void CheckCast(Value* obj);
313};
314
319 public:
320 /*
321 * The largest BigInt64Array size that can be constructed using New.
322 */
323 static constexpr size_t kMaxLength =
324 TypedArray::kMaxByteLength / sizeof(int64_t);
325 static_assert(sizeof(int64_t) == 8);
326
328 size_t byte_offset, size_t length);
330#ifdef V8_ENABLE_CHECKS
331 CheckCast(value);
332#endif
333 return static_cast<BigInt64Array*>(value);
334 }
335
336 private:
338 static void CheckCast(Value* obj);
339};
340
345 public:
346 /*
347 * The largest BigUint64Array size that can be constructed using New.
348 */
349 static constexpr size_t kMaxLength =
350 TypedArray::kMaxByteLength / sizeof(uint64_t);
351 static_assert(sizeof(uint64_t) == 8);
352
354 size_t byte_offset, size_t length);
356#ifdef V8_ENABLE_CHECKS
357 CheckCast(value);
358#endif
359 return static_cast<BigUint64Array*>(value);
360 }
361
362 private:
364 static void CheckCast(Value* obj);
365};
366
367} // namespace v8
368
369#endif // INCLUDE_V8_TYPED_ARRAY_H_
Definition: v8-array-buffer.h:472
Definition: v8-typed-array.h:318
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:329
Definition: v8-typed-array.h:344
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:355
Definition: v8-typed-array.h:244
static Float16Array * Cast(Value *value)
Definition: v8-typed-array.h:251
static Local< Float16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:266
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:277
Definition: v8-typed-array.h:292
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:303
Definition: v8-typed-array.h:166
static Int16Array * Cast(Value *value)
Definition: v8-typed-array.h:177
static Local< Int16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:218
static Int32Array * Cast(Value *value)
Definition: v8-typed-array.h:229
static Local< Int32Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:114
static Int8Array * Cast(Value *value)
Definition: v8-typed-array.h:125
static Local< Int8Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-isolate.h:305
Definition: v8-local-handle.h:356
Definition: v8-local-handle.h:724
Definition: v8-typed-array.h:21
static constexpr size_t kMaxByteLength
Definition: v8-typed-array.h:27
size_t Length()
static TypedArray * Cast(Value *value)
Definition: v8-typed-array.h:40
Definition: v8-typed-array.h:140
static Uint16Array * Cast(Value *value)
Definition: v8-typed-array.h:151
static Local< Uint16Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:192
static Uint32Array * Cast(Value *value)
Definition: v8-typed-array.h:203
static Local< Uint32Array > New(Local< ArrayBufferBase > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:55
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:73
static MaybeLocal< Uint8Array > MaybeNew(Isolate *isolate, std::span< const uint8_t > data)
Definition: v8-typed-array.h:88
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:99
Definition: v8-value.h:32
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:875
#define V8_INLINE
Definition: v8config.h:519