5#ifndef INCLUDE_V8_PRIMITIVE_H_
6#define INCLUDE_V8_PRIMITIVE_H_
22class ScopedExternalStringLock;
23class StringForwardingTable;
27
28
32
33
34
39#ifdef V8_ENABLE_CHECKS
42 return static_cast<
Boolean*>(data);
48 static void CheckCast(
v8::
Data* that);
52
53
54
55
56
57
66#ifdef V8_ENABLE_CHECKS
73 static void CheckCast(
Data* obj);
77
78
82
83
84
85
86
87
91#ifdef V8_ENABLE_CHECKS
94 return static_cast<
Name*>(data);
98 static void CheckCast(
Data* that);
102
103
104
105
106
109
110
114
115
116
117
122
123
135
136
140
141
142
147
148
152
153
154
155
156
160
161
162
163
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
204 int Write(
Isolate* isolate, uint16_t* buffer,
int start = 0,
int length = -1,
209 int length = -1,
int options =
NO_OPTIONS)
const;
213 int* nchars_ref =
nullptr,
int options =
NO_OPTIONS)
const;
230
231
232
233
234
235
236
237
238
239
240
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
267 size_t* processed_characters_return =
nullptr)
const;
270
271
275
276
280
281
285
286
290
291
292
300
301
302
303
307
308
309
310
314
315
316
317
318
319
320
321
323 return kDefaultMemoryEstimate;
330
331
332
338
339
340
352
353
354
355
356
360
361
362
363
364
365
366
367
368
369
373
374
385
386
387
388
389
393
394
395
399
400
401
402 virtual const uint16_t*
data()
const = 0;
405
406
410
411
412
413
415 CheckCachedDataInvariants();
420
421
422
429 void CheckCachedDataInvariants()
const;
431 const uint16_t* cached_data_ =
nullptr;
435
436
437
438
439
440
441
442
448
449
450
454
455
456
457 virtual const char*
data()
const = 0;
463
464
465
466
468 CheckCachedDataInvariants();
473
474
475
482 void CheckCachedDataInvariants()
const;
484 const char* cached_data_ =
nullptr;
490
491
498
499
500
504
505
506
510#ifdef V8_ENABLE_CHECKS
513 return static_cast<
String*>(data);
517
518
519
520
521
522
523
524
527 Isolate* isolate,
const char (&literal)[N],
529 static_assert(N <=
kMaxLength,
"String is too long");
530 return NewFromUtf8Literal(isolate, literal, type, N - 1);
534
536 Isolate* isolate,
const char* data,
540
542 Isolate* isolate,
const uint8_t* data,
546
548 Isolate* isolate,
const uint16_t* data,
552
553
554
559
560
561
562
563
564
565
570
571
572
573
574
575
576
577
582
583
584
585
586
587
588
589
593
594
595
596
597
598
599
604
605
606
607
608
609
610
611
616
617
618
619
620
621
622
623
627
628
629
633
634
638
639
640
641
642
643
644
645
646
665
666
667
668
669
670
671
672
673
677 "Prefer using String::ValueView if you can, or string->Write to a "
678 "buffer if you cannot.")
683 uint32_t
length()
const {
return length_; }
695
696
697
698
699
700
701
702
703
720 uint32_t
length()
const {
return length_; }
728 void CheckOneByte(
bool is_one_byte)
const;
755 static void CheckCast(
v8::
Data* that);
767
768
776
777
781
782
786
787
788
793
794
795
796
797
798
799
803
804
805
824#ifdef V8_ENABLE_CHECKS
827 return static_cast<
Symbol*>(data);
832 static void CheckCast(
Data* that);
836
837
838
842 static void CheckCast(
v8::
Data* that);
846
847
852 template <
typename Int>
853 requires(std::is_integral<Int>::value && !std::is_same<Int,
bool>::value &&
854 std::is_signed_v<Int> &&
sizeof(Int) <=
sizeof(int32_t))
858 template <
typename UInt>
866#ifdef V8_ENABLE_CHECKS
876 static void CheckCast(
v8::
Data* that);
880
881
888#ifdef V8_ENABLE_CHECKS
891 return static_cast<
Integer*>(data);
896 static void CheckCast(
v8::
Data* that);
900
901
906#ifdef V8_ENABLE_CHECKS
909 return static_cast<
Int32*>(data);
914 static void CheckCast(
v8::
Data* that);
918
919
924#ifdef V8_ENABLE_CHECKS
927 return static_cast<
Uint32*>(data);
932 static void CheckCast(
v8::
Data* that);
936
937
943
944
945
946
947
948
950 int word_count,
const uint64_t* words);
953
954
955
956
957
961
962
963
964
968
969
970
974
975
976
977
978
979
980
981 void ToWordsArray(
int* sign_bit,
int* word_count, uint64_t* words)
const;
984#ifdef V8_ENABLE_CHECKS
987 return static_cast<
BigInt*>(data);
992 static void CheckCast(
v8::
Data* that);
1000 return Local<String>::FromSlot(slot);
1006 A obj =
internal::ValueHelper::ValueAsAddress(
this);
1015 result = GetExternalStringResourceSlow();
1017#ifdef V8_ENABLE_CHECKS
1018 VerifyExternalStringResource(result);
1027 A obj =
internal::ValueHelper::ValueAsAddress(
this);
1037 resource = GetExternalStringResourceBaseSlow(encoding_out);
1039#ifdef V8_ENABLE_CHECKS
1040 VerifyExternalStringResourceBase(resource, *encoding_out);
1049 A obj =
internal::ValueHelper::ValueAsAddress(
this);
1060 resource = GetExternalStringResourceBaseSlow(encoding_out);
1062#ifdef V8_ENABLE_CHECKS
1063 VerifyExternalStringResourceBase(resource, *encoding_out);
1075 return Local<Primitive>::FromSlot(slot);
1083 return Local<Primitive>::FromSlot(slot);
1091 return Local<Boolean>::FromSlot(slot);
1099 return Local<Boolean>::FromSlot(slot);
1103 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)
friend Local< Primitive > Null(Isolate *isolate)
friend Local< Boolean > False(Isolate *isolate)
friend Local< Primitive > Undefined(Isolate *isolate)
friend Local< Boolean > True(Isolate *isolate)
static V8_INLINE Name * Cast(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 RecordSharedMemoryUsage(const void *location, size_t size)=0
virtual void Lock() const
virtual void Unaccount(Isolate *isolate)
static constexpr size_t kDefaultMemoryEstimate
virtual size_t EstimateMemoryUsage() const
virtual void EstimateSharedMemoryUsage(SharedMemoryUsageRecorder *recorder) 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(const Value &)=delete
ValueView(const ValueView &)=delete
ValueView(Isolate *isolate, Local< v8::String > str)
const uint16_t * data16() const
const uint8_t * data8() const
void operator=(const ValueView &)=delete
bool ContainsOnlyOneByte() const
Local< String > InternalizeString(Isolate *isolate)
V8_WARN_UNUSED_RESULT Local< String > NewFromUtf8Literal(Isolate *isolate, const char(&literal)[1], NewStringType type)
size_t Utf8LengthV2(Isolate *isolate) const
static V8_WARN_UNUSED_RESULT MaybeLocal< String > NewFromTwoByte(Isolate *isolate, const uint16_t *data, NewStringType type=NewStringType::kNormal, int length=-1)
bool MakeExternal(Isolate *isolate, ExternalStringResource *resource)
@ HINT_MANY_WRITES_EXPECTED
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(Isolate *isolate, ExternalOneByteStringResource *resource)
static constexpr int kMaxLength
bool MakeExternal(ExternalStringResource *resource)
static V8_INLINE String * Cast(v8::Data *data)
void WriteV2(Isolate *isolate, uint32_t offset, uint32_t length, uint16_t *buffer, int flags=WriteFlags::kNone) const
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
size_t WriteUtf8V2(Isolate *isolate, char *buffer, size_t capacity, int flags=WriteFlags::kNone, size_t *processed_characters_return=nullptr) 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
V8_INLINE ExternalStringResourceBase * GetExternalStringResourceBase(v8::Isolate *isolate, Encoding *encoding_out) const
void WriteOneByteV2(Isolate *isolate, uint32_t offset, uint32_t length, uint8_t *buffer, int flags=WriteFlags::kNone) 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 > GetAsyncDispose(Isolate *isolate)
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 > GetDispose(Isolate *isolate)
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 const int kTrueValueRootIndex
static const int kFalseValueRootIndex
static const int kNullValueRootIndex
static const int kEmptyStringRootIndex
static const int kStringRepresentationAndEncodingMask
static const int kDisallowGarbageCollectionSize
static const int kExternalTwoByteRepresentationTag
static const int kUndefinedValueRootIndex
static V8_INLINE void CheckInitialized(v8::Isolate *isolate)
static V8_INLINE Address * GetRootSlot(v8::Isolate *isolate, int index)
static const int kExternalOneByteRepresentationTag
static V8_INLINE int GetInstanceType(Address obj)
static V8_INLINE v8::Isolate * GetCurrentIsolateForSandbox()
static V8_INLINE bool IsExternalTwoByteString(int instance_type)
static const int kStringEncodingMask
static const int kStringResourceOffset
const int kApiSystemPointerSize
@ kExternalStringResourceTag
#define V8_DEPRECATE_SOON(message)
#define V8_DEPRECATED(message)
#define V8_WARN_UNUSED_RESULT