5#ifndef INCLUDE_V8_PRIMITIVE_H_
6#define INCLUDE_V8_PRIMITIVE_H_
22class ScopedExternalStringLock;
23class StringForwardingTable;
39#ifdef V8_ENABLE_CHECKS
42 return static_cast<Boolean*
>(data);
48 static void CheckCast(
v8::Data* that);
66#ifdef V8_ENABLE_CHECKS
73 static void CheckCast(
Data* obj);
91#ifdef V8_ENABLE_CHECKS
94 return static_cast<Name*
>(data);
98 static void CheckCast(
Data* that);
126 static constexpr int kMaxLength =
127 internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
130 UNKNOWN_ENCODING = 0x1,
131 TWO_BYTE_ENCODING = 0x0,
132 ONE_BYTE_ENCODING = 0x8
157 bool IsOneByte() const;
164 bool ContainsOnlyOneByte() const;
193 HINT_MANY_WRITES_EXPECTED = 1,
194 NO_NULL_TERMINATION = 2,
195 PRESERVE_ONE_BYTE_NULL = 4,
199 REPLACE_INVALID_UTF8 = 8
204 int Write(
Isolate* isolate, uint16_t* buffer,
int start = 0,
int length = -1,
205 int options = NO_OPTIONS) const;
208 int WriteOneByte(
Isolate* isolate, uint8_t* buffer,
int start = 0,
209 int length = -1,
int options = NO_OPTIONS) const;
212 int WriteUtf8(
Isolate* isolate,
char* buffer,
int length = -1,
213 int* nchars_ref =
nullptr,
int options = NO_OPTIONS) const;
225 kReplaceInvalidUtf8 = 2
242 uint16_t* buffer,
int flags = WriteFlags::kNone)
const;
244 uint8_t* buffer,
int flags = WriteFlags::kNone)
const;
264 int flags = WriteFlags::kNone)
const;
344 friend class internal::ExternalString;
346 friend class internal::StringForwardingTable;
347 friend class internal::ScopedExternalStringLock;
368 virtual const uint16_t*
data()
const = 0;
381 CheckCachedDataInvariants();
395 void CheckCachedDataInvariants()
const;
397 const uint16_t* cached_data_ =
nullptr;
423 virtual const char*
data()
const = 0;
434 CheckCachedDataInvariants();
448 void CheckCachedDataInvariants()
const;
450 const char* cached_data_ =
nullptr;
476#ifdef V8_ENABLE_CHECKS
479 return static_cast<String*
>(data);
493 Isolate* isolate,
const char (&literal)[N],
495 static_assert(N <= kMaxLength,
"String is too long");
496 return NewFromUtf8Literal(isolate, literal, type, N - 1);
502 Isolate* isolate,
const char* data,
503 NewStringType type = NewStringType::kNormal,
int length = -1);
508 Isolate* isolate,
const uint8_t* data,
509 NewStringType type = NewStringType::kNormal,
int length = -1);
514 Isolate* isolate,
const uint16_t* data,
515 NewStringType type = NewStringType::kNormal,
int length = -1);
621 size_t length()
const {
return length_; }
645 "Prefer using String::ValueView if you can, or string->Write to a "
646 "buffer if you cannot.")
649 uint16_t* operator*() {
return str_; }
651 uint32_t
length()
const {
return length_; }
688 uint32_t
length()
const {
return length_; }
696 void CheckOneByte(
bool is_one_byte)
const;
706 alignas(internal::Internals::
707 kDisallowGarbageCollectionAlign)
char no_gc_debug_scope_
708 [internal::Internals::kDisallowGarbageCollectionSize];
712 void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
713 Encoding encoding)
const;
714 void VerifyExternalStringResource(ExternalStringResource* val)
const;
715 ExternalStringResource* GetExternalStringResourceSlow()
const;
716 ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
723 static void CheckCast(
v8::Data* that);
790#ifdef V8_ENABLE_CHECKS
793 return static_cast<Symbol*
>(data);
798 static void CheckCast(
Data* that);
808 static void CheckCast(
v8::Data* that);
819#ifdef V8_ENABLE_CHECKS
822 return static_cast<Number*
>(data);
827 static void CheckCast(
v8::Data* that);
839#ifdef V8_ENABLE_CHECKS
842 return static_cast<Integer*
>(data);
847 static void CheckCast(
v8::Data* that);
857#ifdef V8_ENABLE_CHECKS
860 return static_cast<Int32*
>(data);
865 static void CheckCast(
v8::Data* that);
875#ifdef V8_ENABLE_CHECKS
878 return static_cast<Uint32*
>(data);
883 static void CheckCast(
v8::Data* that);
901 int word_count,
const uint64_t* words);
932 void ToWordsArray(
int* sign_bit,
int* word_count, uint64_t* words)
const;
935#ifdef V8_ENABLE_CHECKS
938 return static_cast<BigInt*
>(data);
943 static void CheckCast(
v8::Data* that);
949 I::CheckInitialized(isolate);
950 S* slot = I::GetRootSlot(isolate, I::kEmptyStringRootIndex);
960 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
961 Isolate* isolate = I::GetIsolateForSandbox(obj);
962 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
963 isolate, obj, I::kStringResourceOffset);
966 result = GetExternalStringResourceSlow();
968#ifdef V8_ENABLE_CHECKS
969 VerifyExternalStringResource(result);
979 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
980 *encoding_out =
static_cast<Encoding>(type & I::kStringEncodingMask);
982 if (type == I::kExternalOneByteRepresentationTag ||
983 type == I::kExternalTwoByteRepresentationTag) {
984 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
985 isolate, obj, I::kStringResourceOffset);
988 resource = GetExternalStringResourceBaseSlow(encoding_out);
990#ifdef V8_ENABLE_CHECKS
991 VerifyExternalStringResourceBase(resource, *encoding_out);
1001 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
1002 *encoding_out =
static_cast<Encoding>(type & I::kStringEncodingMask);
1004 if (type == I::kExternalOneByteRepresentationTag ||
1005 type == I::kExternalTwoByteRepresentationTag) {
1006 Isolate* isolate = I::GetIsolateForSandbox(obj);
1007 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
1008 isolate, obj, I::kStringResourceOffset);
1011 resource = GetExternalStringResourceBaseSlow(encoding_out);
1013#ifdef V8_ENABLE_CHECKS
1014 VerifyExternalStringResourceBase(resource, *encoding_out);
1024 I::CheckInitialized(isolate);
1025 S* slot = I::GetRootSlot(isolate, I::kUndefinedValueRootIndex);
1032 I::CheckInitialized(isolate);
1033 S* slot = I::GetRootSlot(isolate, I::kNullValueRootIndex);
1040 I::CheckInitialized(isolate);
1041 S* slot = I::GetRootSlot(isolate, I::kTrueValueRootIndex);
1048 I::CheckInitialized(isolate);
1049 S* slot = I::GetRootSlot(isolate, I::kFalseValueRootIndex);
1054 return value ?
True(isolate) :
False(isolate);
Definition: v8-primitive.h:889
uint64_t Uint64Value(bool *lossless=nullptr) const
static BigInt * Cast(v8::Data *data)
Definition: v8-primitive.h:934
static Local< BigInt > New(Isolate *isolate, int64_t value)
int64_t Int64Value(bool *lossless=nullptr) const
static MaybeLocal< BigInt > NewFromWords(Local< Context > context, int sign_bit, int word_count, const uint64_t *words)
static Local< BigInt > NewFromUnsigned(Isolate *isolate, uint64_t value)
void ToWordsArray(int *sign_bit, int *word_count, uint64_t *words) const
Definition: v8-primitive.h:35
static Local< Boolean > New(Isolate *isolate, bool value)
Definition: v8-primitive.h:1053
static Boolean * Cast(v8::Data *data)
Definition: v8-primitive.h:38
Definition: v8-primitive.h:737
virtual ~ExternalResourceVisitor()=default
virtual void VisitExternalString(Local< String > string)
Definition: v8-primitive.h:740
Definition: v8-primitive.h:853
static Int32 * Cast(v8::Data *data)
Definition: v8-primitive.h:856
Definition: v8-primitive.h:833
static Integer * Cast(v8::Data *data)
Definition: v8-primitive.h:838
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
Definition: v8-isolate.h:261
Definition: v8-local-handle.h:266
Definition: v8-local-handle.h:632
Definition: v8-primitive.h:79
static Name * Cast(Data *data)
Definition: v8-primitive.h:90
Definition: v8-primitive.h:814
static Local< Number > New(Isolate *isolate, double value)
static Number * Cast(v8::Data *data)
Definition: v8-primitive.h:818
Definition: v8-primitive.h:805
Definition: v8-primitive.h:58
static Local< PrimitiveArray > New(Isolate *isolate, int length)
Local< Primitive > Get(Isolate *isolate, int index)
static PrimitiveArray * Cast(Data *data)
Definition: v8-primitive.h:65
void Set(Isolate *isolate, int index, Local< Primitive > item)
Definition: v8-primitive.h:29
Definition: v8-primitive.h:411
const char * cached_data() const
Definition: v8-primitive.h:433
ExternalOneByteStringResource()=default
~ExternalOneByteStringResource() override=default
virtual size_t length() const =0
virtual const char * data() const =0
Definition: v8-primitive.h:292
void operator=(const ExternalStringResourceBase &)=delete
virtual void Unaccount(Isolate *isolate)
Definition: v8-primitive.h:308
ExternalStringResourceBase(const ExternalStringResourceBase &)=delete
virtual ~ExternalStringResourceBase()=default
virtual void Unlock() const
Definition: v8-primitive.h:341
virtual bool IsCacheable() const
Definition: v8-primitive.h:301
ExternalStringResourceBase()=default
virtual void Lock() const
Definition: v8-primitive.h:336
virtual void Dispose()
Definition: v8-primitive.h:323
Definition: v8-primitive.h:356
virtual const uint16_t * data() const =0
ExternalStringResource()=default
const uint16_t * cached_data() const
Definition: v8-primitive.h:380
virtual size_t length() const =0
~ExternalStringResource() override=default
Definition: v8-primitive.h:614
char * operator*()
Definition: v8-primitive.h:619
Utf8Value(Isolate *isolate, Local< v8::Value > obj, WriteOptions options=REPLACE_INVALID_UTF8)
Utf8Value(const Utf8Value &)=delete
const char * operator*() const
Definition: v8-primitive.h:620
void operator=(const Utf8Value &)=delete
size_t length() const
Definition: v8-primitive.h:621
Definition: v8-primitive.h:672
bool is_one_byte() const
Definition: v8-primitive.h:689
const uint16_t * data16_
Definition: v8-primitive.h:701
void operator=(const ValueView &)=delete
const uint8_t * data8() const
Definition: v8-primitive.h:676
uint32_t length() const
Definition: v8-primitive.h:688
ValueView(const ValueView &)=delete
const uint16_t * data16() const
Definition: v8-primitive.h:682
ValueView(Isolate *isolate, Local< v8::String > str)
const uint8_t * data8_
Definition: v8-primitive.h:700
Definition: v8-primitive.h:642
const uint16_t * operator*() const
Definition: v8-primitive.h:650
uint32_t length() const
Definition: v8-primitive.h:651
Value(const Value &)=delete
void operator=(const Value &)=delete
Definition: v8-primitive.h:124
bool IsExternalTwoByte() const
static Local< String > Concat(Isolate *isolate, Local< String > left, Local< String > right)
bool IsExternalOneByte() const
ExternalStringResourceBase * GetExternalStringResourceBase(v8::Isolate *isolate, Encoding *encoding_out) const
Definition: v8-primitive.h:974
Encoding
Definition: v8-primitive.h:129
size_t WriteUtf8V2(Isolate *isolate, char *buffer, size_t capacity, int flags=WriteFlags::kNone) const
void WriteOneByteV2(Isolate *isolate, uint32_t offset, uint32_t length, uint8_t *buffer, int flags=WriteFlags::kNone) const
Local< String > InternalizeString(Isolate *isolate)
static MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=NewStringType::kNormal, int length=-1)
void WriteV2(Isolate *isolate, uint32_t offset, uint32_t length, uint16_t *buffer, int flags=WriteFlags::kNone) const
const ExternalOneByteStringResource * GetExternalOneByteStringResource() const
static MaybeLocal< String > NewExternalTwoByte(Isolate *isolate, ExternalStringResource *resource)
static MaybeLocal< String > NewFromOneByte(Isolate *isolate, const uint8_t *data, NewStringType type=NewStringType::kNormal, int length=-1)
static String * Cast(v8::Data *data)
Definition: v8-primitive.h:475
WriteOptions
Definition: v8-primitive.h:191
static Local< String > Empty(Isolate *isolate)
Definition: v8-primitive.h:946
static MaybeLocal< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, NewStringType type=NewStringType::kNormal, int length=-1)
static Local< String > NewFromUtf8Literal(Isolate *isolate, const char(&literal)[N], NewStringType type=NewStringType::kNormal)
Definition: v8-primitive.h:492
ExternalStringResource * GetExternalStringResource() const
Definition: v8-primitive.h:954
Definition: v8-primitive.h:746
static Local< Symbol > GetMatch(Isolate *isolate)
static Local< Symbol > GetIterator(Isolate *isolate)
static Symbol * Cast(Data *data)
Definition: v8-primitive.h:789
static Local< Symbol > ForApi(Isolate *isolate, Local< String > description)
static Local< Symbol > GetSearch(Isolate *isolate)
static Local< Symbol > GetToPrimitive(Isolate *isolate)
static Local< Symbol > GetAsyncIterator(Isolate *isolate)
static Local< Symbol > GetIsConcatSpreadable(Isolate *isolate)
static Local< Symbol > New(Isolate *isolate, Local< String > description=Local< String >())
static Local< Symbol > GetReplace(Isolate *isolate)
static Local< Symbol > GetToStringTag(Isolate *isolate)
static Local< Symbol > GetSplit(Isolate *isolate)
static Local< Symbol > GetUnscopables(Isolate *isolate)
static Local< Symbol > For(Isolate *isolate, Local< String > description)
Local< Value > Description(Isolate *isolate) const
static Local< Symbol > GetHasInstance(Isolate *isolate)
Definition: v8-primitive.h:871
static Uint32 * Cast(v8::Data *data)
Definition: v8-primitive.h:874
Definition: v8-value.h:32
Definition: v8-internal.h:794
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1625
uintptr_t Address
Definition: v8-internal.h:52
Definition: libplatform.h:15
Local< Primitive > Null(Isolate *isolate)
Definition: v8-primitive.h:1029
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1021
Local< Boolean > False(Isolate *isolate)
Definition: v8-primitive.h:1045
Local< Boolean > True(Isolate *isolate)
Definition: v8-primitive.h:1037
NewStringType
Definition: v8-primitive.h:107
Definition: v8-primitive.h:215
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:603
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:660