File indexing completed on 2026-09-13 09:14:39
0001
0002
0003
0004
0005 #ifndef INCLUDE_V8_PRIMITIVE_H_
0006 #define INCLUDE_V8_PRIMITIVE_H_
0007
0008 #include "v8-data.h" // NOLINT(build/include_directory)
0009 #include "v8-internal.h" // NOLINT(build/include_directory)
0010 #include "v8-local-handle.h" // NOLINT(build/include_directory)
0011 #include "v8-value.h" // NOLINT(build/include_directory)
0012 #include "v8config.h" // NOLINT(build/include_directory)
0013
0014 namespace v8 {
0015
0016 class Context;
0017 class Isolate;
0018 class String;
0019
0020 namespace internal {
0021 class ExternalString;
0022 class ScopedExternalStringLock;
0023 class StringForwardingTable;
0024 }
0025
0026
0027
0028
0029 class V8_EXPORT Primitive : public Value {};
0030
0031
0032
0033
0034
0035 class V8_EXPORT Boolean : public Primitive {
0036 public:
0037 bool Value() const;
0038 V8_INLINE static Boolean* Cast(v8::Data* data) {
0039 #ifdef V8_ENABLE_CHECKS
0040 CheckCast(data);
0041 #endif
0042 return static_cast<Boolean*>(data);
0043 }
0044
0045 V8_INLINE static Local<Boolean> New(Isolate* isolate, bool value);
0046
0047 private:
0048 static void CheckCast(v8::Data* that);
0049 };
0050
0051
0052
0053
0054
0055
0056
0057
0058 class V8_EXPORT PrimitiveArray : public Data {
0059 public:
0060 static Local<PrimitiveArray> New(Isolate* isolate, int length);
0061 int Length() const;
0062 void Set(Isolate* isolate, int index, Local<Primitive> item);
0063 Local<Primitive> Get(Isolate* isolate, int index);
0064
0065 V8_INLINE static PrimitiveArray* Cast(Data* data) {
0066 #ifdef V8_ENABLE_CHECKS
0067 CheckCast(data);
0068 #endif
0069 return reinterpret_cast<PrimitiveArray*>(data);
0070 }
0071
0072 private:
0073 static void CheckCast(Data* obj);
0074 };
0075
0076
0077
0078
0079 class V8_EXPORT Name : public Primitive {
0080 public:
0081
0082
0083
0084
0085
0086
0087
0088 int GetIdentityHash();
0089
0090 V8_INLINE static Name* Cast(Data* data) {
0091 #ifdef V8_ENABLE_CHECKS
0092 CheckCast(data);
0093 #endif
0094 return static_cast<Name*>(data);
0095 }
0096
0097 private:
0098 static void CheckCast(Data* that);
0099 };
0100
0101
0102
0103
0104
0105
0106
0107 enum class NewStringType {
0108
0109
0110
0111 kNormal,
0112
0113
0114
0115
0116
0117
0118 kInternalized
0119 };
0120
0121
0122
0123
0124 class V8_EXPORT String : public Name {
0125 public:
0126 static constexpr int kMaxLength =
0127 internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
0128
0129 enum Encoding {
0130 UNKNOWN_ENCODING = 0x1,
0131 TWO_BYTE_ENCODING = 0x0,
0132 ONE_BYTE_ENCODING = 0x8
0133 };
0134
0135
0136
0137 int Length() const;
0138
0139
0140
0141
0142
0143 size_t Utf8LengthV2(Isolate* isolate) const;
0144
0145
0146
0147
0148
0149
0150
0151 bool IsOneByte() const;
0152
0153
0154
0155
0156
0157
0158 bool ContainsOnlyOneByte() const;
0159
0160 struct WriteFlags {
0161 enum {
0162 kNone = 0,
0163
0164
0165
0166 kNullTerminate = 1,
0167
0168
0169
0170 kReplaceInvalidUtf8 = 2
0171 };
0172 };
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 void WriteV2(Isolate* isolate, uint32_t offset, uint32_t length,
0189 uint16_t* buffer, int flags = WriteFlags::kNone) const;
0190 void WriteOneByteV2(Isolate* isolate, uint32_t offset, uint32_t length,
0191 uint8_t* buffer, int flags = WriteFlags::kNone) const;
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 size_t WriteUtf8V2(Isolate* isolate, char* buffer, size_t capacity,
0214 int flags = WriteFlags::kNone,
0215 size_t* processed_characters_return = nullptr) const;
0216
0217
0218
0219
0220 V8_INLINE static Local<String> Empty(Isolate* isolate);
0221
0222
0223
0224
0225 bool IsExternal() const;
0226
0227
0228
0229
0230 bool IsExternalTwoByte() const;
0231
0232
0233
0234
0235 bool IsExternalOneByte() const;
0236
0237
0238
0239
0240
0241 Local<String> InternalizeString(Isolate* isolate);
0242
0243 class V8_EXPORT ExternalStringResourceBase {
0244 public:
0245 virtual ~ExternalStringResourceBase() = default;
0246
0247
0248
0249
0250
0251
0252 virtual bool IsCacheable() const { return true; }
0253
0254
0255
0256
0257
0258
0259 virtual void Unaccount(Isolate* isolate) {}
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 virtual size_t EstimateMemoryUsage() const {
0271 return kDefaultMemoryEstimate;
0272 }
0273 static constexpr size_t kDefaultMemoryEstimate = static_cast<size_t>(-1);
0274
0275 class V8_EXPORT SharedMemoryUsageRecorder {
0276 public:
0277
0278
0279
0280
0281 virtual void RecordSharedMemoryUsage(const void* location,
0282 size_t size) = 0;
0283 };
0284
0285
0286
0287
0288
0289 virtual void EstimateSharedMemoryUsage(
0290 SharedMemoryUsageRecorder* recorder) const {}
0291
0292
0293 ExternalStringResourceBase(const ExternalStringResourceBase&) = delete;
0294 void operator=(const ExternalStringResourceBase&) = delete;
0295
0296 protected:
0297 ExternalStringResourceBase() = default;
0298
0299
0300
0301
0302
0303
0304
0305 virtual void Dispose() { delete this; }
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318 virtual void Lock() const {}
0319
0320
0321
0322
0323 virtual void Unlock() const {}
0324
0325 private:
0326 friend class internal::ExternalString;
0327 friend class v8::String;
0328 friend class internal::StringForwardingTable;
0329 friend class internal::ScopedExternalStringLock;
0330 };
0331
0332
0333
0334
0335
0336
0337
0338 class V8_EXPORT ExternalStringResource : public ExternalStringResourceBase {
0339 public:
0340
0341
0342
0343
0344 ~ExternalStringResource() override = default;
0345
0346
0347
0348
0349
0350 virtual const uint16_t* data() const = 0;
0351
0352
0353
0354
0355 virtual size_t length() const = 0;
0356
0357
0358
0359
0360
0361
0362 const uint16_t* cached_data() const {
0363 CheckCachedDataInvariants();
0364 return cached_data_;
0365 }
0366
0367
0368
0369
0370
0371 void UpdateDataCache();
0372
0373 protected:
0374 ExternalStringResource() = default;
0375
0376 private:
0377 void CheckCachedDataInvariants() const;
0378
0379 const uint16_t* cached_data_ = nullptr;
0380 };
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392 class V8_EXPORT ExternalOneByteStringResource
0393 : public ExternalStringResourceBase {
0394 public:
0395
0396
0397
0398
0399 ~ExternalOneByteStringResource() override = default;
0400
0401
0402
0403
0404
0405 virtual const char* data() const = 0;
0406
0407
0408 virtual size_t length() const = 0;
0409
0410
0411
0412
0413
0414
0415 const char* cached_data() const {
0416 CheckCachedDataInvariants();
0417 return cached_data_;
0418 }
0419
0420
0421
0422
0423
0424 void UpdateDataCache();
0425
0426 protected:
0427 ExternalOneByteStringResource() = default;
0428
0429 private:
0430 void CheckCachedDataInvariants() const;
0431
0432 const char* cached_data_ = nullptr;
0433 };
0434
0435
0436
0437
0438
0439
0440 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
0441 v8::Isolate* isolate, Encoding* encoding_out) const;
0442 V8_INLINE ExternalStringResourceBase* GetExternalStringResourceBase(
0443 Encoding* encoding_out) const;
0444
0445
0446
0447
0448
0449 V8_INLINE ExternalStringResource* GetExternalStringResource() const;
0450
0451
0452
0453
0454
0455 const ExternalOneByteStringResource* GetExternalOneByteStringResource() const;
0456
0457 V8_INLINE static String* Cast(v8::Data* data) {
0458 #ifdef V8_ENABLE_CHECKS
0459 CheckCast(data);
0460 #endif
0461 return static_cast<String*>(data);
0462 }
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473 template <int N>
0474 static V8_WARN_UNUSED_RESULT Local<String> NewFromUtf8Literal(
0475 Isolate* isolate, const char (&literal)[N],
0476 NewStringType type = NewStringType::kNormal) {
0477 static_assert(N <= kMaxLength, "String is too long");
0478 return NewFromUtf8Literal(isolate, literal, type, N - 1);
0479 }
0480
0481
0482
0483 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
0484 Isolate* isolate, const char* data,
0485 NewStringType type = NewStringType::kNormal, int length = -1);
0486
0487
0488
0489 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
0490 Isolate* isolate, const uint8_t* data,
0491 NewStringType type = NewStringType::kNormal, int length = -1);
0492
0493
0494
0495 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
0496 Isolate* isolate, const uint16_t* data,
0497 NewStringType type = NewStringType::kNormal, int length = -1);
0498
0499
0500
0501
0502
0503 static Local<String> Concat(Isolate* isolate, Local<String> left,
0504 Local<String> right);
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalTwoByte(
0515 Isolate* isolate, ExternalStringResource* resource);
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
0527 bool MakeExternal(ExternalStringResource* resource);
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538 bool MakeExternal(Isolate* isolate, ExternalStringResource* resource);
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548 static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
0549 Isolate* isolate, ExternalOneByteStringResource* resource);
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560 V8_DEPRECATE_SOON("Use the version with the isolate argument instead.")
0561 bool MakeExternal(ExternalOneByteStringResource* resource);
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572 bool MakeExternal(Isolate* isolate, ExternalOneByteStringResource* resource);
0573
0574
0575
0576
0577
0578 bool CanMakeExternal(Encoding encoding) const;
0579
0580
0581
0582
0583 bool StringEquals(Local<String> str) const;
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595 class V8_EXPORT Utf8Value {
0596 public:
0597 Utf8Value(Isolate* isolate, Local<v8::Value> obj);
0598 ~Utf8Value();
0599 char* operator*() { return str_; }
0600 const char* operator*() const { return str_; }
0601 size_t length() const { return length_; }
0602
0603
0604 Utf8Value(const Utf8Value&) = delete;
0605 void operator=(const Utf8Value&) = delete;
0606
0607 private:
0608 char* str_;
0609 size_t length_;
0610 };
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622 class V8_EXPORT Value {
0623 public:
0624 V8_DEPRECATE_SOON(
0625 "Prefer using String::ValueView if you can, or string->Write to a "
0626 "buffer if you cannot.")
0627 Value(Isolate* isolate, Local<v8::Value> obj);
0628 ~Value();
0629 uint16_t* operator*() { return str_; }
0630 const uint16_t* operator*() const { return str_; }
0631 uint32_t length() const { return length_; }
0632
0633
0634 Value(const Value&) = delete;
0635 void operator=(const Value&) = delete;
0636
0637 private:
0638 uint16_t* str_;
0639 uint32_t length_;
0640 };
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652 class V8_EXPORT ValueView {
0653 public:
0654 ValueView(Isolate* isolate, Local<v8::String> str);
0655 ~ValueView();
0656 const uint8_t* data8() const {
0657 #if V8_ENABLE_CHECKS
0658 CheckOneByte(true);
0659 #endif
0660 return data8_;
0661 }
0662 const uint16_t* data16() const {
0663 #if V8_ENABLE_CHECKS
0664 CheckOneByte(false);
0665 #endif
0666 return data16_;
0667 }
0668 uint32_t length() const { return length_; }
0669 bool is_one_byte() const { return is_one_byte_; }
0670
0671
0672 ValueView(const ValueView&) = delete;
0673 void operator=(const ValueView&) = delete;
0674
0675 private:
0676 void CheckOneByte(bool is_one_byte) const;
0677
0678 Local<v8::String> flat_str_;
0679 union {
0680 const uint8_t* data8_;
0681 const uint16_t* data16_;
0682 };
0683 uint32_t length_;
0684 bool is_one_byte_;
0685
0686 alignas(internal::Internals::
0687 kDisallowGarbageCollectionAlign) char no_gc_debug_scope_
0688 [internal::Internals::kDisallowGarbageCollectionSize];
0689 };
0690
0691 private:
0692 void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
0693 Encoding encoding) const;
0694 void VerifyExternalStringResource(ExternalStringResource* val) const;
0695 ExternalStringResource* GetExternalStringResourceSlow() const;
0696 ExternalStringResourceBase* GetExternalStringResourceBaseSlow(
0697 String::Encoding* encoding_out) const;
0698
0699 static Local<v8::String> NewFromUtf8Literal(Isolate* isolate,
0700 const char* literal,
0701 NewStringType type, int length);
0702
0703 static void CheckCast(v8::Data* that);
0704 };
0705
0706
0707
0708 template <>
0709 inline V8_WARN_UNUSED_RESULT Local<String> String::NewFromUtf8Literal(
0710 Isolate* isolate, const char (&literal)[1], NewStringType type) {
0711 return String::Empty(isolate);
0712 }
0713
0714
0715
0716
0717 class V8_EXPORT ExternalResourceVisitor {
0718 public:
0719 virtual ~ExternalResourceVisitor() = default;
0720 virtual void VisitExternalString(Local<String> string) {}
0721 };
0722
0723
0724
0725
0726 class V8_EXPORT Symbol : public Name {
0727 public:
0728
0729
0730
0731 Local<Value> Description(Isolate* isolate) const;
0732
0733
0734
0735
0736
0737 static Local<Symbol> New(Isolate* isolate,
0738 Local<String> description = Local<String>());
0739
0740
0741
0742
0743
0744
0745
0746
0747
0748 static Local<Symbol> For(Isolate* isolate, Local<String> description);
0749
0750
0751
0752
0753
0754 static Local<Symbol> ForApi(Isolate* isolate, Local<String> description);
0755
0756
0757 static Local<Symbol> GetAsyncIterator(Isolate* isolate);
0758 static Local<Symbol> GetHasInstance(Isolate* isolate);
0759 static Local<Symbol> GetIsConcatSpreadable(Isolate* isolate);
0760 static Local<Symbol> GetIterator(Isolate* isolate);
0761 static Local<Symbol> GetMatch(Isolate* isolate);
0762 static Local<Symbol> GetReplace(Isolate* isolate);
0763 static Local<Symbol> GetSearch(Isolate* isolate);
0764 static Local<Symbol> GetSplit(Isolate* isolate);
0765 static Local<Symbol> GetToPrimitive(Isolate* isolate);
0766 static Local<Symbol> GetToStringTag(Isolate* isolate);
0767 static Local<Symbol> GetUnscopables(Isolate* isolate);
0768 static Local<Symbol> GetDispose(Isolate* isolate);
0769 static Local<Symbol> GetAsyncDispose(Isolate* isolate);
0770
0771 V8_INLINE static Symbol* Cast(Data* data) {
0772 #ifdef V8_ENABLE_CHECKS
0773 CheckCast(data);
0774 #endif
0775 return static_cast<Symbol*>(data);
0776 }
0777
0778 private:
0779 Symbol();
0780 static void CheckCast(Data* that);
0781 };
0782
0783
0784
0785
0786
0787 class V8_EXPORT Numeric : public Primitive {
0788 private:
0789 Numeric();
0790 static void CheckCast(v8::Data* that);
0791 };
0792
0793
0794
0795
0796 class V8_EXPORT Number : public Numeric {
0797 public:
0798 double Value() const;
0799 static Local<Number> New(Isolate* isolate, double value);
0800 template <typename Int>
0801 requires(std::is_integral<Int>::value && !std::is_same<Int, bool>::value &&
0802 std::is_signed_v<Int> && sizeof(Int) <= sizeof(int32_t))
0803 V8_INLINE static Local<Number> New(Isolate* isolate, Int value) {
0804 return NewFromInt32(isolate, value);
0805 }
0806 template <typename UInt>
0807 requires(std::is_integral<UInt>::value &&
0808 !std::is_same<UInt, bool>::value && std::is_unsigned_v<UInt> &&
0809 sizeof(UInt) <= sizeof(uint32_t))
0810 V8_INLINE static Local<Number> New(Isolate* isolate, UInt value) {
0811 return NewFromUint32(isolate, value);
0812 }
0813 V8_INLINE static Number* Cast(v8::Data* data) {
0814 #ifdef V8_ENABLE_CHECKS
0815 CheckCast(data);
0816 #endif
0817 return static_cast<Number*>(data);
0818 }
0819
0820 private:
0821 Number();
0822 static Local<Number> NewFromInt32(Isolate* isolate, int32_t value);
0823 static Local<Number> NewFromUint32(Isolate* isolate, uint32_t value);
0824 static void CheckCast(v8::Data* that);
0825 };
0826
0827
0828
0829
0830 class V8_EXPORT Integer : public Number {
0831 public:
0832 static Local<Integer> New(Isolate* isolate, int32_t value);
0833 static Local<Integer> NewFromUnsigned(Isolate* isolate, uint32_t value);
0834 int64_t Value() const;
0835 V8_INLINE static Integer* Cast(v8::Data* data) {
0836 #ifdef V8_ENABLE_CHECKS
0837 CheckCast(data);
0838 #endif
0839 return static_cast<Integer*>(data);
0840 }
0841
0842 private:
0843 Integer();
0844 static void CheckCast(v8::Data* that);
0845 };
0846
0847
0848
0849
0850 class V8_EXPORT Int32 : public Integer {
0851 public:
0852 int32_t Value() const;
0853 V8_INLINE static Int32* Cast(v8::Data* data) {
0854 #ifdef V8_ENABLE_CHECKS
0855 CheckCast(data);
0856 #endif
0857 return static_cast<Int32*>(data);
0858 }
0859
0860 private:
0861 Int32();
0862 static void CheckCast(v8::Data* that);
0863 };
0864
0865
0866
0867
0868 class V8_EXPORT Uint32 : public Integer {
0869 public:
0870 uint32_t Value() const;
0871 V8_INLINE static Uint32* Cast(v8::Data* data) {
0872 #ifdef V8_ENABLE_CHECKS
0873 CheckCast(data);
0874 #endif
0875 return static_cast<Uint32*>(data);
0876 }
0877
0878 private:
0879 Uint32();
0880 static void CheckCast(v8::Data* that);
0881 };
0882
0883
0884
0885
0886 class V8_EXPORT BigInt : public Numeric {
0887 public:
0888 static Local<BigInt> New(Isolate* isolate, int64_t value);
0889 static Local<BigInt> NewFromUnsigned(Isolate* isolate, uint64_t value);
0890
0891
0892
0893
0894
0895
0896
0897 static MaybeLocal<BigInt> NewFromWords(Local<Context> context, int sign_bit,
0898 int word_count, const uint64_t* words);
0899
0900
0901
0902
0903
0904
0905
0906 uint64_t Uint64Value(bool* lossless = nullptr) const;
0907
0908
0909
0910
0911
0912
0913 int64_t Int64Value(bool* lossless = nullptr) const;
0914
0915
0916
0917
0918
0919 int WordCount() const;
0920
0921
0922
0923
0924
0925
0926
0927
0928
0929 void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const;
0930
0931 V8_INLINE static BigInt* Cast(v8::Data* data) {
0932 #ifdef V8_ENABLE_CHECKS
0933 CheckCast(data);
0934 #endif
0935 return static_cast<BigInt*>(data);
0936 }
0937
0938 private:
0939 BigInt();
0940 static void CheckCast(v8::Data* that);
0941 };
0942
0943 Local<String> String::Empty(Isolate* isolate) {
0944 using S = internal::Address;
0945 using I = internal::Internals;
0946 I::CheckInitialized(isolate);
0947 S* slot = I::GetRootSlot(isolate, I::kEmptyStringRootIndex);
0948 return Local<String>::FromSlot(slot);
0949 }
0950
0951 String::ExternalStringResource* String::GetExternalStringResource() const {
0952 using A = internal::Address;
0953 using I = internal::Internals;
0954 A obj = internal::ValueHelper::ValueAsAddress(this);
0955
0956 ExternalStringResource* result;
0957 if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
0958 Isolate* isolate = I::GetCurrentIsolateForSandbox();
0959 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
0960 isolate, obj, I::kStringResourceOffset);
0961 result = reinterpret_cast<String::ExternalStringResource*>(value);
0962 } else {
0963 result = GetExternalStringResourceSlow();
0964 }
0965 #ifdef V8_ENABLE_CHECKS
0966 VerifyExternalStringResource(result);
0967 #endif
0968 return result;
0969 }
0970
0971 String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
0972 v8::Isolate* isolate, String::Encoding* encoding_out) const {
0973 using A = internal::Address;
0974 using I = internal::Internals;
0975 A obj = internal::ValueHelper::ValueAsAddress(this);
0976 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
0977 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
0978 ExternalStringResourceBase* resource;
0979 if (type == I::kExternalOneByteRepresentationTag ||
0980 type == I::kExternalTwoByteRepresentationTag) {
0981 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
0982 isolate, obj, I::kStringResourceOffset);
0983 resource = reinterpret_cast<ExternalStringResourceBase*>(value);
0984 } else {
0985 resource = GetExternalStringResourceBaseSlow(encoding_out);
0986 }
0987 #ifdef V8_ENABLE_CHECKS
0988 VerifyExternalStringResourceBase(resource, *encoding_out);
0989 #endif
0990 return resource;
0991 }
0992
0993 String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
0994 String::Encoding* encoding_out) const {
0995 using A = internal::Address;
0996 using I = internal::Internals;
0997 A obj = internal::ValueHelper::ValueAsAddress(this);
0998 int type = I::GetInstanceType(obj) & I::kStringRepresentationAndEncodingMask;
0999 *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
1000 ExternalStringResourceBase* resource;
1001 if (type == I::kExternalOneByteRepresentationTag ||
1002 type == I::kExternalTwoByteRepresentationTag) {
1003 Isolate* isolate = I::GetCurrentIsolateForSandbox();
1004 A value = I::ReadExternalPointerField<internal::kExternalStringResourceTag>(
1005 isolate, obj, I::kStringResourceOffset);
1006 resource = reinterpret_cast<ExternalStringResourceBase*>(value);
1007 } else {
1008 resource = GetExternalStringResourceBaseSlow(encoding_out);
1009 }
1010 #ifdef V8_ENABLE_CHECKS
1011 VerifyExternalStringResourceBase(resource, *encoding_out);
1012 #endif
1013 return resource;
1014 }
1015
1016
1017
1018 V8_INLINE Local<Primitive> Undefined(Isolate* isolate) {
1019 using S = internal::Address;
1020 using I = internal::Internals;
1021 I::CheckInitialized(isolate);
1022 S* slot = I::GetRootSlot(isolate, I::kUndefinedValueRootIndex);
1023 return Local<Primitive>::FromSlot(slot);
1024 }
1025
1026 V8_INLINE Local<Primitive> Null(Isolate* isolate) {
1027 using S = internal::Address;
1028 using I = internal::Internals;
1029 I::CheckInitialized(isolate);
1030 S* slot = I::GetRootSlot(isolate, I::kNullValueRootIndex);
1031 return Local<Primitive>::FromSlot(slot);
1032 }
1033
1034 V8_INLINE Local<Boolean> True(Isolate* isolate) {
1035 using S = internal::Address;
1036 using I = internal::Internals;
1037 I::CheckInitialized(isolate);
1038 S* slot = I::GetRootSlot(isolate, I::kTrueValueRootIndex);
1039 return Local<Boolean>::FromSlot(slot);
1040 }
1041
1042 V8_INLINE Local<Boolean> False(Isolate* isolate) {
1043 using S = internal::Address;
1044 using I = internal::Internals;
1045 I::CheckInitialized(isolate);
1046 S* slot = I::GetRootSlot(isolate, I::kFalseValueRootIndex);
1047 return Local<Boolean>::FromSlot(slot);
1048 }
1049
1050 Local<Boolean> Boolean::New(Isolate* isolate, bool value) {
1051 return value ? True(isolate) : False(isolate);
1052 }
1053
1054 }
1055
1056 #endif