Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:15:23

0001 // Copyright 2021 the V8 project authors. All rights reserved.
0002 // Use of this source code is governed by a BSD-style license that can be
0003 // found in the LICENSE file.
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  * A base class for an instance of TypedArray series of constructors
0018  * (ES6 draft 15.13.6).
0019  */
0020 class V8_EXPORT TypedArray : public ArrayBufferView {
0021  public:
0022   /*
0023    * The largest supported typed array byte size. Each subclass defines a
0024    * type-specific kMaxLength for the maximum length that can be passed to New.
0025    */
0026   static constexpr size_t kMaxByteLength = ArrayBuffer::kMaxByteLength;
0027 
0028 #ifdef V8_ENABLE_SANDBOX
0029   static_assert(v8::TypedArray::kMaxByteLength <=
0030                 v8::internal::kMaxSafeBufferSizeForSandbox);
0031 #endif
0032 
0033   /**
0034    * Number of elements in this typed array
0035    * (e.g. for Int16Array, |ByteLength|/2).
0036    */
0037   size_t Length();
0038 
0039   V8_INLINE static TypedArray* Cast(Value* value) {
0040 #ifdef V8_ENABLE_CHECKS
0041     CheckCast(value);
0042 #endif
0043     return static_cast<TypedArray*>(value);
0044   }
0045 
0046  private:
0047   TypedArray();
0048   static void CheckCast(Value* obj);
0049 };
0050 
0051 /**
0052  * An instance of Uint8Array constructor (ES6 draft 15.13.6).
0053  */
0054 class V8_EXPORT Uint8Array : public TypedArray {
0055  public:
0056   /*
0057    * The largest Uint8Array size that can be constructed using New.
0058    */
0059   static constexpr size_t kMaxLength =
0060       TypedArray::kMaxByteLength / sizeof(uint8_t);
0061   static_assert(sizeof(uint8_t) == 1);
0062 
0063   static Local<Uint8Array> New(Local<ArrayBuffer> array_buffer,
0064                                size_t byte_offset, size_t length);
0065   static Local<Uint8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0066                                size_t byte_offset, size_t length);
0067   V8_INLINE static Uint8Array* Cast(Value* value) {
0068 #ifdef V8_ENABLE_CHECKS
0069     CheckCast(value);
0070 #endif
0071     return static_cast<Uint8Array*>(value);
0072   }
0073 
0074  private:
0075   Uint8Array();
0076   static void CheckCast(Value* obj);
0077 };
0078 
0079 /**
0080  * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6).
0081  */
0082 class V8_EXPORT Uint8ClampedArray : public TypedArray {
0083  public:
0084   /*
0085    * The largest Uint8ClampedArray size that can be constructed using New.
0086    */
0087   static constexpr size_t kMaxLength =
0088       TypedArray::kMaxByteLength / sizeof(uint8_t);
0089   static_assert(sizeof(uint8_t) == 1);
0090 
0091   static Local<Uint8ClampedArray> New(Local<ArrayBuffer> array_buffer,
0092                                       size_t byte_offset, size_t length);
0093   static Local<Uint8ClampedArray> New(
0094       Local<SharedArrayBuffer> shared_array_buffer, size_t byte_offset,
0095       size_t length);
0096   V8_INLINE static Uint8ClampedArray* Cast(Value* value) {
0097 #ifdef V8_ENABLE_CHECKS
0098     CheckCast(value);
0099 #endif
0100     return static_cast<Uint8ClampedArray*>(value);
0101   }
0102 
0103  private:
0104   Uint8ClampedArray();
0105   static void CheckCast(Value* obj);
0106 };
0107 
0108 /**
0109  * An instance of Int8Array constructor (ES6 draft 15.13.6).
0110  */
0111 class V8_EXPORT Int8Array : public TypedArray {
0112  public:
0113   /*
0114    * The largest Int8Array size that can be constructed using New.
0115    */
0116   static constexpr size_t kMaxLength =
0117       TypedArray::kMaxByteLength / sizeof(int8_t);
0118   static_assert(sizeof(int8_t) == 1);
0119 
0120   static Local<Int8Array> New(Local<ArrayBuffer> array_buffer,
0121                               size_t byte_offset, size_t length);
0122   static Local<Int8Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0123                               size_t byte_offset, size_t length);
0124   V8_INLINE static Int8Array* Cast(Value* value) {
0125 #ifdef V8_ENABLE_CHECKS
0126     CheckCast(value);
0127 #endif
0128     return static_cast<Int8Array*>(value);
0129   }
0130 
0131  private:
0132   Int8Array();
0133   static void CheckCast(Value* obj);
0134 };
0135 
0136 /**
0137  * An instance of Uint16Array constructor (ES6 draft 15.13.6).
0138  */
0139 class V8_EXPORT Uint16Array : public TypedArray {
0140  public:
0141   /*
0142    * The largest Uint16Array size that can be constructed using New.
0143    */
0144   static constexpr size_t kMaxLength =
0145       TypedArray::kMaxByteLength / sizeof(uint16_t);
0146   static_assert(sizeof(uint16_t) == 2);
0147 
0148   static Local<Uint16Array> New(Local<ArrayBuffer> array_buffer,
0149                                 size_t byte_offset, size_t length);
0150   static Local<Uint16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0151                                 size_t byte_offset, size_t length);
0152   V8_INLINE static Uint16Array* Cast(Value* value) {
0153 #ifdef V8_ENABLE_CHECKS
0154     CheckCast(value);
0155 #endif
0156     return static_cast<Uint16Array*>(value);
0157   }
0158 
0159  private:
0160   Uint16Array();
0161   static void CheckCast(Value* obj);
0162 };
0163 
0164 /**
0165  * An instance of Int16Array constructor (ES6 draft 15.13.6).
0166  */
0167 class V8_EXPORT Int16Array : public TypedArray {
0168  public:
0169   /*
0170    * The largest Int16Array size that can be constructed using New.
0171    */
0172   static constexpr size_t kMaxLength =
0173       TypedArray::kMaxByteLength / sizeof(int16_t);
0174   static_assert(sizeof(int16_t) == 2);
0175 
0176   static Local<Int16Array> New(Local<ArrayBuffer> array_buffer,
0177                                size_t byte_offset, size_t length);
0178   static Local<Int16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0179                                size_t byte_offset, size_t length);
0180   V8_INLINE static Int16Array* Cast(Value* value) {
0181 #ifdef V8_ENABLE_CHECKS
0182     CheckCast(value);
0183 #endif
0184     return static_cast<Int16Array*>(value);
0185   }
0186 
0187  private:
0188   Int16Array();
0189   static void CheckCast(Value* obj);
0190 };
0191 
0192 /**
0193  * An instance of Uint32Array constructor (ES6 draft 15.13.6).
0194  */
0195 class V8_EXPORT Uint32Array : public TypedArray {
0196  public:
0197   /*
0198    * The largest Uint32Array size that can be constructed using New.
0199    */
0200   static constexpr size_t kMaxLength =
0201       TypedArray::kMaxByteLength / sizeof(uint32_t);
0202   static_assert(sizeof(uint32_t) == 4);
0203 
0204   static Local<Uint32Array> New(Local<ArrayBuffer> array_buffer,
0205                                 size_t byte_offset, size_t length);
0206   static Local<Uint32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0207                                 size_t byte_offset, size_t length);
0208   V8_INLINE static Uint32Array* Cast(Value* value) {
0209 #ifdef V8_ENABLE_CHECKS
0210     CheckCast(value);
0211 #endif
0212     return static_cast<Uint32Array*>(value);
0213   }
0214 
0215  private:
0216   Uint32Array();
0217   static void CheckCast(Value* obj);
0218 };
0219 
0220 /**
0221  * An instance of Int32Array constructor (ES6 draft 15.13.6).
0222  */
0223 class V8_EXPORT Int32Array : public TypedArray {
0224  public:
0225   /*
0226    * The largest Int32Array size that can be constructed using New.
0227    */
0228   static constexpr size_t kMaxLength =
0229       TypedArray::kMaxByteLength / sizeof(int32_t);
0230   static_assert(sizeof(int32_t) == 4);
0231 
0232   static Local<Int32Array> New(Local<ArrayBuffer> array_buffer,
0233                                size_t byte_offset, size_t length);
0234   static Local<Int32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0235                                size_t byte_offset, size_t length);
0236   V8_INLINE static Int32Array* Cast(Value* value) {
0237 #ifdef V8_ENABLE_CHECKS
0238     CheckCast(value);
0239 #endif
0240     return static_cast<Int32Array*>(value);
0241   }
0242 
0243  private:
0244   Int32Array();
0245   static void CheckCast(Value* obj);
0246 };
0247 
0248 /**
0249  * An instance of Float16Array constructor.
0250  */
0251 class V8_EXPORT Float16Array : public TypedArray {
0252  public:
0253   static constexpr size_t kMaxLength =
0254       TypedArray::kMaxByteLength / sizeof(uint16_t);
0255 
0256   static Local<Float16Array> New(Local<ArrayBuffer> array_buffer,
0257                                  size_t byte_offset, size_t length);
0258   static Local<Float16Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0259                                  size_t byte_offset, size_t length);
0260   V8_INLINE static Float16Array* Cast(Value* value) {
0261 #ifdef V8_ENABLE_CHECKS
0262     CheckCast(value);
0263 #endif
0264     return static_cast<Float16Array*>(value);
0265   }
0266 
0267  private:
0268   Float16Array();
0269   static void CheckCast(Value* obj);
0270 };
0271 
0272 /**
0273  * An instance of Float32Array constructor (ES6 draft 15.13.6).
0274  */
0275 class V8_EXPORT Float32Array : public TypedArray {
0276  public:
0277   /*
0278    * The largest Float32Array size that can be constructed using New.
0279    */
0280   static constexpr size_t kMaxLength =
0281       TypedArray::kMaxByteLength / sizeof(float);
0282   static_assert(sizeof(float) == 4);
0283 
0284   static Local<Float32Array> New(Local<ArrayBuffer> array_buffer,
0285                                  size_t byte_offset, size_t length);
0286   static Local<Float32Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0287                                  size_t byte_offset, size_t length);
0288   V8_INLINE static Float32Array* Cast(Value* value) {
0289 #ifdef V8_ENABLE_CHECKS
0290     CheckCast(value);
0291 #endif
0292     return static_cast<Float32Array*>(value);
0293   }
0294 
0295  private:
0296   Float32Array();
0297   static void CheckCast(Value* obj);
0298 };
0299 
0300 /**
0301  * An instance of Float64Array constructor (ES6 draft 15.13.6).
0302  */
0303 class V8_EXPORT Float64Array : public TypedArray {
0304  public:
0305   /*
0306    * The largest Float64Array size that can be constructed using New.
0307    */
0308   static constexpr size_t kMaxLength =
0309       TypedArray::kMaxByteLength / sizeof(double);
0310   static_assert(sizeof(double) == 8);
0311 
0312   static Local<Float64Array> New(Local<ArrayBuffer> array_buffer,
0313                                  size_t byte_offset, size_t length);
0314   static Local<Float64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0315                                  size_t byte_offset, size_t length);
0316   V8_INLINE static Float64Array* Cast(Value* value) {
0317 #ifdef V8_ENABLE_CHECKS
0318     CheckCast(value);
0319 #endif
0320     return static_cast<Float64Array*>(value);
0321   }
0322 
0323  private:
0324   Float64Array();
0325   static void CheckCast(Value* obj);
0326 };
0327 
0328 /**
0329  * An instance of BigInt64Array constructor.
0330  */
0331 class V8_EXPORT BigInt64Array : public TypedArray {
0332  public:
0333   /*
0334    * The largest BigInt64Array size that can be constructed using New.
0335    */
0336   static constexpr size_t kMaxLength =
0337       TypedArray::kMaxByteLength / sizeof(int64_t);
0338   static_assert(sizeof(int64_t) == 8);
0339 
0340   static Local<BigInt64Array> New(Local<ArrayBuffer> array_buffer,
0341                                   size_t byte_offset, size_t length);
0342   static Local<BigInt64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0343                                   size_t byte_offset, size_t length);
0344   V8_INLINE static BigInt64Array* Cast(Value* value) {
0345 #ifdef V8_ENABLE_CHECKS
0346     CheckCast(value);
0347 #endif
0348     return static_cast<BigInt64Array*>(value);
0349   }
0350 
0351  private:
0352   BigInt64Array();
0353   static void CheckCast(Value* obj);
0354 };
0355 
0356 /**
0357  * An instance of BigUint64Array constructor.
0358  */
0359 class V8_EXPORT BigUint64Array : public TypedArray {
0360  public:
0361   /*
0362    * The largest BigUint64Array size that can be constructed using New.
0363    */
0364   static constexpr size_t kMaxLength =
0365       TypedArray::kMaxByteLength / sizeof(uint64_t);
0366   static_assert(sizeof(uint64_t) == 8);
0367 
0368   static Local<BigUint64Array> New(Local<ArrayBuffer> array_buffer,
0369                                    size_t byte_offset, size_t length);
0370   static Local<BigUint64Array> New(Local<SharedArrayBuffer> shared_array_buffer,
0371                                    size_t byte_offset, size_t length);
0372   V8_INLINE static BigUint64Array* Cast(Value* value) {
0373 #ifdef V8_ENABLE_CHECKS
0374     CheckCast(value);
0375 #endif
0376     return static_cast<BigUint64Array*>(value);
0377   }
0378 
0379  private:
0380   BigUint64Array();
0381   static void CheckCast(Value* obj);
0382 };
0383 
0384 }  // namespace v8
0385 
0386 #endif  // INCLUDE_V8_TYPED_ARRAY_H_