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;
27class StringForwardingTable;
28} // namespace internal
29
33class V8_EXPORT Primitive : public Value {};
34
39class V8_EXPORT Boolean : public Primitive {
40 public:
41 bool Value() const;
42 V8_INLINE static Boolean* Cast(v8::Data* data) {
43#ifdef V8_ENABLE_CHECKS
44 CheckCast(data);
45#endif
46 return static_cast<Boolean*>(data);
47 }
48
49 V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
50
51 private:
52 static void CheckCast(v8::Data* that);
53};
54
63 public:
64 static Local<PrimitiveArray> New(Isolate* isolate, int length);
65 int Length() const;
66 void Set(Isolate* isolate, int index, Local<Primitive> item);
67 Local<Primitive> Get(Isolate* isolate, int index);
68
70#ifdef V8_ENABLE_CHECKS
71 CheckCast(data);
72#endif
73 return reinterpret_cast<PrimitiveArray*>(data);
74 }
75
76 private:
77 static void CheckCast(Data* obj);
78};
79
83class V8_EXPORT Name : public Primitive {
84 public:
93
94 V8_INLINE static Name* Cast(Data* data) {
95#ifdef V8_ENABLE_CHECKS
96 CheckCast(data);
97#endif
98 return static_cast<Name*>(data);
99 }
100
101 private:
102 static void CheckCast(Data* that);
103};
104
111enum class NewStringType {
115 kNormal,
116
123};
124
128class V8_EXPORT String : public Name {
129 public:
130#ifndef V8_LOWER_LIMITS_MODE
131 static constexpr int kMaxLength =
132 internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
133#else
134 static constexpr int kMaxLength = 1 << 20;
135#endif // V8_LOWER_LIMITS_MODE
136
137 enum Encoding {
138 UNKNOWN_ENCODING = 0x1,
139 TWO_BYTE_ENCODING = 0x0,
140 ONE_BYTE_ENCODING = 0x8
141 };
145 int Length() const;
146
150 size_t Utf8Length(Isolate* isolate) const;
151 // TODO(http://crbug.com/373485796): deprecate and remove.
152 V8_DEPRECATE_SOON("Use Utf8Length(isolate) instead.")
153 size_t Utf8LengthV2(Isolate* isolate) const { return Utf8Length(isolate); }
154
161 bool IsOneByte() const;
162
169
170 struct WriteFlags {
171 enum {
172 kNone = 0,
173 // Indicates that the output string should be null-terminated. In that
174 // case, the output buffer must include sufficient space for the
175 // additional null character.
176 kNullTerminate = 1,
177 // Used by WriteUtf8 to replace orphan surrogate code units with the
178 // unicode replacement character. Needs to be set to guarantee valid UTF-8
179 // output.
180 kReplaceInvalidUtf8 = 2
181 };
182 };
183
196 void Write(Isolate* isolate, uint32_t offset, uint32_t length,
197 uint16_t* buffer, int flags = WriteFlags::kNone) const;
198 void WriteOneByte(Isolate* isolate, uint32_t offset, uint32_t length,
199 uint8_t* buffer, int flags = WriteFlags::kNone) const;
200 // TODO(http://crbug.com/373485796): deprecate and remove.
201 V8_DEPRECATE_SOON("Use Write(..) instead.")
202 void WriteV2(Isolate* isolate, uint32_t offset, uint32_t length,
203 uint16_t* buffer, int flags = WriteFlags::kNone) const {
204 Write(isolate, offset, length, buffer, flags);
205 }
206 // TODO(http://crbug.com/373485796): deprecate and remove.
207 V8_DEPRECATE_SOON("Use WriteOneByte(..) instead.")
208 void WriteOneByteV2(Isolate* isolate, uint32_t offset, uint32_t length,
209 uint8_t* buffer, int flags = WriteFlags::kNone) const {
210 WriteOneByte(isolate, offset, length, buffer, flags);
211 }
212
232 size_t WriteUtf8(Isolate* isolate, char* buffer, size_t capacity,
233 int flags = WriteFlags::kNone,
234 size_t* processed_characters_return = nullptr) const;
235 // TODO(http://crbug.com/373485796): deprecate and remove.
236 V8_DEPRECATE_SOON("Use WriteUtf8(..) instead.")
237 size_t WriteUtf8V2(Isolate* isolate, char* buffer, size_t capacity,
238 int flags = WriteFlags::kNone,
239 size_t* processed_characters_return = nullptr) const {
240 return WriteUtf8(isolate, buffer, capacity, flags,
241 processed_characters_return);
242 }
243
247 V8_INLINE static Local<String> Empty(Isolate* isolate);
248
252 bool IsExternal() const;
253
257 bool IsExternalTwoByte() const;
258
262 bool IsExternalOneByte() const;
263
269
273 bool IsInStringTable(Isolate* isolate) const;
274
276 public:
277 virtual ~ExternalStringResourceBase() = default;
278
284 virtual bool IsCacheable() const { return true; }
285
294 virtual void Unaccount(Isolate* isolate) {}
295
305 virtual size_t EstimateMemoryUsage() const {
306 return kDefaultMemoryEstimate;
307 }
308 static constexpr size_t kDefaultMemoryEstimate = static_cast<size_t>(-1);
309
311 public:
316 virtual void RecordSharedMemoryUsage(const void* location,
317 size_t size) = 0;
318 };
319
325 SharedMemoryUsageRecorder* recorder) const {}
326
327 // Disallow copying and assigning.
330
331 protected:
333
343 virtual void Dispose() { delete this; }
344
356 virtual void Lock() const {}
357
361 virtual void Unlock() const {}
362
363 private:
364 friend class internal::ExternalString;
365 friend class internal::ExternalStringResourceWrapper;
366 friend class v8::String;
367 friend class internal::StringForwardingTable;
368 friend class internal::ScopedExternalStringLock;
369 };
370
378 public:
383 ~ExternalStringResource() override = default;
384
389 virtual const uint16_t* data() const = 0;
390
394 virtual size_t length() const = 0;
395
401 const uint16_t* cached_data() const {
402 CheckCachedDataInvariants();
403 return cached_data_;
404 }
405
411
412 protected:
414
415 private:
416 void CheckCachedDataInvariants() const;
417
418 const uint16_t* cached_data_ = nullptr;
419 };
420
433 public:
438 ~ExternalOneByteStringResource() override = default;
439
444 virtual const char* data() const = 0;
445
447 virtual size_t length() const = 0;
448
454 const char* cached_data() const {
455 CheckCachedDataInvariants();
456 return cached_data_;
457 }
458
464
465 protected:
467
468 private:
469 void CheckCachedDataInvariants() const;
470
471 const char* cached_data_ = nullptr;
472 };
473
479 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
480 v8::Isolate* isolate, Encoding* encoding_out) const;
481 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
482 Encoding* encoding_out) const;
488 // TODO(pthier): Change return type to const ExternalStringResource*.
489 V8_INLINE ExternalStringResource* GetExternalStringResource() const;
490
495 V8_INLINE const ExternalOneByteStringResource*
496 GetExternalOneByteStringResource() const;
497
498 V8_INLINE static String* Cast(v8::Data* data) {
499#ifdef V8_ENABLE_CHECKS
500 CheckCast(data);
501#endif
502 return static_cast<String*>(data);
503 }
504
514 template <int N>
516 Isolate* isolate, const char (&literal)[N],
517 NewStringType type = NewStringType::kNormal) {
518 static_assert(N <= kMaxLength, "String is too long");
519 return NewFromUtf8Literal(isolate, literal, type, N - 1);
520 }
521
525 Isolate* isolate, const char* data,
526 NewStringType type = NewStringType::kNormal, int length = -1);
527
531 Isolate* isolate, const uint8_t* data,
532 NewStringType type = NewStringType::kNormal, int length = -1);
533
537 Isolate* isolate, const uint16_t* data,
538 NewStringType type = NewStringType::kNormal, int length = -1);
539
545 Local<String> right);
546
556 Isolate* isolate, ExternalStringResource* resource);
557
567 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
568 bool MakeExternal(ExternalStringResource* resource);
569
579 bool MakeExternal(Isolate* isolate, ExternalStringResource* resource);
580
589 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
590 Isolate* isolate, ExternalOneByteStringResource* resource);
591
601 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
602 bool MakeExternal(ExternalOneByteStringResource* resource);
603
613 bool MakeExternal(Isolate* isolate, ExternalOneByteStringResource* resource);
614
619 bool CanMakeExternal(Encoding encoding) const;
620
624 bool StringEquals(Local<String> str) const;
625
637 public:
640 char* operator*() { return str_; }
641 const char* operator*() const { return str_; }
642 size_t length() const { return length_; }
643 std::string_view as_view() const { return std::string_view(str_, length_); }
644
645 // Disallow copying and assigning.
646 Utf8Value(const Utf8Value&) = delete;
647 void operator=(const Utf8Value&) = delete;
648
649 private:
650 char* str_;
651 size_t length_;
652 };
653
665 "Prefer using String::ValueView if you can, or string->Write to a "
666 "buffer if you cannot.") V8_EXPORT Value {
667 public:
669 "Prefer using String::ValueView if you can, or string->Write to a "
670 "buffer if you cannot.")
671 Value(Isolate* isolate, Local<v8::Value> obj);
673 uint16_t* operator*() { return str_; }
674 const uint16_t* operator*() const { return str_; }
675 uint32_t length() const { return length_; }
676
677 // Disallow copying and assigning.
678 Value(const Value&) = delete;
679 void operator=(const Value&) = delete;
680
681 private:
682 uint16_t* str_;
683 uint32_t length_;
684 };
685
697 public:
700 const uint8_t* data8() const {
701#if V8_ENABLE_CHECKS
702 CheckOneByte(true);
703#endif
704 return data8_;
705 }
706 const uint16_t* data16() const {
707#if V8_ENABLE_CHECKS
708 CheckOneByte(false);
709#endif
710 return data16_;
711 }
712 uint32_t length() const { return length_; }
713 bool is_one_byte() const { return is_one_byte_; }
714
715 // Disallow copying and assigning.
716 ValueView(const ValueView&) = delete;
717 void operator=(const ValueView&) = delete;
718
719 private:
720 void CheckOneByte(bool is_one_byte) const;
721
722 Local<v8::String> flat_str_;
723 union {
724 const uint8_t* data8_;
725 const uint16_t* data16_;
726 };
727 uint32_t length_;
728 bool is_one_byte_;
729 // Avoid exposing the internal DisallowGarbageCollection scope.
730 alignas(internal::Internals::
731 kDisallowGarbageCollectionAlign) char no_gc_debug_scope_
732 [internal::Internals::kDisallowGarbageCollectionSize];
733 };
734
735 private:
736 void VerifyExternalStringResourceBase(const ExternalStringResourceBase* v,
737 Encoding encoding) const;
738 // Reads the resource of the external string at {obj}. Generally returns a
739 // resource unless corruption results in sandbox violations.
740 V8_INLINE static ExternalStringResourceBase* ReadExternalStringResource(
741 v8::Isolate* isolate, internal::Address obj);
742 ExternalStringResource* GetExternalStringResourceSlow() const;
743 const ExternalOneByteStringResource* GetExternalOneByteStringResourceSlow()
744 const;
745 ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
746 String::Encoding* encoding_out) const;
747
748 static Local<v8::String> NewFromUtf8Literal(Isolate* isolate,
749 const char* literal,
750 NewStringType type, int length);
751
752 static void CheckCast(v8::Data* that);
753};
754
755// Zero-length string specialization (templated string size includes
756// terminator).
757template <>
759 Isolate* isolate, const char (&literal)[1], NewStringType type) {
760 return String::Empty(isolate);
761}
762
767 public:
768 virtual ~ExternalResourceVisitor() = default;
769 virtual void VisitExternalString(Local<String> string) {}
770};
771
775class V8_EXPORT Symbol : public Name {
776 public:
781
786 static Local<Symbol> New(Isolate* isolate,
787 Local<String> description = Local<String>());
788
797 static Local<Symbol> For(Isolate* isolate, Local<String> description);
798
803 static Local<Symbol> ForApi(Isolate* isolate, Local<String> description);
804
805 // Well-known symbols
819
820 V8_INLINE static Symbol* Cast(Data* data) {
821#ifdef V8_ENABLE_CHECKS
822 CheckCast(data);
823#endif
824 return static_cast<Symbol*>(data);
825 }
826
827 private:
828 Symbol();
829 static void CheckCast(Data* that);
830};
831
837 private:
838 Numeric();
839 static void CheckCast(v8::Data* that);
840};
841
845class V8_EXPORT Number : public Numeric {
846 public:
847 double Value() const;
848 static Local<Number> New(Isolate* isolate, double value);
849 template <typename Int>
850 requires(std::is_integral<Int>::value && !std::is_same<Int, bool>::value &&
851 std::is_signed_v<Int> && sizeof(Int) <= sizeof(int32_t))
852 V8_INLINE static Local<Number> New(Isolate* isolate, Int value) {
853 return NewFromInt32(isolate, value);
854 }
855 template <typename UInt>
856 requires(std::is_integral<UInt>::value &&
857 !std::is_same<UInt, bool>::value && std::is_unsigned_v<UInt> &&
858 sizeof(UInt) <= sizeof(uint32_t))
859 V8_INLINE static Local<Number> New(Isolate* isolate, UInt value) {
860 return NewFromUint32(isolate, value);
861 }
862 V8_INLINE static Number* Cast(v8::Data* data) {
863#ifdef V8_ENABLE_CHECKS
864 CheckCast(data);
865#endif
866 return static_cast<Number*>(data);
867 }
868
869 private:
870 Number();
871 static Local<Number> NewFromInt32(Isolate* isolate, int32_t value);
872 static Local<Number> NewFromUint32(Isolate* isolate, uint32_t value);
873 static void CheckCast(v8::Data* that);
874};
875
879class V8_EXPORT Integer : public Number {
880 public:
881 static Local<Integer> New(Isolate* isolate, int32_t value);
882 static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
883 int64_t Value() const;
885#ifdef V8_ENABLE_CHECKS
886 CheckCast(data);
887#endif
888 return static_cast<Integer*>(data);
889 }
890
891 private:
892 Integer();
893 static void CheckCast(v8::Data* that);
894};
895
899class V8_EXPORT Int32 : public Integer {
900 public:
901 int32_t Value() const;
902 V8_INLINE static Int32* Cast(v8::Data* data) {
903#ifdef V8_ENABLE_CHECKS
904 CheckCast(data);
905#endif
906 return static_cast<Int32*>(data);
907 }
908
909 private:
910 Int32();
911 static void CheckCast(v8::Data* that);
912};
913
917class V8_EXPORT Uint32 : public Integer {
918 public:
919 uint32_t Value() const;
920 V8_INLINE static Uint32* Cast(v8::Data* data) {
921#ifdef V8_ENABLE_CHECKS
922 CheckCast(data);
923#endif
924 return static_cast<Uint32*>(data);
925 }
926
927 private:
928 Uint32();
929 static void CheckCast(v8::Data* that);
930};
931
935class V8_EXPORT BigInt : public Numeric {
936 public:
937 static Local<BigInt> New(Isolate* isolate, int64_t value);
938 static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
946 static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
947 int word_count, const uint64_t* words);
948
955 uint64_t Uint64Value(bool* lossless = nullptr) const;
956
962 int64_t Int64Value(bool* lossless = nullptr) const;
963
968 int WordCount() const;
969
978 void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
979
980 V8_INLINE static BigInt* Cast(v8::Data* data) {
981#ifdef V8_ENABLE_CHECKS
982 CheckCast(data);
983#endif
984 return static_cast<BigInt*>(data);
985 }
986
987 private:
988 BigInt();
989 static void CheckCast(v8::Data* that);
990};
991
993 using S = internal::Address;
994 using I = internal::Internals;
995 I::CheckInitialized(isolate);
996 S* slot = I::GetRootSlot(isolate, I::kEmptyStringRootIndex);
997 return Local<String>::FromSlot(slot);
998}
999
1000// static
1001String::ExternalStringResourceBase* String::ReadExternalStringResource(
1002 v8::Isolate* isolate, internal::Address obj) {
1003 using A = internal::Address;
1004 using I = internal::Internals;
1005 // The resource field references a cppgc wrapper object (through the
1006 // CppHeapPointerTable when pointer compression is enabled), which in turn
1007 // holds the resource. The wrapper is nullptr if the type check fails.
1008 A wrapper = reinterpret_cast<A>(internal::ReadCppHeapPointerField<void>(
1009 isolate, obj, I::kStringResourceOffset,
1011 if (wrapper == internal::kNullAddress) return nullptr;
1012 return *reinterpret_cast<ExternalStringResourceBase* const*>(
1013 wrapper + I::kExternalStringResourceWrapperResourceOffset);
1014}
1015
1017 using A = internal::Address;
1018 using I = internal::Internals;
1020
1021 ExternalStringResource* result;
1022 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
1023 Isolate* isolate = I::GetCurrentIsolate();
1024 result = static_cast<ExternalStringResource*>(
1025 ReadExternalStringResource(isolate, obj));
1026 } else {
1027 result = GetExternalStringResourceSlow();
1028 }
1029#ifdef V8_ENABLE_CHECKS
1030 VerifyExternalStringResourceBase(result, Encoding::TWO_BYTE_ENCODING);
1031#endif
1032 return result;
1033}
1034
1037 using A = internal::Address;
1038 using I = internal::Internals;
1040 const ExternalOneByteStringResource* result;
1041 if (I::IsExternalOneByteString(I::GetInstanceType(obj))) {
1042 Isolate* isolate = I::GetCurrentIsolate();
1043 result = static_cast<const ExternalOneByteStringResource*>(
1044 ReadExternalStringResource(isolate, obj));
1045 } else {
1046 result = GetExternalOneByteStringResourceSlow();
1047 }
1048#ifdef V8_ENABLE_CHECKS
1049 VerifyExternalStringResourceBase(result, Encoding::ONE_BYTE_ENCODING);
1050#endif
1051 return result;
1052}
1053
1055 v8::Isolate* isolate, String::Encoding* encoding_out) const {
1056 using A = internal::Address;
1057 using I = internal::Internals;
1059 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
1060 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
1062 if (type == I::kExternalOneByteRepresentationTag ||
1063 type == I::kExternalTwoByteRepresentationTag) {
1064 resource = ReadExternalStringResource(isolate, obj);
1065 } else {
1066 resource = GetExternalStringResourceBaseSlow(encoding_out);
1067 }
1068#ifdef V8_ENABLE_CHECKS
1069 VerifyExternalStringResourceBase(resource, *encoding_out);
1070#endif
1071 return resource;
1072}
1073
1075 String::Encoding* encoding_out) const {
1077 return GetExternalStringResourceBase(isolate, encoding_out);
1078}
1079
1080// --- Statics ---
1081
1083 using S = internal::Address;
1084 using I = internal::Internals;
1085 I::CheckInitialized(isolate);
1086 S* slot = I::GetRootSlot(isolate, I::kUndefinedValueRootIndex);
1087 return Local<Primitive>::FromSlot(slot);
1088}
1089
1091 using S = internal::Address;
1092 using I = internal::Internals;
1093 I::CheckInitialized(isolate);
1094 S* slot = I::GetRootSlot(isolate, I::kNullValueRootIndex);
1095 return Local<Primitive>::FromSlot(slot);
1096}
1097
1099 using S = internal::Address;
1100 using I = internal::Internals;
1101 I::CheckInitialized(isolate);
1102 S* slot = I::GetRootSlot(isolate, I::kTrueValueRootIndex);
1103 return Local<Boolean>::FromSlot(slot);
1104}
1105
1107 using S = internal::Address;
1108 using I = internal::Internals;
1109 I::CheckInitialized(isolate);
1110 S* slot = I::GetRootSlot(isolate, I::kFalseValueRootIndex);
1111 return Local<Boolean>::FromSlot(slot);
1112}
1113
1114Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
1115 return value ? True(isolate) : False(isolate);
1116}
1117
1118} // namespace v8
1119
1120#endif // INCLUDE_V8_PRIMITIVE_H_
Definition: v8-primitive.h:935
uint64_t Uint64Value(bool *lossless=nullptr) const
static BigInt * Cast(v8::Data *data)
Definition: v8-primitive.h:980
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:39
bool Value() const
static Local< Boolean > New(Isolate *isolate, bool value)
Definition: v8-primitive.h:1114
static Boolean * Cast(v8::Data *data)
Definition: v8-primitive.h:42
Definition: v8-data.h:18
Definition: v8-primitive.h:766
virtual ~ExternalResourceVisitor()=default
virtual void VisitExternalString(Local< String > string)
Definition: v8-primitive.h:769
Definition: v8-primitive.h:899
static Int32 * Cast(v8::Data *data)
Definition: v8-primitive.h:902
int32_t Value() const
Definition: v8-primitive.h:879
static Integer * Cast(v8::Data *data)
Definition: v8-primitive.h:884
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:305
Definition: v8-local-handle.h:359
Definition: v8-local-handle.h:730
Definition: v8-primitive.h:83
static Name * Cast(Data *data)
Definition: v8-primitive.h:94
int GetIdentityHash()
Definition: v8-primitive.h:845
static Local< Number > New(Isolate *isolate, double value)
static Local< Number > New(Isolate *isolate, Int value)
Definition: v8-primitive.h:852
static Local< Number > New(Isolate *isolate, UInt value)
Definition: v8-primitive.h:859
static Number * Cast(v8::Data *data)
Definition: v8-primitive.h:862
double Value() const
Definition: v8-primitive.h:836
Definition: v8-primitive.h:62
static Local< PrimitiveArray > New(Isolate *isolate, int length)
Local< Primitive > Get(Isolate *isolate, int index)
static PrimitiveArray * Cast(Data *data)
Definition: v8-primitive.h:69
int Length() const
void Set(Isolate *isolate, int index, Local< Primitive > item)
Definition: v8-primitive.h:33
Definition: v8-primitive.h:432
const char * cached_data() const
Definition: v8-primitive.h:454
~ExternalOneByteStringResource() override=default
virtual const char * data() const =0
virtual void RecordSharedMemoryUsage(const void *location, size_t size)=0
Definition: v8-primitive.h:275
void operator=(const ExternalStringResourceBase &)=delete
virtual void Unaccount(Isolate *isolate)
Definition: v8-primitive.h:294
ExternalStringResourceBase(const ExternalStringResourceBase &)=delete
virtual ~ExternalStringResourceBase()=default
virtual void Unlock() const
Definition: v8-primitive.h:361
virtual void EstimateSharedMemoryUsage(SharedMemoryUsageRecorder *recorder) const
Definition: v8-primitive.h:324
virtual bool IsCacheable() const
Definition: v8-primitive.h:284
virtual void Lock() const
Definition: v8-primitive.h:356
virtual size_t EstimateMemoryUsage() const
Definition: v8-primitive.h:305
virtual void Dispose()
Definition: v8-primitive.h:343
Definition: v8-primitive.h:377
virtual const uint16_t * data() const =0
const uint16_t * cached_data() const
Definition: v8-primitive.h:401
virtual size_t length() const =0
~ExternalStringResource() override=default
Definition: v8-primitive.h:636
char * operator*()
Definition: v8-primitive.h:640
Utf8Value(Isolate *isolate, Local< v8::Value > obj)
Utf8Value(const Utf8Value &)=delete
const char * operator*() const
Definition: v8-primitive.h:641
void operator=(const Utf8Value &)=delete
std::string_view as_view() const
Definition: v8-primitive.h:643
size_t length() const
Definition: v8-primitive.h:642
Definition: v8-primitive.h:696
bool is_one_byte() const
Definition: v8-primitive.h:713
const uint16_t * data16_
Definition: v8-primitive.h:725
void operator=(const ValueView &)=delete
const uint8_t * data8() const
Definition: v8-primitive.h:700
uint32_t length() const
Definition: v8-primitive.h:712
ValueView(const ValueView &)=delete
const uint16_t * data16() const
Definition: v8-primitive.h:706
ValueView(Isolate *isolate, Local< v8::String > str)
const uint8_t * data8_
Definition: v8-primitive.h:724
Definition: v8-primitive.h:666
const uint16_t * operator*() const
Definition: v8-primitive.h:674
uint32_t length() const
Definition: v8-primitive.h:675
Value(const Value &)=delete
void operator=(const Value &)=delete
Definition: v8-primitive.h:128
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:1054
Encoding
Definition: v8-primitive.h:137
@ ONE_BYTE_ENCODING
Definition: v8-primitive.h:140
@ TWO_BYTE_ENCODING
Definition: v8-primitive.h:139
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:498
size_t Utf8Length(Isolate *isolate) const
static Local< String > Empty(Isolate *isolate)
Definition: v8-primitive.h:992
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:515
ExternalStringResource * GetExternalStringResource() const
Definition: v8-primitive.h:1016
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:1036
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:775
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:820
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:917
static Uint32 * Cast(v8::Data *data)
Definition: v8-primitive.h:920
uint32_t Value() const
Definition: v8-value.h:32
Definition: v8-internal.h:969
static v8::Isolate * GetCurrentIsolate()
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1838
uintptr_t Address
Definition: v8-internal.h:38
Definition: libplatform.h:15
Local< Primitive > Null(Isolate *isolate)
Definition: v8-primitive.h:1090
Local< Primitive > Undefined(Isolate *isolate)
Definition: v8-primitive.h:1082
Local< Boolean > False(Isolate *isolate)
Definition: v8-primitive.h:1106
Local< Boolean > True(Isolate *isolate)
Definition: v8-primitive.h:1098
NewStringType
Definition: v8-primitive.h:111
Definition: v8-primitive.h:170
#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