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);
66 size_t byte_offset, size_t length);
67 V8_INLINE static Uint8Array* Cast(Value* value) {
68#ifdef V8_ENABLE_CHECKS
69 CheckCast(value);
70#endif
71 return static_cast<Uint8Array*>(value);
72 }
73
74 private:
75 Uint8Array();
76 static void CheckCast(Value* obj);
77};
78
83 public:
84 /*
85 * The largest Uint8ClampedArray size that can be constructed using New.
86 */
87 static constexpr size_t kMaxLength =
88 TypedArray::kMaxByteLength / sizeof(uint8_t);
89 static_assert(sizeof(uint8_t) == 1);
90
92 size_t byte_offset, size_t length);
94 Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
95 size_t length);
97#ifdef V8_ENABLE_CHECKS
98 CheckCast(value);
99#endif
100 return static_cast<Uint8ClampedArray*>(value);
101 }
102
103 private:
105 static void CheckCast(Value* obj);
106};
107
112 public:
113 /*
114 * The largest Int8Array size that can be constructed using New.
115 */
116 static constexpr size_t kMaxLength =
117 TypedArray::kMaxByteLength / sizeof(int8_t);
118 static_assert(sizeof(int8_t) == 1);
119
121 size_t byte_offset, size_t length);
123 size_t byte_offset, size_t length);
124 V8_INLINE static Int8Array* Cast(Value* value) {
125#ifdef V8_ENABLE_CHECKS
126 CheckCast(value);
127#endif
128 return static_cast<Int8Array*>(value);
129 }
130
131 private:
132 Int8Array();
133 static void CheckCast(Value* obj);
134};
135
140 public:
141 /*
142 * The largest Uint16Array size that can be constructed using New.
143 */
144 static constexpr size_t kMaxLength =
145 TypedArray::kMaxByteLength / sizeof(uint16_t);
146 static_assert(sizeof(uint16_t) == 2);
147
149 size_t byte_offset, size_t length);
151 size_t byte_offset, size_t length);
152 V8_INLINE static Uint16Array* Cast(Value* value) {
153#ifdef V8_ENABLE_CHECKS
154 CheckCast(value);
155#endif
156 return static_cast<Uint16Array*>(value);
157 }
158
159 private:
160 Uint16Array();
161 static void CheckCast(Value* obj);
162};
163
168 public:
169 /*
170 * The largest Int16Array size that can be constructed using New.
171 */
172 static constexpr size_t kMaxLength =
173 TypedArray::kMaxByteLength / sizeof(int16_t);
174 static_assert(sizeof(int16_t) == 2);
175
177 size_t byte_offset, size_t length);
179 size_t byte_offset, size_t length);
180 V8_INLINE static Int16Array* Cast(Value* value) {
181#ifdef V8_ENABLE_CHECKS
182 CheckCast(value);
183#endif
184 return static_cast<Int16Array*>(value);
185 }
186
187 private:
188 Int16Array();
189 static void CheckCast(Value* obj);
190};
191
196 public:
197 /*
198 * The largest Uint32Array size that can be constructed using New.
199 */
200 static constexpr size_t kMaxLength =
201 TypedArray::kMaxByteLength / sizeof(uint32_t);
202 static_assert(sizeof(uint32_t) == 4);
203
205 size_t byte_offset, size_t length);
207 size_t byte_offset, size_t length);
208 V8_INLINE static Uint32Array* Cast(Value* value) {
209#ifdef V8_ENABLE_CHECKS
210 CheckCast(value);
211#endif
212 return static_cast<Uint32Array*>(value);
213 }
214
215 private:
216 Uint32Array();
217 static void CheckCast(Value* obj);
218};
219
224 public:
225 /*
226 * The largest Int32Array size that can be constructed using New.
227 */
228 static constexpr size_t kMaxLength =
229 TypedArray::kMaxByteLength / sizeof(int32_t);
230 static_assert(sizeof(int32_t) == 4);
231
233 size_t byte_offset, size_t length);
235 size_t byte_offset, size_t length);
236 V8_INLINE static Int32Array* Cast(Value* value) {
237#ifdef V8_ENABLE_CHECKS
238 CheckCast(value);
239#endif
240 return static_cast<Int32Array*>(value);
241 }
242
243 private:
244 Int32Array();
245 static void CheckCast(Value* obj);
246};
247
252 public:
253 static constexpr size_t kMaxLength =
254 TypedArray::kMaxByteLength / sizeof(uint16_t);
255
257 size_t byte_offset, size_t length);
259 size_t byte_offset, size_t length);
261#ifdef V8_ENABLE_CHECKS
262 CheckCast(value);
263#endif
264 return static_cast<Float16Array*>(value);
265 }
266
267 private:
268 Float16Array();
269 static void CheckCast(Value* obj);
270};
271
276 public:
277 /*
278 * The largest Float32Array size that can be constructed using New.
279 */
280 static constexpr size_t kMaxLength =
281 TypedArray::kMaxByteLength / sizeof(float);
282 static_assert(sizeof(float) == 4);
283
285 size_t byte_offset, size_t length);
287 size_t byte_offset, size_t length);
289#ifdef V8_ENABLE_CHECKS
290 CheckCast(value);
291#endif
292 return static_cast<Float32Array*>(value);
293 }
294
295 private:
296 Float32Array();
297 static void CheckCast(Value* obj);
298};
299
304 public:
305 /*
306 * The largest Float64Array size that can be constructed using New.
307 */
308 static constexpr size_t kMaxLength =
309 TypedArray::kMaxByteLength / sizeof(double);
310 static_assert(sizeof(double) == 8);
311
313 size_t byte_offset, size_t length);
315 size_t byte_offset, size_t length);
317#ifdef V8_ENABLE_CHECKS
318 CheckCast(value);
319#endif
320 return static_cast<Float64Array*>(value);
321 }
322
323 private:
324 Float64Array();
325 static void CheckCast(Value* obj);
326};
327
332 public:
333 /*
334 * The largest BigInt64Array size that can be constructed using New.
335 */
336 static constexpr size_t kMaxLength =
337 TypedArray::kMaxByteLength / sizeof(int64_t);
338 static_assert(sizeof(int64_t) == 8);
339
341 size_t byte_offset, size_t length);
343 size_t byte_offset, size_t length);
345#ifdef V8_ENABLE_CHECKS
346 CheckCast(value);
347#endif
348 return static_cast<BigInt64Array*>(value);
349 }
350
351 private:
353 static void CheckCast(Value* obj);
354};
355
360 public:
361 /*
362 * The largest BigUint64Array size that can be constructed using New.
363 */
364 static constexpr size_t kMaxLength =
365 TypedArray::kMaxByteLength / sizeof(uint64_t);
366 static_assert(sizeof(uint64_t) == 8);
367
369 size_t byte_offset, size_t length);
371 size_t byte_offset, size_t length);
373#ifdef V8_ENABLE_CHECKS
374 CheckCast(value);
375#endif
376 return static_cast<BigUint64Array*>(value);
377 }
378
379 private:
381 static void CheckCast(Value* obj);
382};
383
384} // namespace v8
385
386#endif // INCLUDE_V8_TYPED_ARRAY_H_
Definition: v8-array-buffer.h:417
Definition: v8-typed-array.h:331
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:344
Definition: v8-typed-array.h:359
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:372
Definition: v8-typed-array.h:251
static Local< Float16Array > New(Local< SharedArrayBuffer > shared_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 Float16Array * Cast(Value *value)
Definition: v8-typed-array.h:260
Definition: v8-typed-array.h:275
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:288
Definition: v8-typed-array.h:303
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:316
Definition: v8-typed-array.h:167
static Int16Array * Cast(Value *value)
Definition: v8-typed-array.h:180
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:223
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:236
static Local< Int32Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:111
static Int8Array * Cast(Value *value)
Definition: v8-typed-array.h:124
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:266
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:139
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:152
static Local< Uint16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
Definition: v8-typed-array.h:195
static Uint32Array * Cast(Value *value)
Definition: v8-typed-array.h:208
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:54
static Uint8Array * Cast(Value *value)
Definition: v8-typed-array.h:67
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:82
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:96
Definition: v8-value.h:32
Definition: libplatform.h:15
#define V8_EXPORT
Definition: v8config.h:803
#define V8_INLINE
Definition: v8config.h:499