Loading...
Searching...
No Matches
v8-primitive.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_V8_PRIMITIVE_H_
6#define INCLUDE_V8_PRIMITIVE_H_
7
8#include <string_view>
9
10#include "v8-data.h" // NOLINT(build/include_directory)
11#include "v8-internal.h" // NOLINT(build/include_directory)
12#include "v8-local-handle.h" // NOLINT(build/include_directory)
13#include "v8-sandbox.h" // NOLINT(build/include_directory)
14#include "v8-value.h" // NOLINT(build/include_directory)
15#include "v8config.h" // NOLINT(build/include_directory)
16
17namespace v8 {
18
19class Context;
20class Isolate;
21class String;
22
23namespace internal {
24class ExternalString;
25class ExternalStringResourceWrapper;
26class ScopedExternalStringLock;
27} // namespace internal
28
32class V8_EXPORT Primitive : public Value {};
33
38class V8_EXPORT Boolean : public Primitive {
39 public:
40 bool Value() const;
41 V8_INLINE static Boolean* Cast(v8::Data* data) {
42#ifdef V8_ENABLE_CHECKS
43 CheckCast(data);
44#endif
45 return static_cast<Boolean*>(data);
46 }
47
48 V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
49
50 private:
51 static void CheckCast(v8::Data* that);
52};
53
62 public:
63 static Local<PrimitiveArray> New(Isolate* isolate, int length);
64 int Length() const;
65 void Set(Isolate* isolate, int index, Local<Primitive> item);
66 Local<Primitive> Get(Isolate* isolate, int index);
67
69#ifdef V8_ENABLE_CHECKS
70 CheckCast(data);
71#endif
72 return reinterpret_cast<PrimitiveArray*>(data);
73 }
74
75 private:
76 static void CheckCast(Data* obj);
77};
78
82class V8_EXPORT Name : public Primitive {
83 public:
92
93 V8_INLINE static Name* Cast(Data* data) {
94#ifdef V8_ENABLE_CHECKS
95 CheckCast(data);
96#endif
97 return static_cast<Name*>(data);
98 }
99
100 private:
101 static void CheckCast(Data* that);
102};
103
110enum class NewStringType {
114 kNormal,
115
122};
123
127class V8_EXPORT String : public Name {
128 public:
129#ifndef V8_LOWER_LIMITS_MODE
130 static constexpr int kMaxLength =
131 internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
132#else
133 static constexpr int kMaxLength = 1 << 20;
134#endif // V8_LOWER_LIMITS_MODE
135
136 enum Encoding {
137 UNKNOWN_ENCODING = 0x1,
138 TWO_BYTE_ENCODING = 0x0,
139 ONE_BYTE_ENCODING = 0x8
140 };
144 int Length() const;
145
149 size_t Utf8Length(Isolate* isolate) const;
150 // TODO(http://crbug.com/373485796): deprecate and remove.
151 V8_DEPRECATE_SOON("Use Utf8Length(isolate) instead.")
152 size_t Utf8LengthV2(Isolate* isolate) const { return Utf8Length(isolate); }
153
160 bool IsOneByte() const;
161
168
169 struct WriteFlags {
170 enum {
171 kNone = 0,
172 // Indicates that the output string should be null-terminated. In that
173 // case, the output buffer must include sufficient space for the
174 // additional null character.
175 kNullTerminate = 1,
176 // Used by WriteUtf8 to replace orphan surrogate code units with the
177 // unicode replacement character. Needs to be set to guarantee valid UTF-8
178 // output.
179 kReplaceInvalidUtf8 = 2
180 };
181 };
182
195 void Write(Isolate* isolate, uint32_t offset, uint32_t length,
196 uint16_t* buffer, int flags = WriteFlags::kNone) const;
197 void WriteOneByte(Isolate* isolate, uint32_t offset, uint32_t length,
198 uint8_t* buffer, int flags = WriteFlags::kNone) const;
199 // TODO(http://crbug.com/373485796): deprecate and remove.
200 V8_DEPRECATE_SOON("Use Write(..) instead.")
201 void WriteV2(Isolate* isolate, uint32_t offset, uint32_t length,
202 uint16_t* buffer, int flags = WriteFlags::kNone) const {
203 Write(isolate, offset, length, buffer, flags);
204 }
205 // TODO(http://crbug.com/373485796): deprecate and remove.
206 V8_DEPRECATE_SOON("Use WriteOneByte(..) instead.")
207 void WriteOneByteV2(Isolate* isolate, uint32_t offset, uint32_t length,
208 uint8_t* buffer, int flags = WriteFlags::kNone) const {
209 WriteOneByte(isolate, offset, length, buffer, flags);
210 }
211
231 size_t WriteUtf8(Isolate* isolate, char* buffer, size_t capacity,
232 int flags = WriteFlags::kNone,
233 size_t* processed_characters_return = nullptr) const;
234 // TODO(http://crbug.com/373485796): deprecate and remove.
235 V8_DEPRECATE_SOON("Use WriteUtf8(..) instead.")
236 size_t WriteUtf8V2(Isolate* isolate, char* buffer, size_t capacity,
237 int flags = WriteFlags::kNone,
238 size_t* processed_characters_return = nullptr) const {
239 return WriteUtf8(isolate, buffer, capacity, flags,
240 processed_characters_return);
241 }
242
246 V8_INLINE static Local<String> Empty(Isolate* isolate);
247
251 bool IsExternal() const;
252
256 bool IsExternalTwoByte() const;
257
261 bool IsExternalOneByte() const;
262
268
272 bool IsInStringTable(Isolate* isolate) const;
273
275 public:
276 virtual ~ExternalStringResourceBase() = default;
277
283 virtual bool IsCacheable() const { return true; }
284
293 virtual void Unaccount(Isolate* isolate) {}
294
304 virtual size_t EstimateMemoryUsage() const {
305 return kDefaultMemoryEstimate;
306 }
307 static constexpr size_t kDefaultMemoryEstimate = static_cast<size_t>(-1);
308
310 public:
315 virtual void RecordSharedMemoryUsage(const void* location,
316 size_t size) = 0;
317 };
318
324 SharedMemoryUsageRecorder* recorder) const {}
325
326 // Disallow copying and assigning.
329
330 protected:
332
342 virtual void Dispose() { delete this; }
343
355 virtual void Lock() const {}
356
360 virtual void Unlock() const {}
361
362 private:
363 friend class internal::ExternalString;
364 friend class internal::ExternalStringResourceWrapper;
365 friend class v8::String;
366 friend class internal::ScopedExternalStringLock;
367 };
368
376 public:
381 ~ExternalStringResource() override = default;
382
387 virtual const uint16_t* data() const = 0;
388
392 virtual size_t length() const = 0;
393
399 const uint16_t* cached_data() const {
400 CheckCachedDataInvariants();
401 return cached_data_;
402 }
403
409
410 protected:
412
413 private:
414 void CheckCachedDataInvariants() const;
415
416 const uint16_t* cached_data_ = nullptr;
417 };
418
431 public:
436 ~ExternalOneByteStringResource() override = default;
437
442 virtual const char* data() const = 0;
443
445 virtual size_t length() const = 0;
446
452 const char* cached_data() const {
453 CheckCachedDataInvariants();
454 return cached_data_;
455 }
456
462
463 protected:
465
466 private:
467 void CheckCachedDataInvariants() const;
468
469 const char* cached_data_ = nullptr;
470 };
471
477 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
478 v8::Isolate* isolate, Encoding* encoding_out) const;
479 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
480 Encoding* encoding_out) const;
481
486 // TODO(pthier): Change return type to const ExternalStringResource*.
487 V8_INLINE ExternalStringResource* GetExternalStringResource() const;
488
493 V8_INLINE const ExternalOneByteStringResource*
494 GetExternalOneByteStringResource() const;
495
496 V8_INLINE static String* Cast(v8::Data* data) {
497#ifdef V8_ENABLE_CHECKS
498 CheckCast(data);
499#endif
500 return static_cast<String*>(data);
501 }
502
512 template <int N>
514 Isolate* isolate, const char (&literal)[N],
515 NewStringType type = NewStringType::kNormal) {
516 static_assert(N <= kMaxLength, "String is too long");
517 return NewFromUtf8Literal(isolate, literal, type, N - 1);
518 }
519
523 Isolate* isolate, const char* data,
524 NewStringType type = NewStringType::kNormal, int length = -1);
525
529 Isolate* isolate, const uint8_t* data,
530 NewStringType type = NewStringType::kNormal, int length = -1);
531
535 Isolate* isolate, const uint16_t* data,
536 NewStringType type = NewStringType::kNormal, int length = -1);
537
543 Local<String> right);
544
554 Isolate* isolate, ExternalStringResource* resource);
555
565 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
566 bool MakeExternal(ExternalStringResource* resource);
567
577 bool MakeExternal(Isolate* isolate, ExternalStringResource* resource);
578
587 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
588 Isolate* isolate, ExternalOneByteStringResource* resource);
589
599 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
600 bool MakeExternal(ExternalOneByteStringResource* resource);
601
611 bool MakeExternal(Isolate* isolate, ExternalOneByteStringResource* resource);
612
617 bool CanMakeExternal(Encoding encoding) const;
618
622 bool StringEquals(Local<String> str) const;
623
635 public:
638 char* operator*() { return str_; }
639 const char* operator*() const { return str_; }
640 size_t length() const { return length_; }
641 std::string_view as_view() const { return std::string_view(str_, length_); }
642
643 // Disallow copying and assigning.
644 Utf8Value(const Utf8Value&) = delete;
645 void operator=(const Utf8Value&) = delete;
646
647 private:
648 char* str_;
649 size_t length_;
650 };
651
663 "Prefer using String::ValueView if you can, or string->Write to a "
664 "buffer if you cannot.") V8_EXPORT Value {
665 public:
667 "Prefer using String::ValueView if you can, or string->Write to a "
668 "buffer if you cannot.")
669 Value(Isolate* isolate, Local<v8::Value> obj);
671 uint16_t* operator*() { return str_; }
672 const uint16_t* operator*() const { return str_; }
673 uint32_t length() const { return length_; }
674
675 // Disallow copying and assigning.
676 Value(const Value&) = delete;
677 void operator=(const Value&) = delete;
678
679 private:
680 uint16_t* str_;
681 uint32_t length_;
682 };
683
695 public:
698 const uint8_t* data8() const {
699#if V8_ENABLE_CHECKS
700 CheckOneByte(true);
701#endif
702 return data8_;
703 }
704 const uint16_t* data16() const {
705#if V8_ENABLE_CHECKS
706 CheckOneByte(false);
707#endif
708 return data16_;
709 }
710 uint32_t length() const { return length_; }
711 bool is_one_byte() const { return is_one_byte_; }
712
713 // Disallow copying and assigning.
714 ValueView(const ValueView&) = delete;
715 void operator=(const ValueView&) = delete;
716
717 private:
718 void CheckOneByte(bool is_one_byte) const;
719
720 Local<v8::String> flat_str_;
721 union {
722 const uint8_t* data8_;
723 const uint16_t* data16_;
724 };
725 uint32_t length_;
726 bool is_one_byte_;
727 // Avoid exposing the internal DisallowGarbageCollection scope.
728 alignas(internal::Internals::
729 kDisallowGarbageCollectionAlign) char no_gc_debug_scope_
730 [internal::Internals::kDisallowGarbageCollectionSize];
731 };
732
733 private:
734 void VerifyExternalStringResourceBase(const ExternalStringResourceBase* v,
735 Encoding encoding) const;
736 // Reads the resource of the external string at {obj}. Generally returns a
737 // resource unless corruption results in sandbox violations.
738 V8_INLINE static ExternalStringResourceBase* ReadExternalStringResource(
739 v8::Isolate* isolate, internal::Address obj);
740 ExternalStringResource* GetExternalStringResourceSlow() const;
741 const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
742 const;
743 ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
744 String::Encoding* encoding_out) const;
745
746 static Local<v8::String> NewFromUtf8Literal(Isolate* isolate,
747 const char* literal,
748 NewStringType type, int length);
749
750 static void CheckCast(v8::Data* that);
751};
752
753// Zero-length string specialization (templated string size includes
754// terminator).
755template <>
757 Isolate* isolate, const char (&literal)[1], NewStringType type) {
758 return String::Empty(isolate);
759}
760
765 public:
766 virtual ~ExternalResourceVisitor() = default;
767 virtual void VisitExternalString(Local<String> string) {}
768};
769
773class V8_EXPORT Symbol : public Name {
774 public:
779
784 static Local<Symbol> New(Isolate* isolate,
785 Local<String> description = Local<String>());
786
795 static Local<Symbol> For(Isolate* isolate, Local<String> description);
796
801 static Local<Symbol> ForApi(Isolate* isolate, Local<String> description);
802
803 // Well-known symbols
817
818 V8_INLINE static Symbol* Cast(Data* data) {
819#ifdef V8_ENABLE_CHECKS
820 CheckCast(data);
821#endif
822 return static_cast<Symbol*>(data);
823 }
824
825 private:
826 Symbol();
827 static void CheckCast(Data* that);
828};
829
835 private:
836 Numeric();
837 static void CheckCast(v8::Data* that);
838};
839
843class V8_EXPORT Number : public Numeric {
844 public:
845 double Value() const;
846 static Local<Number> New(Isolate* isolate, double value);
847 template <typename Int>
848 requires(std::is_integral<Int>::value && !std::is_same<Int, bool>::value &&
849 std::is_signed_v<Int> && sizeof(Int) <= sizeof(int32_t))
850 V8_INLINE static Local<Number> New(Isolate* isolate, Int value) {
851 return NewFromInt32(isolate, value);
852 }
853 template <typename UInt>
854 requires(std::is_integral<UInt>::value &&
855 !std::is_same<UInt, bool>::value && std::is_unsigned_v<UInt> &&
856 sizeof(UInt) <= sizeof(uint32_t))
857 V8_INLINE static Local<Number> New(Isolate* isolate, UInt value) {
858 return NewFromUint32(isolate, value);
859 }
860 V8_INLINE static Number* Cast(v8::Data* data) {
861#ifdef V8_ENABLE_CHECKS
862 CheckCast(data);
863#endif
864 return static_cast<Number*>(data);
865 }
866
867 private:
868 Number();
869 static Local<Number> NewFromInt32(Isolate* isolate, int32_t value);
870 static Local<Number> NewFromUint32(Isolate* isolate, uint32_t value);
871 static void CheckCast(v8::Data* that);
872};
873
877class V8_EXPORT Integer : public Number {
878 public:
879 static Local<Integer> New(Isolate* isolate, int32_t value);
880 static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
881 int64_t Value() const;
883#ifdef V8_ENABLE_CHECKS
884 CheckCast(data);
885#endif
886 return static_cast<Integer*>(data);
887 }
888
889 private:
890 Integer();
891 static void CheckCast(v8::Data* that);
892};
893
897class V8_EXPORT Int32 : public Integer {
898 public:
899 int32_t Value() const;
900 V8_INLINE static Int32* Cast(v8::Data* data) {
901#ifdef V8_ENABLE_CHECKS
902 CheckCast(data);
903#endif
904 return static_cast<Int32*>(data);
905 }
906
907 private:
908 Int32();
909 static void CheckCast(v8::Data* that);
910};
911
915class V8_EXPORT Uint32 : public Integer {
916 public:
917 uint32_t Value() const;
918 V8_INLINE static Uint32* Cast(v8::Data* data) {
919#ifdef V8_ENABLE_CHECKS
920 CheckCast(data);
921#endif
922 return static_cast<Uint32*>(data);
923 }
924
925 private:
926 Uint32();
927 static void CheckCast(v8::Data* that);
928};
929
933class V8_EXPORT BigInt : public Numeric {
934 public:
935 static Local<BigInt> New(Isolate* isolate, int64_t value);
936 static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
944 static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
945 int word_count, const uint64_t* words);
946
953 uint64_t Uint64Value(bool* lossless = nullptr) const;
954
960 int64_t Int64Value(bool* lossless = nullptr) const;
961
966 int WordCount() const;
967
976 void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
977
978 V8_INLINE static BigInt* Cast(v8::Data* data) {
979#ifdef V8_ENABLE_CHECKS
980 CheckCast(data);
981#endif
982 return static_cast<BigInt*>(data);
983 }
984
985 private:
986 BigInt();
987 static void CheckCast(v8::Data* that);
988};
989
991 using S = internal::Address;
992 using I = internal::Internals;
993 I::CheckInitialized(isolate);
994 S* slot = I::GetRootSlot(isolate, I::kEmptyStringRootIndex);
995 return Local<String>::FromSlot(slot);
996}
997
998// static
999String::ExternalStringResourceBase* String::ReadExternalStringResource(
1000 v8::Isolate* isolate, internal::Address obj) {
1001 using A = internal::Address;
1002 using I = internal::Internals;
1003 // The resource field references a cppgc wrapper object (through the
1004 // CppHeapPointerTable when pointer compression is enabled), which in turn
1005 // holds the resource. The wrapper is nullptr if the type check fails.
1006 A wrapper = reinterpret_cast<A>(internal::ReadCppHeapPointerField<void>(
1007 isolate, obj, I::kStringResourceOffset,
1009 if (wrapper == internal::kNullAddress) return nullptr;
1010 return *reinterpret_cast<ExternalStringResourceBase* const*>(
1011 wrapper + I::kExternalStringResourceWrapperResourceOffset);
1012}
1013
1015 using A = internal::Address;
1016 using I = internal::Internals;
1018
1019 ExternalStringResource* result;
1020 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
1021 Isolate* isolate = I::GetCurrentIsolate();
1022 result = static_cast<ExternalStringResource*>(
1023 ReadExternalStringResource(isolate, obj));
1024 } else {
1025 result = GetExternalStringResourceSlow();
1026 }
1027#ifdef V8_ENABLE_CHECKS
1028 VerifyExternalStringResourceBase(result, Encoding::TWO_BYTE_ENCODING);
1029#endif
1030 return result;
1031}
1032
1035 using A = internal::Address;
1036 using I = internal::Internals;
1038 const ExternalOneByteStringResource* result;
1039 if (I::IsExternalOneByteString(I::GetInstanceType(obj))) {
1040 Isolate* isolate = I::GetCurrentIsolate();
1041 result = static_cast<const ExternalOneByteStringResource*>(
1042 ReadExternalStringResource(isolate, obj));
1043 } else {
1044 result = GetExternalOneByteStringResourceSlow();
1045 }
1046#ifdef V8_ENABLE_CHECKS
1047 VerifyExternalStringResourceBase(result, Encoding::ONE_BYTE_ENCODING);
1048#endif
1049 return result;
1050}
1051
1053 v8::Isolate* isolate, String::Encoding* encoding_out) const {
1054 using A = internal::Address;
1055 using I = internal::Internals;
1057 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
1058 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
1060 if (type == I::kExternalOneByteRepresentationTag ||
1061 type == I::kExternalTwoByteRepresentationTag) {
1062 resource = ReadExternalStringResource(isolate, obj);
1063 } else {
1064 resource = GetExternalStringResourceBaseSlow(encoding_out);
1065 }
1066#ifdef V8_ENABLE_CHECKS
1067 VerifyExternalStringResourceBase(resource, *encoding_out);
1068#endif
1069 return resource;
1070}
1071
1073 String::Encoding* encoding_out) const {
1075 return GetExternalStringResourceBase(isolate, encoding_out);
1076}
1077
1078// --- Statics ---
1079
1081 using S = internal::Address;
1082 using I = internal::Internals;
1083 I::CheckInitialized(isolate);
1084 S* slot = I::GetRootSlot(isolate, I::kUndefinedValueRootIndex);
1085 return Local<Primitive>::FromSlot(slot);
1086}
1087
1089 using S = internal::Address;
1090 using I = internal::Internals;
1091 I::CheckInitialized(isolate);
1092 S* slot = I::GetRootSlot(isolate, I::kNullValueRootIndex);
1093 return Local<Primitive>::FromSlot(slot);
1094}
1095
1097 using S = internal::Address;
1098 using I = internal::Internals;
1099 I::CheckInitialized(isolate);
1100 S* slot = I::GetRootSlot(isolate, I::kTrueValueRootIndex);
1101 return Local<Boolean>::FromSlot(slot);
1102}
1103
1105 using S = internal::Address;
1106 using I = internal::Internals;
1107 I::CheckInitialized(isolate);
1108 S* slot = I::GetRootSlot(isolate, I::kFalseValueRootIndex);
1109 return Local<Boolean>::FromSlot(slot);
1110}
1111
1112Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
1113 return value ? True(isolate) : False(isolate);
1114}
1115
1116} // namespace v8
1117
1118#endif // INCLUDE_V8_PRIMITIVE_H_
Definition: v8-primitive.h:933
uint64_t Uint64Value(bool *lossless=nullptr) const
static BigInt * Cast(v8::Data *data)
Definition: v8-primitive.h:978
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)
int WordCount() const
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:38
bool Value() const
static Local< Boolean > New(Isolate *isolate, bool value)
Definition: v8-primitive.h:1112
static Boolean * Cast(v8::Data *data)
Definition: v8-primitive.h:41
Definition: v8-data.h:18
Definition: v8-primitive.h:764
virtual ~ExternalResourceVisitor()=default
virtual void VisitExternalString(Local< String > string)
Definition: v8-primitive.h:767
Definition: v8-primitive.h:897
static Int32 * Cast(v8::Data *data)
Definition: v8-primitive.h:900
int32_t Value() const
Definition: v8-primitive.h:877
static Integer * Cast(v8::Data *data)
Definition: v8-primitive.h:882
static Local< Integer > New(Isolate *isolate, int32_t value)
static Local< Integer > NewFromUnsigned(Isolate *isolate, uint32_t value)
int64_t Value() const
Definition: v8-isolate.h:299
Definition: v8-local-handle.h:356
Definition: v8-local-handle.h:724
Definition: v8-primitive.h:82
static Name * Cast(Data *data)
Definition: v8-primitive.h:93
int GetIdentityHash()
Definition: v8-primitive.h:843
static Local< Number > New(Isolate *isolate, double value)
static Local< Number > New(Isolate *isolate, Int value)
Definition: v8-primitive.h:850
static Local< Number > New(Isolate *isolate, UInt value)
Definition: v8-primitive.h:857
static Number * Cast(v8::Data *data)
Definition: v8-primitive.h:860
double Value() const
Definition: v8-primitive.h:834
Definition: v8-primitive.h:61
static Local< PrimitiveArray > New(Isolate *isolate, int length)
Local< Primitive > Get(Isolate *isolate, int index)
static PrimitiveArray * Cast(Data *data)
Definition: v8-primitive.h:68
int Length() const
void Set(Isolate *isolate, int index, Local< Primitive > item)
Definition: v8-primitive.h:32
Definition: v8-primitive.h:430
const char * cached_data() const
Definition: v8-primitive.h:452
~ExternalOneByteStringResource() override=default
virtual const char * data() const =0
virtual void RecordSharedMemoryUsage(const void *location, size_t size)=0
Definition: v8-primitive.h:274
void operator=(const ExternalStringResourceBase &)=delete
virtual void Unaccount(Isolate *isolate)
Definition: v8-primitive.h:293
ExternalStringResourceBase(const ExternalStringResourceBase &)=delete
virtual ~ExternalStringResourceBase()=default
virtual void Unlock() const
Definition: v8-primitive.h:360
virtual void EstimateSharedMemoryUsage(SharedMemoryUsageRecorder *recorder) const
Definition: v8-primitive.h:323
virtual bool IsCacheable() const
Definition: v8-primitive.h:283
virtual void Lock() const
Definition: v8-primitive.h:355
virtual size_t EstimateMemoryUsage() const
Definition: v8-primitive.h:304
virtual void Dispose()
Definition: v8-primitive.h:342
Definition: v8-primitive.h:375
virtual const uint16_t * data() const =0
const uint16_t * cached_data() const
Definition: v8-primitive.h:399
virtual size_t length() const =0
~ExternalStringResource() override=default
Definition: v8-primitive.h:634
char * operator*()
Definition: v8-primitive.h:638
Utf8Value(Isolate *isolate, Local< v8::Value > obj)
Utf8Value(const Utf8Value &)=delete
const char * operator*() const
Definition: v8-primitive.h:639
void operator=(const Utf8Value &)=delete
std::string_view as_view() const
Definition: v8-primitive.h:641
size_t length() const
Definition: v8-primitive.h:640
Definition: v8-primitive.h:694
bool is_one_byte() const
Definition: v8-primitive.h:711
const uint16_t * data16_
Definition: v8-primitive.h:723
void operator=(const ValueView &)=delete
const uint8_t * data8() const
Definition: v8-primitive.h:698
uint32_t length() const
Definition: v8-primitive.h:710
ValueView(const ValueView &)=delete
const uint16_t * data16() const
Definition: v8-primitive.h:704
ValueView(Isolate *isolate, Local< v8::String > str)
const uint8_t * data8_
Definition: v8-primitive.h:722
Definition: v8-primitive.h:664
const uint16_t * operator*() const
Definition: v8-primitive.h:672
uint32_t length() const
Definition: v8-primitive.h:673
Value(const Value &)=delete
void operator=(const Value &)=delete
Definition: v8-primitive.h:127
bool IsInStringTable(Isolate *isolate) const
bool IsExternalTwoByte() const
bool IsExternal() const
static Local< String > Concat(Isolate *isolate, Local< String > left, Local< String > right)
bool IsExternalOneByte() const
bool ContainsOnlyOneByte() const
ExternalStringResourceBase * GetExternalStringResourceBase(v8::Isolate *isolate, Encoding *encoding_out) const
Definition: v8-primitive.h:1052
Encoding
Definition: v8-primitive.h:136
@ ONE_BYTE_ENCODING
Definition: v8-primitive.h:139
@ TWO_BYTE_ENCODING
Definition: v8-primitive.h:138
void WriteOneByte(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)
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)
bool IsOneByte() const
static String * Cast(v8::Data *data)
Definition: v8-primitive.h:496
size_t Utf8Length(Isolate *isolate) const
static Local< String > Empty(Isolate *isolate)
Definition: v8-primitive.h:990
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:513
ExternalStringResource * GetExternalStringResource() const
Definition: v8-primitive.h:1014
size_t WriteUtf8(Isolate *isolate, char *buffer, size_t capacity, int flags=WriteFlags::kNone, size_t *processed_characters_return=nullptr) const
const ExternalOneByteStringResource * GetExternalOneByteStringResource() const
Definition: v8-primitive.h:1034
void Write(Isolate *isolate, uint32_t offset, uint32_t length, uint16_t *buffer, int flags=WriteFlags::kNone) const
int Length() const
Definition: v8-primitive.h:773
static Local< Symbol > GetDispose(Isolate *isolate)
static Local< Symbol > GetMatch(Isolate *isolate)
static Local< Symbol > GetIterator(Isolate *isolate)
static Symbol * Cast(Data *data)
Definition: v8-primitive.h:818
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 > GetAsyncDispose(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:915
static Uint32 * Cast(v8::Data *data)
Definition: v8-primitive.h:918
uint32_t Value() const
Definition: v8-value.h:32
Definition: v8-internal.h:965
static v8::Isolate * GetCurrentIsolate()
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1836
uintptr_t Address
Definition: v8-internal.h:38
Definition: libplatform.h:15
Local< Primitive > Null(Isolate *isolate)
Definition: v8-primitive.h:1088
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1080
Local< Boolean > False(Isolate *isolate)
Definition: v8-primitive.h:1104
Local< Boolean > True(Isolate *isolate)
Definition: v8-primitive.h:1096
NewStringType
Definition: v8-primitive.h:110
Definition: v8-primitive.h:169
#define V8_EXPORT
Definition: v8config.h:875
#define V8_INLINE
Definition: v8config.h:519
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:632
#define V8_DEPRECATED(message)
Definition: v8config.h:624
#define V8_WARN_UNUSED_RESULT
Definition: v8config.h:689