File indexing completed on 2025-02-21 10:05:27
0001
0002
0003
0004
0005 #ifndef INCLUDE_V8_TEMPLATE_H_
0006 #define INCLUDE_V8_TEMPLATE_H_
0007
0008 #include <cstddef>
0009 #include <string_view>
0010
0011 #include "v8-data.h" // NOLINT(build/include_directory)
0012 #include "v8-function-callback.h" // NOLINT(build/include_directory)
0013 #include "v8-local-handle.h" // NOLINT(build/include_directory)
0014 #include "v8-memory-span.h" // NOLINT(build/include_directory)
0015 #include "v8-object.h" // NOLINT(build/include_directory)
0016 #include "v8config.h" // NOLINT(build/include_directory)
0017
0018 namespace v8 {
0019
0020 class CFunction;
0021 class FunctionTemplate;
0022 class ObjectTemplate;
0023 class Signature;
0024
0025
0026
0027 #define V8_INTRINSICS_LIST(F) \
0028 F(ArrayProto_entries, array_entries_iterator) \
0029 F(ArrayProto_forEach, array_for_each_iterator) \
0030 F(ArrayProto_keys, array_keys_iterator) \
0031 F(ArrayProto_values, array_values_iterator) \
0032 F(ArrayPrototype, initial_array_prototype) \
0033 F(AsyncIteratorPrototype, initial_async_iterator_prototype) \
0034 F(ErrorPrototype, initial_error_prototype) \
0035 F(IteratorPrototype, initial_iterator_prototype) \
0036 F(MapIteratorPrototype, initial_map_iterator_prototype) \
0037 F(ObjProto_valueOf, object_value_of_function) \
0038 F(SetIteratorPrototype, initial_set_iterator_prototype)
0039
0040 enum Intrinsic {
0041 #define V8_DECL_INTRINSIC(name, iname) k##name,
0042 V8_INTRINSICS_LIST(V8_DECL_INTRINSIC)
0043 #undef V8_DECL_INTRINSIC
0044 };
0045
0046
0047
0048
0049 class V8_EXPORT Template : public Data {
0050 public:
0051
0052
0053
0054
0055
0056 void Set(Local<Name> name, Local<Data> value,
0057 PropertyAttribute attributes = None);
0058 void SetPrivate(Local<Private> name, Local<Data> value,
0059 PropertyAttribute attributes = None);
0060 V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value,
0061 PropertyAttribute attributes = None);
0062
0063 void SetAccessorProperty(
0064 Local<Name> name,
0065 Local<FunctionTemplate> getter = Local<FunctionTemplate>(),
0066 Local<FunctionTemplate> setter = Local<FunctionTemplate>(),
0067 PropertyAttribute attribute = None);
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 V8_DEPRECATE_SOON("Use SetNativeDataProperty without AccessControl instead")
0084 void SetNativeDataProperty(
0085 Local<String> name, AccessorGetterCallback getter,
0086 AccessorSetterCallback setter, Local<Value> data,
0087 PropertyAttribute attribute, AccessControl settings,
0088 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
0089 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
0090 V8_DEPRECATE_SOON("Use SetNativeDataProperty without AccessControl instead")
0091 void SetNativeDataProperty(
0092 Local<Name> name, AccessorNameGetterCallback getter,
0093 AccessorNameSetterCallback setter, Local<Value> data,
0094 PropertyAttribute attribute, AccessControl settings,
0095 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
0096 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
0097 V8_DEPRECATE_SOON("Use SetNativeDataProperty with Local<Name> instead")
0098 void SetNativeDataProperty(
0099 Local<String> name, AccessorGetterCallback getter,
0100 AccessorSetterCallback setter = nullptr,
0101 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
0102 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
0103 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
0104 void SetNativeDataProperty(
0105 Local<Name> name, AccessorNameGetterCallback getter,
0106 AccessorNameSetterCallback setter = nullptr,
0107 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
0108 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
0109 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
0110
0111
0112
0113
0114
0115 void SetLazyDataProperty(
0116 Local<Name> name, AccessorNameGetterCallback getter,
0117 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
0118 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
0119 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
0120
0121
0122
0123
0124
0125 void SetIntrinsicDataProperty(Local<Name> name, Intrinsic intrinsic,
0126 PropertyAttribute attribute = None);
0127
0128 private:
0129 Template();
0130
0131 friend class ObjectTemplate;
0132 friend class FunctionTemplate;
0133 };
0134
0135
0136
0137
0138
0139 enum class Intercepted : uint8_t { kNo = 0, kYes = 1 };
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 using NamedPropertyGetterCallback = Intercepted (*)(
0184 Local<Name> property, const PropertyCallbackInfo<Value>& info);
0185
0186
0187
0188
0189
0190 using GenericNamedPropertyGetterCallback =
0191 void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211 using NamedPropertySetterCallback =
0212 Intercepted (*)(Local<Name> property, Local<Value> value,
0213 const PropertyCallbackInfo<void>& info);
0214
0215
0216
0217
0218
0219
0220
0221
0222 using GenericNamedPropertySetterCallback =
0223 void (*)(Local<Name> property, Local<Value> value,
0224 const PropertyCallbackInfo<Value>& info);
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251 using NamedPropertyQueryCallback = Intercepted (*)(
0252 Local<Name> property, const PropertyCallbackInfo<Integer>& info);
0253
0254
0255
0256
0257
0258
0259 using GenericNamedPropertyQueryCallback =
0260 void (*)(Local<Name> property, const PropertyCallbackInfo<Integer>& info);
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 using NamedPropertyDeleterCallback = Intercepted (*)(
0286 Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
0287
0288
0289
0290
0291
0292
0293
0294
0295 using GenericNamedPropertyDeleterCallback =
0296 void (*)(Local<Name> property, const PropertyCallbackInfo<Boolean>& info);
0297
0298
0299
0300
0301
0302
0303
0304 using NamedPropertyEnumeratorCallback =
0305 void (*)(const PropertyCallbackInfo<Array>& info);
0306
0307
0308 using GenericNamedPropertyEnumeratorCallback = NamedPropertyEnumeratorCallback;
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 using NamedPropertyDefinerCallback =
0329 Intercepted (*)(Local<Name> property, const PropertyDescriptor& desc,
0330 const PropertyCallbackInfo<void>& info);
0331
0332
0333
0334
0335
0336
0337
0338
0339 using GenericNamedPropertyDefinerCallback =
0340 void (*)(Local<Name> property, const PropertyDescriptor& desc,
0341 const PropertyCallbackInfo<Value>& info);
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366 using NamedPropertyDescriptorCallback = Intercepted (*)(
0367 Local<Name> property, const PropertyCallbackInfo<Value>& info);
0368
0369
0370
0371
0372
0373
0374 using GenericNamedPropertyDescriptorCallback =
0375 void (*)(Local<Name> property, const PropertyCallbackInfo<Value>& info);
0376
0377
0378
0379
0380
0381
0382
0383
0384 using IndexedPropertyGetterCallbackV2 =
0385 Intercepted (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
0386
0387 using IndexedPropertyGetterCallback =
0388 void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
0389
0390
0391
0392
0393 using IndexedPropertySetterCallbackV2 = Intercepted (*)(
0394 uint32_t index, Local<Value> value, const PropertyCallbackInfo<void>& info);
0395
0396 using IndexedPropertySetterCallback =
0397 void (*)(uint32_t index, Local<Value> value,
0398 const PropertyCallbackInfo<Value>& info);
0399
0400
0401
0402
0403 using IndexedPropertyQueryCallbackV2 =
0404 Intercepted (*)(uint32_t index, const PropertyCallbackInfo<Integer>& info);
0405
0406 using IndexedPropertyQueryCallback =
0407 void (*)(uint32_t index, const PropertyCallbackInfo<Integer>& info);
0408
0409
0410
0411
0412 using IndexedPropertyDeleterCallbackV2 =
0413 Intercepted (*)(uint32_t index, const PropertyCallbackInfo<Boolean>& info);
0414
0415 using IndexedPropertyDeleterCallback =
0416 void (*)(uint32_t index, const PropertyCallbackInfo<Boolean>& info);
0417
0418
0419
0420
0421
0422
0423
0424 using IndexedPropertyEnumeratorCallback =
0425 void (*)(const PropertyCallbackInfo<Array>& info);
0426
0427
0428
0429
0430 using IndexedPropertyDefinerCallbackV2 =
0431 Intercepted (*)(uint32_t index, const PropertyDescriptor& desc,
0432 const PropertyCallbackInfo<void>& info);
0433
0434 using IndexedPropertyDefinerCallback =
0435 void (*)(uint32_t index, const PropertyDescriptor& desc,
0436 const PropertyCallbackInfo<Value>& info);
0437
0438
0439
0440
0441 using IndexedPropertyDescriptorCallbackV2 =
0442 Intercepted (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
0443
0444 using IndexedPropertyDescriptorCallback =
0445 void (*)(uint32_t index, const PropertyCallbackInfo<Value>& info);
0446
0447
0448
0449
0450
0451 using AccessCheckCallback = bool (*)(Local<Context> accessing_context,
0452 Local<Object> accessed_object,
0453 Local<Value> data);
0454
0455 enum class ConstructorBehavior { kThrow, kAllow };
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564 class V8_EXPORT FunctionTemplate : public Template {
0565 public:
0566
0567 static Local<FunctionTemplate> New(
0568 Isolate* isolate, FunctionCallback callback = nullptr,
0569 Local<Value> data = Local<Value>(),
0570 Local<Signature> signature = Local<Signature>(), int length = 0,
0571 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
0572 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
0573 const CFunction* c_function = nullptr, uint16_t instance_type = 0,
0574 uint16_t allowed_receiver_instance_type_range_start = 0,
0575 uint16_t allowed_receiver_instance_type_range_end = 0);
0576
0577
0578 static Local<FunctionTemplate> NewWithCFunctionOverloads(
0579 Isolate* isolate, FunctionCallback callback = nullptr,
0580 Local<Value> data = Local<Value>(),
0581 Local<Signature> signature = Local<Signature>(), int length = 0,
0582 ConstructorBehavior behavior = ConstructorBehavior::kAllow,
0583 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
0584 const MemorySpan<const CFunction>& c_function_overloads = {});
0585
0586
0587
0588
0589 static Local<FunctionTemplate> NewWithCache(
0590 Isolate* isolate, FunctionCallback callback,
0591 Local<Private> cache_property, Local<Value> data = Local<Value>(),
0592 Local<Signature> signature = Local<Signature>(), int length = 0,
0593 SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
0594
0595
0596 V8_WARN_UNUSED_RESULT MaybeLocal<Function> GetFunction(
0597 Local<Context> context);
0598
0599
0600
0601
0602
0603
0604
0605
0606 V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewRemoteInstance();
0607
0608
0609
0610
0611
0612
0613
0614 void SetCallHandler(
0615 FunctionCallback callback, Local<Value> data = Local<Value>(),
0616 SideEffectType side_effect_type = SideEffectType::kHasSideEffect,
0617 const MemorySpan<const CFunction>& c_function_overloads = {});
0618
0619
0620 void SetLength(int length);
0621
0622
0623 Local<ObjectTemplate> InstanceTemplate();
0624
0625
0626
0627
0628
0629
0630 void Inherit(Local<FunctionTemplate> parent);
0631
0632
0633
0634
0635
0636 Local<ObjectTemplate> PrototypeTemplate();
0637
0638
0639
0640
0641
0642
0643
0644 void SetPrototypeProviderTemplate(Local<FunctionTemplate> prototype_provider);
0645
0646
0647
0648
0649
0650
0651 void SetClassName(Local<String> name);
0652
0653
0654
0655
0656
0657 void SetAcceptAnyReceiver(bool value);
0658
0659
0660
0661
0662
0663 void ReadOnlyPrototype();
0664
0665
0666
0667
0668
0669 void RemovePrototype();
0670
0671
0672
0673
0674
0675 bool HasInstance(Local<Value> object);
0676
0677
0678
0679
0680
0681
0682
0683
0684 bool IsLeafTemplateForApiObject(v8::Local<v8::Value> value) const;
0685
0686 V8_INLINE static FunctionTemplate* Cast(Data* data);
0687
0688 private:
0689 FunctionTemplate();
0690
0691 static void CheckCast(Data* that);
0692 friend class Context;
0693 friend class ObjectTemplate;
0694 };
0695
0696
0697
0698
0699
0700 enum class PropertyHandlerFlags {
0701
0702
0703
0704 kNone = 0,
0705
0706
0707
0708
0709
0710
0711 kNonMasking = 1,
0712
0713
0714
0715
0716
0717 kOnlyInterceptStrings = 1 << 1,
0718
0719
0720
0721
0722 kHasNoSideEffect = 1 << 2,
0723
0724
0725
0726
0727
0728
0729
0730
0731 kInternalNewCallbacksSignatures = 1 << 10,
0732 };
0733
0734 struct NamedPropertyHandlerConfiguration {
0735 private:
0736 static constexpr PropertyHandlerFlags WithNewSignatureFlag(
0737 PropertyHandlerFlags flags) {
0738 return static_cast<PropertyHandlerFlags>(
0739 static_cast<int>(flags) |
0740 static_cast<int>(
0741 PropertyHandlerFlags::kInternalNewCallbacksSignatures));
0742 }
0743
0744 public:
0745 NamedPropertyHandlerConfiguration(
0746 NamedPropertyGetterCallback getter,
0747 NamedPropertySetterCallback setter,
0748 NamedPropertyQueryCallback query,
0749 NamedPropertyDeleterCallback deleter,
0750 NamedPropertyEnumeratorCallback enumerator,
0751 NamedPropertyDefinerCallback definer,
0752 NamedPropertyDescriptorCallback descriptor,
0753 Local<Value> data = Local<Value>(),
0754 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0755 : getter(reinterpret_cast<void*>(getter)),
0756 setter(reinterpret_cast<void*>(setter)),
0757 query(reinterpret_cast<void*>(query)),
0758 deleter(reinterpret_cast<void*>(deleter)),
0759 enumerator(enumerator),
0760 definer(reinterpret_cast<void*>(definer)),
0761 descriptor(reinterpret_cast<void*>(descriptor)),
0762 data(data),
0763 flags(WithNewSignatureFlag(flags)) {}
0764
0765
0766 NamedPropertyHandlerConfiguration(
0767 GenericNamedPropertyGetterCallback getter,
0768 GenericNamedPropertySetterCallback setter,
0769 GenericNamedPropertyQueryCallback query,
0770 GenericNamedPropertyDeleterCallback deleter,
0771 GenericNamedPropertyEnumeratorCallback enumerator,
0772 GenericNamedPropertyDefinerCallback definer,
0773 GenericNamedPropertyDescriptorCallback descriptor,
0774 Local<Value> data = Local<Value>(),
0775 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0776 : getter(reinterpret_cast<void*>(getter)),
0777 setter(reinterpret_cast<void*>(setter)),
0778 query(reinterpret_cast<void*>(query)),
0779 deleter(reinterpret_cast<void*>(deleter)),
0780 enumerator(enumerator),
0781 definer(reinterpret_cast<void*>(definer)),
0782 descriptor(reinterpret_cast<void*>(descriptor)),
0783 data(data),
0784 flags(flags) {}
0785
0786 explicit NamedPropertyHandlerConfiguration(
0787 NamedPropertyGetterCallback getter,
0788 NamedPropertySetterCallback setter = nullptr,
0789 NamedPropertyQueryCallback query = nullptr,
0790 NamedPropertyDeleterCallback deleter = nullptr,
0791 NamedPropertyEnumeratorCallback enumerator = nullptr,
0792 Local<Value> data = Local<Value>(),
0793 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0794 : getter(reinterpret_cast<void*>(getter)),
0795 setter(reinterpret_cast<void*>(setter)),
0796 query(reinterpret_cast<void*>(query)),
0797 deleter(reinterpret_cast<void*>(deleter)),
0798 enumerator(enumerator),
0799 definer(nullptr),
0800 descriptor(nullptr),
0801 data(data),
0802 flags(WithNewSignatureFlag(flags)) {}
0803
0804
0805 explicit NamedPropertyHandlerConfiguration(
0806 GenericNamedPropertyGetterCallback getter,
0807 GenericNamedPropertySetterCallback setter = nullptr,
0808 GenericNamedPropertyQueryCallback query = nullptr,
0809 GenericNamedPropertyDeleterCallback deleter = nullptr,
0810 GenericNamedPropertyEnumeratorCallback enumerator = nullptr,
0811 Local<Value> data = Local<Value>(),
0812 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0813 : getter(reinterpret_cast<void*>(getter)),
0814 setter(reinterpret_cast<void*>(setter)),
0815 query(reinterpret_cast<void*>(query)),
0816 deleter(reinterpret_cast<void*>(deleter)),
0817 enumerator(enumerator),
0818 definer(nullptr),
0819 descriptor(nullptr),
0820 data(data),
0821 flags(flags) {}
0822
0823 NamedPropertyHandlerConfiguration(
0824 NamedPropertyGetterCallback getter,
0825 NamedPropertySetterCallback setter,
0826 NamedPropertyDescriptorCallback descriptor,
0827 NamedPropertyDeleterCallback deleter,
0828 NamedPropertyEnumeratorCallback enumerator,
0829 NamedPropertyDefinerCallback definer,
0830 Local<Value> data = Local<Value>(),
0831 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0832 : getter(reinterpret_cast<void*>(getter)),
0833 setter(reinterpret_cast<void*>(setter)),
0834 query(nullptr),
0835 deleter(reinterpret_cast<void*>(deleter)),
0836 enumerator(enumerator),
0837 definer(reinterpret_cast<void*>(definer)),
0838 descriptor(reinterpret_cast<void*>(descriptor)),
0839 data(data),
0840 flags(WithNewSignatureFlag(flags)) {}
0841
0842
0843 NamedPropertyHandlerConfiguration(
0844 GenericNamedPropertyGetterCallback getter,
0845 GenericNamedPropertySetterCallback setter,
0846 GenericNamedPropertyDescriptorCallback descriptor,
0847 GenericNamedPropertyDeleterCallback deleter,
0848 GenericNamedPropertyEnumeratorCallback enumerator,
0849 GenericNamedPropertyDefinerCallback definer,
0850 Local<Value> data = Local<Value>(),
0851 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0852 : getter(reinterpret_cast<void*>(getter)),
0853 setter(reinterpret_cast<void*>(setter)),
0854 query(nullptr),
0855 deleter(reinterpret_cast<void*>(deleter)),
0856 enumerator(enumerator),
0857 definer(reinterpret_cast<void*>(definer)),
0858 descriptor(reinterpret_cast<void*>(descriptor)),
0859 data(data),
0860 flags(flags) {}
0861
0862 void* getter;
0863 void* setter;
0864 void* query;
0865 void* deleter;
0866 NamedPropertyEnumeratorCallback enumerator;
0867 void* definer;
0868 void* descriptor;
0869 Local<Value> data;
0870 PropertyHandlerFlags flags;
0871 };
0872
0873 struct IndexedPropertyHandlerConfiguration {
0874 private:
0875 static constexpr PropertyHandlerFlags WithNewSignatureFlag(
0876 PropertyHandlerFlags flags) {
0877 return static_cast<PropertyHandlerFlags>(
0878 static_cast<int>(flags) |
0879 static_cast<int>(
0880 PropertyHandlerFlags::kInternalNewCallbacksSignatures));
0881 }
0882
0883 public:
0884 IndexedPropertyHandlerConfiguration(
0885 IndexedPropertyGetterCallbackV2 getter,
0886 IndexedPropertySetterCallbackV2 setter,
0887 IndexedPropertyQueryCallbackV2 query,
0888 IndexedPropertyDeleterCallbackV2 deleter,
0889 IndexedPropertyEnumeratorCallback enumerator,
0890 IndexedPropertyDefinerCallbackV2 definer,
0891 IndexedPropertyDescriptorCallbackV2 descriptor,
0892 Local<Value> data = Local<Value>(),
0893 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0894 : getter(reinterpret_cast<void*>(getter)),
0895 setter(reinterpret_cast<void*>(setter)),
0896 query(reinterpret_cast<void*>(query)),
0897 deleter(reinterpret_cast<void*>(deleter)),
0898 enumerator(enumerator),
0899 definer(reinterpret_cast<void*>(definer)),
0900 descriptor(reinterpret_cast<void*>(descriptor)),
0901 data(data),
0902 flags(WithNewSignatureFlag(flags)) {}
0903
0904
0905 IndexedPropertyHandlerConfiguration(
0906 IndexedPropertyGetterCallback getter,
0907 IndexedPropertySetterCallback setter,
0908 IndexedPropertyQueryCallback query,
0909 IndexedPropertyDeleterCallback deleter,
0910 IndexedPropertyEnumeratorCallback enumerator,
0911 IndexedPropertyDefinerCallback definer,
0912 IndexedPropertyDescriptorCallback descriptor,
0913 Local<Value> data = Local<Value>(),
0914 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0915 : getter(reinterpret_cast<void*>(getter)),
0916 setter(reinterpret_cast<void*>(setter)),
0917 query(reinterpret_cast<void*>(query)),
0918 deleter(reinterpret_cast<void*>(deleter)),
0919 enumerator(enumerator),
0920 definer(reinterpret_cast<void*>(definer)),
0921 descriptor(reinterpret_cast<void*>(descriptor)),
0922 data(data),
0923 flags(flags) {}
0924
0925 explicit IndexedPropertyHandlerConfiguration(
0926 IndexedPropertyGetterCallbackV2 getter = nullptr,
0927 IndexedPropertySetterCallbackV2 setter = nullptr,
0928 IndexedPropertyQueryCallbackV2 query = nullptr,
0929 IndexedPropertyDeleterCallbackV2 deleter = nullptr,
0930 IndexedPropertyEnumeratorCallback enumerator = nullptr,
0931 Local<Value> data = Local<Value>(),
0932 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0933 : getter(reinterpret_cast<void*>(getter)),
0934 setter(reinterpret_cast<void*>(setter)),
0935 query(reinterpret_cast<void*>(query)),
0936 deleter(reinterpret_cast<void*>(deleter)),
0937 enumerator(enumerator),
0938 definer(nullptr),
0939 descriptor(nullptr),
0940 data(data),
0941 flags(WithNewSignatureFlag(flags)) {}
0942
0943
0944 explicit IndexedPropertyHandlerConfiguration(
0945 IndexedPropertyGetterCallback getter,
0946 IndexedPropertySetterCallback setter = nullptr,
0947 IndexedPropertyQueryCallback query = nullptr,
0948 IndexedPropertyDeleterCallback deleter = nullptr,
0949 IndexedPropertyEnumeratorCallback enumerator = nullptr,
0950 Local<Value> data = Local<Value>(),
0951 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0952 : getter(reinterpret_cast<void*>(getter)),
0953 setter(reinterpret_cast<void*>(setter)),
0954 query(reinterpret_cast<void*>(query)),
0955 deleter(reinterpret_cast<void*>(deleter)),
0956 enumerator(enumerator),
0957 definer(nullptr),
0958 descriptor(nullptr),
0959 data(data),
0960 flags(flags) {}
0961
0962 IndexedPropertyHandlerConfiguration(
0963 IndexedPropertyGetterCallbackV2 getter,
0964 IndexedPropertySetterCallbackV2 setter,
0965 IndexedPropertyDescriptorCallbackV2 descriptor,
0966 IndexedPropertyDeleterCallbackV2 deleter,
0967 IndexedPropertyEnumeratorCallback enumerator,
0968 IndexedPropertyDefinerCallbackV2 definer,
0969 Local<Value> data = Local<Value>(),
0970 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0971 : getter(reinterpret_cast<void*>(getter)),
0972 setter(reinterpret_cast<void*>(setter)),
0973 query(nullptr),
0974 deleter(reinterpret_cast<void*>(deleter)),
0975 enumerator(enumerator),
0976 definer(reinterpret_cast<void*>(definer)),
0977 descriptor(reinterpret_cast<void*>(descriptor)),
0978 data(data),
0979 flags(WithNewSignatureFlag(flags)) {}
0980
0981
0982 IndexedPropertyHandlerConfiguration(
0983 IndexedPropertyGetterCallback getter,
0984 IndexedPropertySetterCallback setter,
0985 IndexedPropertyDescriptorCallback descriptor,
0986 IndexedPropertyDeleterCallback deleter,
0987 IndexedPropertyEnumeratorCallback enumerator,
0988 IndexedPropertyDefinerCallback definer,
0989 Local<Value> data = Local<Value>(),
0990 PropertyHandlerFlags flags = PropertyHandlerFlags::kNone)
0991 : getter(reinterpret_cast<void*>(getter)),
0992 setter(reinterpret_cast<void*>(setter)),
0993 query(nullptr),
0994 deleter(reinterpret_cast<void*>(deleter)),
0995 enumerator(enumerator),
0996 definer(reinterpret_cast<void*>(definer)),
0997 descriptor(reinterpret_cast<void*>(descriptor)),
0998 data(data),
0999 flags(flags) {}
1000
1001 void* getter;
1002 void* setter;
1003 void* query;
1004 void* deleter;
1005 IndexedPropertyEnumeratorCallback enumerator;
1006 void* definer;
1007 void* descriptor;
1008 Local<Value> data;
1009 PropertyHandlerFlags flags;
1010 };
1011
1012
1013
1014
1015
1016
1017
1018 class V8_EXPORT ObjectTemplate : public Template {
1019 public:
1020
1021 static Local<ObjectTemplate> New(
1022 Isolate* isolate,
1023 Local<FunctionTemplate> constructor = Local<FunctionTemplate>());
1024
1025
1026
1027
1028
1029
1030 V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 V8_DEPRECATE_SOON("Use SetAccessor with Local<Name> instead")
1049 void SetAccessor(
1050 Local<String> name, AccessorGetterCallback getter,
1051 AccessorSetterCallback setter = nullptr,
1052 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
1053 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1054 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1055 void SetAccessor(
1056 Local<Name> name, AccessorNameGetterCallback getter,
1057 AccessorNameSetterCallback setter = nullptr,
1058 Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
1059 SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
1060 SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect);
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073 void SetHandler(const NamedPropertyHandlerConfiguration& configuration);
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091 V8_DEPRECATE_SOON("Use SetHandler instead")
1092 void SetIndexedPropertyHandler(
1093 IndexedPropertyGetterCallback getter,
1094 IndexedPropertySetterCallback setter = nullptr,
1095 IndexedPropertyQueryCallback query = nullptr,
1096 IndexedPropertyDeleterCallback deleter = nullptr,
1097 IndexedPropertyEnumeratorCallback enumerator = nullptr,
1098 Local<Value> data = Local<Value>()) {
1099 SetHandler(IndexedPropertyHandlerConfiguration(getter, setter, query,
1100 deleter, enumerator, data));
1101 }
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113 void SetHandler(const IndexedPropertyHandlerConfiguration& configuration);
1114
1115
1116
1117
1118
1119
1120
1121 void SetCallAsFunctionHandler(FunctionCallback callback,
1122 Local<Value> data = Local<Value>());
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132 void MarkAsUndetectable();
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142 void SetAccessCheckCallback(AccessCheckCallback callback,
1143 Local<Value> data = Local<Value>());
1144
1145
1146
1147
1148
1149
1150
1151 void SetAccessCheckCallbackAndHandler(
1152 AccessCheckCallback callback,
1153 const NamedPropertyHandlerConfiguration& named_handler,
1154 const IndexedPropertyHandlerConfiguration& indexed_handler,
1155 Local<Value> data = Local<Value>());
1156
1157
1158
1159
1160
1161 int InternalFieldCount() const;
1162
1163
1164
1165
1166
1167 void SetInternalFieldCount(int value);
1168
1169
1170
1171
1172 bool IsImmutableProto() const;
1173
1174
1175
1176
1177
1178 void SetImmutableProto();
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189 void SetCodeLike();
1190 bool IsCodeLike() const;
1191
1192 V8_INLINE static ObjectTemplate* Cast(Data* data);
1193
1194 private:
1195 ObjectTemplate();
1196
1197 static void CheckCast(Data* that);
1198 friend class FunctionTemplate;
1199 };
1200
1201
1202
1203
1204 class V8_EXPORT DictionaryTemplate final {
1205 public:
1206
1207
1208
1209
1210
1211
1212
1213 static Local<DictionaryTemplate> New(
1214 Isolate* isolate, MemorySpan<const std::string_view> names);
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225 V8_WARN_UNUSED_RESULT Local<Object> NewInstance(
1226 Local<Context> context, MemorySpan<MaybeLocal<Value>> property_values);
1227
1228 V8_INLINE static DictionaryTemplate* Cast(Data* data);
1229
1230 private:
1231 static void CheckCast(Data* that);
1232
1233 DictionaryTemplate();
1234 };
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244 class V8_EXPORT Signature : public Data {
1245 public:
1246 static Local<Signature> New(
1247 Isolate* isolate,
1248 Local<FunctionTemplate> receiver = Local<FunctionTemplate>());
1249
1250 V8_INLINE static Signature* Cast(Data* data);
1251
1252 private:
1253 Signature();
1254
1255 static void CheckCast(Data* that);
1256 };
1257
1258
1259
1260 void Template::Set(Isolate* isolate, const char* name, Local<Data> value,
1261 PropertyAttribute attributes) {
1262 Set(String::NewFromUtf8(isolate, name, NewStringType::kInternalized)
1263 .ToLocalChecked(),
1264 value, attributes);
1265 }
1266
1267 FunctionTemplate* FunctionTemplate::Cast(Data* data) {
1268 #ifdef V8_ENABLE_CHECKS
1269 CheckCast(data);
1270 #endif
1271 return reinterpret_cast<FunctionTemplate*>(data);
1272 }
1273
1274 ObjectTemplate* ObjectTemplate::Cast(Data* data) {
1275 #ifdef V8_ENABLE_CHECKS
1276 CheckCast(data);
1277 #endif
1278 return reinterpret_cast<ObjectTemplate*>(data);
1279 }
1280
1281 DictionaryTemplate* DictionaryTemplate::Cast(Data* data) {
1282 #ifdef V8_ENABLE_CHECKS
1283 CheckCast(data);
1284 #endif
1285 return reinterpret_cast<DictionaryTemplate*>(data);
1286 }
1287
1288 Signature* Signature::Cast(Data* data) {
1289 #ifdef V8_ENABLE_CHECKS
1290 CheckCast(data);
1291 #endif
1292 return reinterpret_cast<Signature*>(data);
1293 }
1294
1295 }
1296
1297 #endif