v8 14.1.146 (node 25.0.0)
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
16/**
17 * A base class for an instance of TypedArray series of constructors
18 * (ES6 draft 15.13.6).
19 */
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 */
27
28#ifdef V8_ENABLE_SANDBOX
29 static_assert(v8::TypedArray::kMaxByteLength <=
31#endif
32
33 /**
34 * Number of elements in this typed array
35 * (e.g. for Int16Array, |ByteLength|/2).
36 */
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
51/**
52 * An instance of Uint8Array constructor (ES6 draft 15.13.6).
53 */
55 public:
56 /*
57 * The largest Uint8Array size that can be constructed using New.
58 */
59 static constexpr size_t kMaxLength =
61 static_assert(sizeof(uint8_t) == 1);
62
63 static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
64 size_t byte_offset, size_t length);
65 static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
79/**
80 * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
81 */
83 public:
84 /*
85 * The largest Uint8ClampedArray size that can be constructed using New.
86 */
87 static constexpr size_t kMaxLength =
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:
104 Uint8ClampedArray();
105 static void CheckCast(Value* obj);
106};
107
108/**
109 * An instance of Int8Array constructor (ES6 draft 15.13.6).
110 */
112 public:
113 /*
114 * The largest Int8Array size that can be constructed using New.
115 */
116 static constexpr size_t kMaxLength =
118 static_assert(sizeof(int8_t) == 1);
119
120 static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
121 size_t byte_offset, size_t length);
122 static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
136/**
137 * An instance of Uint16Array constructor (ES6 draft 15.13.6).
138 */
140 public:
141 /*
142 * The largest Uint16Array size that can be constructed using New.
143 */
144 static constexpr size_t kMaxLength =
146 static_assert(sizeof(uint16_t) == 2);
147
148 static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
149 size_t byte_offset, size_t length);
150 static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
164/**
165 * An instance of Int16Array constructor (ES6 draft 15.13.6).
166 */
168 public:
169 /*
170 * The largest Int16Array size that can be constructed using New.
171 */
172 static constexpr size_t kMaxLength =
174 static_assert(sizeof(int16_t) == 2);
175
176 static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
177 size_t byte_offset, size_t length);
178 static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
192/**
193 * An instance of Uint32Array constructor (ES6 draft 15.13.6).
194 */
196 public:
197 /*
198 * The largest Uint32Array size that can be constructed using New.
199 */
200 static constexpr size_t kMaxLength =
202 static_assert(sizeof(uint32_t) == 4);
203
204 static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
205 size_t byte_offset, size_t length);
206 static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
220/**
221 * An instance of Int32Array constructor (ES6 draft 15.13.6).
222 */
224 public:
225 /*
226 * The largest Int32Array size that can be constructed using New.
227 */
228 static constexpr size_t kMaxLength =
230 static_assert(sizeof(int32_t) == 4);
231
232 static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
233 size_t byte_offset, size_t length);
234 static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
248/**
249 * An instance of Float16Array constructor.
250 */
252 public:
253 static constexpr size_t kMaxLength =
255
256 static Local<Float16Array> New(Local<ArrayBuffer> array_buffer,
257 size_t byte_offset, size_t length);
258 static Local<Float16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
272/**
273 * An instance of Float32Array constructor (ES6 draft 15.13.6).
274 */
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
284 static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
285 size_t byte_offset, size_t length);
286 static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
300/**
301 * An instance of Float64Array constructor (ES6 draft 15.13.6).
302 */
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
312 static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
313 size_t byte_offset, size_t length);
314 static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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
328/**
329 * An instance of BigInt64Array constructor.
330 */
332 public:
333 /*
334 * The largest BigInt64Array size that can be constructed using New.
335 */
336 static constexpr size_t kMaxLength =
338 static_assert(sizeof(int64_t) == 8);
339
340 static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
341 size_t byte_offset, size_t length);
342 static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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:
352 BigInt64Array();
353 static void CheckCast(Value* obj);
354};
355
356/**
357 * An instance of BigUint64Array constructor.
358 */
360 public:
361 /*
362 * The largest BigUint64Array size that can be constructed using New.
363 */
364 static constexpr size_t kMaxLength =
366 static_assert(sizeof(uint64_t) == 8);
367
368 static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
369 size_t byte_offset, size_t length);
370 static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
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:
380 BigUint64Array();
381 static void CheckCast(Value* obj);
382};
383
384} // namespace v8
385
386#endif // INCLUDE_V8_TYPED_ARRAY_H_
static constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
static Local< Float16Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
static V8_INLINE Float16Array * Cast(Value *value)
static constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
static V8_INLINE Int16Array * Cast(Value *value)
static V8_INLINE Int32Array * Cast(Value *value)
static constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
static V8_INLINE Int8Array * Cast(Value *value)
static Local< Int8Array > New(Local< SharedArrayBuffer > shared_array_buffer, size_t byte_offset, size_t length)
friend class Local
static V8_INLINE TypedArray * Cast(Value *value)
size_t Length()
static constexpr size_t kMaxByteLength
static Local< Uint16Array > New(Local< ArrayBuffer > array_buffer, size_t byte_offset, size_t length)
static constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
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 constexpr size_t kMaxLength
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:860
#define V8_INLINE
Definition v8config.h:513