File indexing completed on 2025-02-22 10:42:35
0001
0002
0003
0004
0005 #ifndef INCLUDE_V8_TYPED_ARRAY_H_
0006 #define INCLUDE_V8_TYPED_ARRAY_H_
0007
0008 #include <limits>
0009
0010 #include "v8-array-buffer.h" // NOLINT(build/include_directory)
0011 #include "v8-local-handle.h" // NOLINT(build/include_directory)
0012 #include "v8config.h" // NOLINT(build/include_directory)
0013
0014 namespace v8 {
0015
0016
0017
0018
0019
0020 class V8_EXPORT TypedArray : public ArrayBufferView {
0021 public:
0022
0023
0024
0025
0026 #if V8_ENABLE_SANDBOX
0027 static constexpr size_t kMaxByteLength =
0028 internal::kMaxSafeBufferSizeForSandbox;
0029 #elif V8_HOST_ARCH_32_BIT
0030 static constexpr size_t kMaxByteLength = std::numeric_limits<int>::max();
0031 #else
0032
0033 static constexpr size_t kMaxByteLength =
0034 static_cast<size_t>((uint64_t{1} << 53) - 1);
0035 #endif
0036
0037
0038
0039
0040
0041 size_t Length();
0042
0043 V8_INLINE static TypedArray* Cast(Value* value) {
0044 #ifdef V8_ENABLE_CHECKS
0045 CheckCast(value);
0046 #endif
0047 return static_cast<TypedArray*>(value);
0048 }
0049
0050 private:
0051 TypedArray();
0052 static void CheckCast(Value* obj);
0053 };
0054
0055
0056
0057
0058 class V8_EXPORT Uint8Array : public TypedArray {
0059 public:
0060
0061
0062
0063 static constexpr size_t kMaxLength =
0064 TypedArray::kMaxByteLength / sizeof(uint8_t);
0065 static_assert(sizeof(uint8_t) == 1);
0066
0067 static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
0068 size_t byte_offset, size_t length);
0069 static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0070 size_t byte_offset, size_t length);
0071 V8_INLINE static Uint8Array* Cast(Value* value) {
0072 #ifdef V8_ENABLE_CHECKS
0073 CheckCast(value);
0074 #endif
0075 return static_cast<Uint8Array*>(value);
0076 }
0077
0078 private:
0079 Uint8Array();
0080 static void CheckCast(Value* obj);
0081 };
0082
0083
0084
0085
0086 class V8_EXPORT Uint8ClampedArray : public TypedArray {
0087 public:
0088
0089
0090
0091 static constexpr size_t kMaxLength =
0092 TypedArray::kMaxByteLength / sizeof(uint8_t);
0093 static_assert(sizeof(uint8_t) == 1);
0094
0095 static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
0096 size_t byte_offset, size_t length);
0097 static Local<Uint8ClampedArray> New(
0098 Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
0099 size_t length);
0100 V8_INLINE static Uint8ClampedArray* Cast(Value* value) {
0101 #ifdef V8_ENABLE_CHECKS
0102 CheckCast(value);
0103 #endif
0104 return static_cast<Uint8ClampedArray*>(value);
0105 }
0106
0107 private:
0108 Uint8ClampedArray();
0109 static void CheckCast(Value* obj);
0110 };
0111
0112
0113
0114
0115 class V8_EXPORT Int8Array : public TypedArray {
0116 public:
0117
0118
0119
0120 static constexpr size_t kMaxLength =
0121 TypedArray::kMaxByteLength / sizeof(int8_t);
0122 static_assert(sizeof(int8_t) == 1);
0123
0124 static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
0125 size_t byte_offset, size_t length);
0126 static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0127 size_t byte_offset, size_t length);
0128 V8_INLINE static Int8Array* Cast(Value* value) {
0129 #ifdef V8_ENABLE_CHECKS
0130 CheckCast(value);
0131 #endif
0132 return static_cast<Int8Array*>(value);
0133 }
0134
0135 private:
0136 Int8Array();
0137 static void CheckCast(Value* obj);
0138 };
0139
0140
0141
0142
0143 class V8_EXPORT Uint16Array : public TypedArray {
0144 public:
0145
0146
0147
0148 static constexpr size_t kMaxLength =
0149 TypedArray::kMaxByteLength / sizeof(uint16_t);
0150 static_assert(sizeof(uint16_t) == 2);
0151
0152 static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
0153 size_t byte_offset, size_t length);
0154 static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0155 size_t byte_offset, size_t length);
0156 V8_INLINE static Uint16Array* Cast(Value* value) {
0157 #ifdef V8_ENABLE_CHECKS
0158 CheckCast(value);
0159 #endif
0160 return static_cast<Uint16Array*>(value);
0161 }
0162
0163 private:
0164 Uint16Array();
0165 static void CheckCast(Value* obj);
0166 };
0167
0168
0169
0170
0171 class V8_EXPORT Int16Array : public TypedArray {
0172 public:
0173
0174
0175
0176 static constexpr size_t kMaxLength =
0177 TypedArray::kMaxByteLength / sizeof(int16_t);
0178 static_assert(sizeof(int16_t) == 2);
0179
0180 static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
0181 size_t byte_offset, size_t length);
0182 static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0183 size_t byte_offset, size_t length);
0184 V8_INLINE static Int16Array* Cast(Value* value) {
0185 #ifdef V8_ENABLE_CHECKS
0186 CheckCast(value);
0187 #endif
0188 return static_cast<Int16Array*>(value);
0189 }
0190
0191 private:
0192 Int16Array();
0193 static void CheckCast(Value* obj);
0194 };
0195
0196
0197
0198
0199 class V8_EXPORT Uint32Array : public TypedArray {
0200 public:
0201
0202
0203
0204 static constexpr size_t kMaxLength =
0205 TypedArray::kMaxByteLength / sizeof(uint32_t);
0206 static_assert(sizeof(uint32_t) == 4);
0207
0208 static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
0209 size_t byte_offset, size_t length);
0210 static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0211 size_t byte_offset, size_t length);
0212 V8_INLINE static Uint32Array* Cast(Value* value) {
0213 #ifdef V8_ENABLE_CHECKS
0214 CheckCast(value);
0215 #endif
0216 return static_cast<Uint32Array*>(value);
0217 }
0218
0219 private:
0220 Uint32Array();
0221 static void CheckCast(Value* obj);
0222 };
0223
0224
0225
0226
0227 class V8_EXPORT Int32Array : public TypedArray {
0228 public:
0229
0230
0231
0232 static constexpr size_t kMaxLength =
0233 TypedArray::kMaxByteLength / sizeof(int32_t);
0234 static_assert(sizeof(int32_t) == 4);
0235
0236 static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
0237 size_t byte_offset, size_t length);
0238 static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0239 size_t byte_offset, size_t length);
0240 V8_INLINE static Int32Array* Cast(Value* value) {
0241 #ifdef V8_ENABLE_CHECKS
0242 CheckCast(value);
0243 #endif
0244 return static_cast<Int32Array*>(value);
0245 }
0246
0247 private:
0248 Int32Array();
0249 static void CheckCast(Value* obj);
0250 };
0251
0252
0253
0254
0255 class V8_EXPORT Float16Array : public TypedArray {
0256 static constexpr size_t kMaxLength =
0257 TypedArray::kMaxByteLength / sizeof(uint16_t);
0258
0259 public:
0260 static Local<Float16Array> New(Local<ArrayBuffer> array_buffer,
0261 size_t byte_offset, size_t length);
0262 static Local<Float16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0263 size_t byte_offset, size_t length);
0264 V8_INLINE static Float16Array* Cast(Value* value) {
0265 #ifdef V8_ENABLE_CHECKS
0266 CheckCast(value);
0267 #endif
0268 return static_cast<Float16Array*>(value);
0269 }
0270
0271 private:
0272 Float16Array();
0273 static void CheckCast(Value* obj);
0274 };
0275
0276
0277
0278
0279 class V8_EXPORT Float32Array : public TypedArray {
0280 public:
0281
0282
0283
0284 static constexpr size_t kMaxLength =
0285 TypedArray::kMaxByteLength / sizeof(float);
0286 static_assert(sizeof(float) == 4);
0287
0288 static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
0289 size_t byte_offset, size_t length);
0290 static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0291 size_t byte_offset, size_t length);
0292 V8_INLINE static Float32Array* Cast(Value* value) {
0293 #ifdef V8_ENABLE_CHECKS
0294 CheckCast(value);
0295 #endif
0296 return static_cast<Float32Array*>(value);
0297 }
0298
0299 private:
0300 Float32Array();
0301 static void CheckCast(Value* obj);
0302 };
0303
0304
0305
0306
0307 class V8_EXPORT Float64Array : public TypedArray {
0308 public:
0309
0310
0311
0312 static constexpr size_t kMaxLength =
0313 TypedArray::kMaxByteLength / sizeof(double);
0314 static_assert(sizeof(double) == 8);
0315
0316 static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
0317 size_t byte_offset, size_t length);
0318 static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0319 size_t byte_offset, size_t length);
0320 V8_INLINE static Float64Array* Cast(Value* value) {
0321 #ifdef V8_ENABLE_CHECKS
0322 CheckCast(value);
0323 #endif
0324 return static_cast<Float64Array*>(value);
0325 }
0326
0327 private:
0328 Float64Array();
0329 static void CheckCast(Value* obj);
0330 };
0331
0332
0333
0334
0335 class V8_EXPORT BigInt64Array : public TypedArray {
0336 public:
0337
0338
0339
0340 static constexpr size_t kMaxLength =
0341 TypedArray::kMaxByteLength / sizeof(int64_t);
0342 static_assert(sizeof(int64_t) == 8);
0343
0344 static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
0345 size_t byte_offset, size_t length);
0346 static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0347 size_t byte_offset, size_t length);
0348 V8_INLINE static BigInt64Array* Cast(Value* value) {
0349 #ifdef V8_ENABLE_CHECKS
0350 CheckCast(value);
0351 #endif
0352 return static_cast<BigInt64Array*>(value);
0353 }
0354
0355 private:
0356 BigInt64Array();
0357 static void CheckCast(Value* obj);
0358 };
0359
0360
0361
0362
0363 class V8_EXPORT BigUint64Array : public TypedArray {
0364 public:
0365
0366
0367
0368 static constexpr size_t kMaxLength =
0369 TypedArray::kMaxByteLength / sizeof(uint64_t);
0370 static_assert(sizeof(uint64_t) == 8);
0371
0372 static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
0373 size_t byte_offset, size_t length);
0374 static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0375 size_t byte_offset, size_t length);
0376 V8_INLINE static BigUint64Array* Cast(Value* value) {
0377 #ifdef V8_ENABLE_CHECKS
0378 CheckCast(value);
0379 #endif
0380 return static_cast<BigUint64Array*>(value);
0381 }
0382
0383 private:
0384 BigUint64Array();
0385 static void CheckCast(Value* obj);
0386 };
0387
0388 }
0389
0390 #endif