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
187 HINT_MANY_WRITES_EXPECTED = 1,
188 NO_NULL_TERMINATION = 2,
189 PRESERVE_ONE_BYTE_NULL = 4,
193 REPLACE_INVALID_UTF8 = 8
197 int Write(
Isolate* isolate, uint16_t* buffer,
int start = 0,
int length = -1,
198 int options = NO_OPTIONS)
const;
201 int length = -1,
int options = NO_OPTIONS)
const;
204 int* nchars_ref =
nullptr,
int options = NO_OPTIONS)
const;
271 friend class internal::ExternalString;
273 friend class internal::StringForwardingTable;
274 friend class internal::ScopedExternalStringLock;
295 virtual const uint16_t*
data()
const = 0;
308 CheckCachedDataInvariants();
322 void CheckCachedDataInvariants()
const;
324 const uint16_t* cached_data_ =
nullptr;
350 virtual const char*
data()
const = 0;
361 CheckCachedDataInvariants();
375 void CheckCachedDataInvariants()
const;
377 const char* cached_data_ =
nullptr;
385 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
386 Encoding* encoding_out)
const;
392 V8_INLINE ExternalStringResource* GetExternalStringResource()
const;
401#ifdef V8_ENABLE_CHECKS
404 return static_cast<String*
>(data);
418 Isolate* isolate,
const char (&literal)[N],
420 static_assert(N <= kMaxLength,
"String is too long");
421 return NewFromUtf8Literal(isolate, literal, type, N - 1);
427 Isolate* isolate,
const char* data,
428 NewStringType type = NewStringType::kNormal,
int length = -1);
433 Isolate* isolate,
const uint8_t* data,
434 NewStringType type = NewStringType::kNormal,
int length = -1);
439 Isolate* isolate,
const uint16_t* data,
440 NewStringType type = NewStringType::kNormal,
int length = -1);
563 static void CheckCast(
v8::Data* that);
630#ifdef V8_ENABLE_CHECKS
633 return static_cast<Symbol*
>(data);
638 static void CheckCast(
Data* that);
648 static void CheckCast(
v8::Data* that);
659#ifdef V8_ENABLE_CHECKS
662 return static_cast<Number*
>(data);
667 static void CheckCast(
v8::Data* that);
679#ifdef V8_ENABLE_CHECKS
682 return static_cast<Integer*
>(data);
687 static void CheckCast(
v8::Data* that);
697#ifdef V8_ENABLE_CHECKS
700 return static_cast<Int32*
>(data);
705 static void CheckCast(
v8::Data* that);
715#ifdef V8_ENABLE_CHECKS
718 return static_cast<Uint32*
>(data);
723 static void CheckCast(
v8::Data* that);
741 int word_count,
const uint64_t* words);
772 void ToWordsArray(
int* sign_bit,
int* word_count, uint64_t* words)
const;
775#ifdef V8_ENABLE_CHECKS
778 return static_cast<BigInt*
>(data);
783 static void CheckCast(
v8::Data* that);
789 I::CheckInitialized(isolate);
790 S* slot = I::GetRootSlot(isolate, I::kEmptyStringRootIndex);
800 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
801 Isolate* isolate = I::GetIsolateForSandbox(obj);
802 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
803 isolate, obj, I::kStringResourceOffset);
806 result = GetExternalStringResourceSlow();
808#ifdef V8_ENABLE_CHECKS
809 VerifyExternalStringResource(result);
819 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
820 *encoding_out =
static_cast<Encoding>(type & I::kStringEncodingMask);
822 if (type == I::kExternalOneByteRepresentationTag ||
823 type == I::kExternalTwoByteRepresentationTag) {
824 Isolate* isolate = I::GetIsolateForSandbox(obj);
825 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
826 isolate, obj, I::kStringResourceOffset);
829 resource = GetExternalStringResourceBaseSlow(encoding_out);
831#ifdef V8_ENABLE_CHECKS
832 VerifyExternalStringResourceBase(resource, *encoding_out);
842 I::CheckInitialized(isolate);
843 S* slot = I::GetRootSlot(isolate, I::kUndefinedValueRootIndex);
850 I::CheckInitialized(isolate);
851 S* slot = I::GetRootSlot(isolate, I::kNullValueRootIndex);
858 I::CheckInitialized(isolate);
859 S* slot = I::GetRootSlot(isolate, I::kTrueValueRootIndex);
866 I::CheckInitialized(isolate);
867 S* slot = I::GetRootSlot(isolate, I::kFalseValueRootIndex);
872 return value ?
True(isolate) :
False(isolate);
static MaybeLocal< BigInt > NewFromWords(Local< Context > context, int sign_bit, int word_count, const uint64_t *words)
static Local< BigInt > New(Isolate *isolate, int64_t value)
void ToWordsArray(int *sign_bit, int *word_count, uint64_t *words) const
uint64_t Uint64Value(bool *lossless=nullptr) const
static V8_INLINE BigInt * Cast(v8::Data *data)
static Local< BigInt > NewFromUnsigned(Isolate *isolate, uint64_t value)
int64_t Int64Value(bool *lossless=nullptr) const
static V8_INLINE Boolean * Cast(v8::Data *data)
static V8_INLINE Local< Boolean > New(Isolate *isolate, bool value)
virtual void VisitExternalString(Local< String > string)
virtual ~ExternalResourceVisitor()=default
static V8_INLINE Int32 * Cast(v8::Data *data)
static Local< Integer > New(Isolate *isolate, int32_t value)
static V8_INLINE Integer * Cast(v8::Data *data)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
static V8_INLINE Name * Cast(Data *data)
static V8_INLINE Number * Cast(v8::Data *data)
static Local< Number > New(Isolate *isolate, double value)
void Set(Isolate *isolate, int index, Local< Primitive > item)
Local< Primitive > Get(Isolate *isolate, int index)
static Local< PrimitiveArray > New(Isolate *isolate, int length)
static V8_INLINE PrimitiveArray * Cast(Data *data)
ExternalOneByteStringResource()=default
~ExternalOneByteStringResource() override=default
virtual const char * data() const =0
const char * cached_data() const
virtual size_t length() const =0
virtual void Lock() const
virtual ~ExternalStringResourceBase()=default
ExternalStringResourceBase()=default
void operator=(const ExternalStringResourceBase &)=delete
virtual bool IsCacheable() const
ExternalStringResourceBase(const ExternalStringResourceBase &)=delete
virtual void Unlock() const
ExternalStringResource()=default
~ExternalStringResource() override=default
const uint16_t * cached_data() const
virtual const uint16_t * data() const =0
virtual size_t length() const =0
void operator=(const Utf8Value &)=delete
const char * operator*() const
Utf8Value(const Utf8Value &)=delete
Utf8Value(Isolate *isolate, Local< v8::Value > obj)
const uint16_t * operator*() const
void operator=(const Value &)=delete
Value(Isolate *isolate, Local< v8::Value > obj)
Value(const Value &)=delete
bool ContainsOnlyOneByte() const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, NewStringType type=NewStringType::kNormal, int length=-1)
V8_INLINE ExternalStringResource * GetExternalStringResource() const
bool IsExternalTwoByte() const
static V8_WARN_UNUSED_RESULT Local< String > NewFromUtf8Literal(Isolate *isolate, const char(&literal)[N], NewStringType type=NewStringType::kNormal)
bool MakeExternal(ExternalStringResource *resource)
static V8_INLINE String * Cast(v8::Data *data)
static V8_INLINE Local< String > Empty(Isolate *isolate)
const ExternalOneByteStringResource * GetExternalOneByteStringResource() const
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(Encoding *encoding_out) const
int WriteUtf8(Isolate *isolate, char *buffer, int length=-1, int *nchars_ref=nullptr, int options=NO_OPTIONS) const
int WriteOneByte(Isolate *isolate, uint8_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
bool MakeExternal(ExternalOneByteStringResource *resource)
bool StringEquals(Local< String > str) const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewExternalTwoByte(Isolate *isolate, ExternalStringResource *resource)
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=NewStringType::kNormal, int length=-1)
static Local< String > Concat(Isolate *isolate, Local< String > left, Local< String > right)
bool IsExternalOneByte() const
int Utf8Length(Isolate *isolate) const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewExternalOneByte(Isolate *isolate, ExternalOneByteStringResource *resource)
bool CanMakeExternal(Encoding encoding) const
int Write(Isolate *isolate, uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromOneByte(Isolate *isolate, const uint8_t *data, NewStringType type=NewStringType::kNormal, int length=-1)
static Local< Symbol > New(Isolate *isolate, Local< String > description=Local< String >())
static Local< Symbol > GetIterator(Isolate *isolate)
static V8_INLINE Symbol * Cast(Data *data)
static Local< Symbol > GetToPrimitive(Isolate *isolate)
static Local< Symbol > GetHasInstance(Isolate *isolate)
static Local< Symbol > GetIsConcatSpreadable(Isolate *isolate)
static Local< Symbol > GetToStringTag(Isolate *isolate)
static Local< Symbol > ForApi(Isolate *isolate, Local< String > description)
static Local< Symbol > GetReplace(Isolate *isolate)
Local< Value > Description(Isolate *isolate) const
static Local< Symbol > For(Isolate *isolate, Local< String > description)
static Local< Symbol > GetAsyncIterator(Isolate *isolate)
static Local< Symbol > GetMatch(Isolate *isolate)
static Local< Symbol > GetSplit(Isolate *isolate)
static Local< Symbol > GetUnscopables(Isolate *isolate)
static Local< Symbol > GetSearch(Isolate *isolate)
static V8_INLINE Uint32 * Cast(v8::Data *data)
static V8_INLINE Address ValueAsAddress(const T *value)
V8_INLINE Local< Primitive > Null(Isolate *isolate)
V8_INLINE Local< Boolean > True(Isolate *isolate)
V8_INLINE Local< Boolean > False(Isolate *isolate)
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
#define V8_WARN_UNUSED_RESULT