5#ifndef INCLUDE_V8_PRIMITIVE_H_
6#define INCLUDE_V8_PRIMITIVE_H_
22class ScopedExternalStringLock;
38#ifdef V8_ENABLE_CHECKS
41 return static_cast<Boolean*
>(data);
47 static void CheckCast(
v8::Data* that);
65#ifdef V8_ENABLE_CHECKS
72 static void CheckCast(
Data* obj);
90#ifdef V8_ENABLE_CHECKS
93 return static_cast<Name*
>(data);
97 static void CheckCast(
Data* that);
125 static constexpr int kMaxLength =
126 internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
129 UNKNOWN_ENCODING = 0x1,
130 TWO_BYTE_ENCODING = 0x0,
131 ONE_BYTE_ENCODING = 0x8
186 HINT_MANY_WRITES_EXPECTED = 1,
187 NO_NULL_TERMINATION = 2,
188 PRESERVE_ONE_BYTE_NULL = 4,
192 REPLACE_INVALID_UTF8 = 8
196 int Write(
Isolate* isolate, uint16_t* buffer,
int start = 0,
int length = -1,
197 int options = NO_OPTIONS)
const;
200 int length = -1,
int options = NO_OPTIONS)
const;
203 int* nchars_ref =
nullptr,
int options = NO_OPTIONS)
const;
270 friend class internal::ExternalString;
272 friend class internal::ScopedExternalStringLock;
293 virtual const uint16_t*
data()
const = 0;
306 CheckCachedDataInvariants();
320 void CheckCachedDataInvariants()
const;
322 const uint16_t* cached_data_ =
nullptr;
348 virtual const char*
data()
const = 0;
359 CheckCachedDataInvariants();
373 void CheckCachedDataInvariants()
const;
375 const char* cached_data_ =
nullptr;
399#ifdef V8_ENABLE_CHECKS
402 return static_cast<String*
>(data);
416 Isolate* isolate,
const char (&literal)[N],
418 static_assert(N <= kMaxLength,
"String is too long");
419 return NewFromUtf8Literal(isolate, literal, type, N - 1);
425 Isolate* isolate,
const char* data,
426 NewStringType type = NewStringType::kNormal,
int length = -1);
431 Isolate* isolate,
const uint8_t* data,
432 NewStringType type = NewStringType::kNormal,
int length = -1);
437 Isolate* isolate,
const uint16_t* data,
438 NewStringType type = NewStringType::kNormal,
int length = -1);
560 static void CheckCast(
v8::Data* that);
627#ifdef V8_ENABLE_CHECKS
630 return static_cast<Symbol*
>(data);
635 static void CheckCast(
Data* that);
646#ifdef V8_ENABLE_CHECKS
649 return static_cast<Number*
>(data);
654 static void CheckCast(
v8::Data* that);
666#ifdef V8_ENABLE_CHECKS
669 return static_cast<Integer*
>(data);
674 static void CheckCast(
v8::Data* that);
684#ifdef V8_ENABLE_CHECKS
687 return static_cast<Int32*
>(data);
692 static void CheckCast(
v8::Data* that);
702#ifdef V8_ENABLE_CHECKS
705 return static_cast<Uint32*
>(data);
710 static void CheckCast(
v8::Data* that);
728 int word_count,
const uint64_t* words);
759 void ToWordsArray(
int* sign_bit,
int* word_count, uint64_t* words)
const;
762#ifdef V8_ENABLE_CHECKS
765 return static_cast<BigInt*
>(data);
770 static void CheckCast(
v8::Data* that);
776 I::CheckInitialized(isolate);
777 S* slot = I::GetRoot(isolate, I::kEmptyStringRootIndex);
784 A obj = *
reinterpret_cast<const A*
>(
this);
787 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
788 internal::Isolate* isolate = I::GetIsolateForSandbox(obj);
790 I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset,
794 result = GetExternalStringResourceSlow();
796#ifdef V8_ENABLE_CHECKS
797 VerifyExternalStringResource(result);
806 A obj = *
reinterpret_cast<const A*
>(
this);
807 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
808 *encoding_out =
static_cast<Encoding>(type & I::kStringEncodingMask);
810 if (type == I::kExternalOneByteRepresentationTag ||
811 type == I::kExternalTwoByteRepresentationTag) {
812 internal::Isolate* isolate = I::GetIsolateForSandbox(obj);
814 I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset,
818 resource = GetExternalStringResourceBaseSlow(encoding_out);
820#ifdef V8_ENABLE_CHECKS
821 VerifyExternalStringResourceBase(resource, *encoding_out);
831 I::CheckInitialized(isolate);
832 S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex);
839 I::CheckInitialized(isolate);
840 S* slot = I::GetRoot(isolate, I::kNullValueRootIndex);
847 I::CheckInitialized(isolate);
848 S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex);
855 I::CheckInitialized(isolate);
856 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
861 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)
bool CanMakeExternal() const
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)
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)
@ kExternalStringResourceTag
V8_INLINE Local< Primitive > Null(Isolate *isolate)
V8_INLINE Local< Boolean > True(Isolate *isolate)
V8_INLINE Local< Boolean > False(Isolate *isolate)
int32_t(Local< Array > src, int32_t *dst, uint32_t max_length)
V8_INLINE Local< Primitive > Undefined(Isolate *isolate)
#define V8_WARN_UNUSED_RESULT