1use crate::ConstructorBehavior;
2use crate::Context;
3use crate::Function;
4use crate::FunctionBuilder;
5use crate::FunctionCallback;
6use crate::IndexedDefinerCallback;
7use crate::IndexedDeleterCallback;
8use crate::IndexedGetterCallback;
9use crate::IndexedQueryCallback;
10use crate::IndexedSetterCallback;
11use crate::Local;
12use crate::NamedDefinerCallback;
13use crate::NamedDeleterCallback;
14use crate::NamedGetterCallback;
15use crate::NamedGetterCallbackForAccessor;
16use crate::NamedQueryCallback;
17use crate::NamedSetterCallback;
18use crate::NamedSetterCallbackForAccessor;
19use crate::Object;
20use crate::PropertyAttribute;
21use crate::PropertyEnumeratorCallback;
22use crate::PropertyHandlerFlags;
23use crate::SideEffectType;
24use crate::Signature;
25use crate::String;
26use crate::Value;
27pub use crate::binding::v8__Intercepted as Intercepted;
28use crate::data::Data;
29use crate::data::FunctionTemplate;
30use crate::data::Name;
31use crate::data::ObjectTemplate;
32use crate::data::Template;
33use crate::fast_api::CFunction;
34use crate::isolate::RealIsolate;
35use crate::scope::PinScope;
36use crate::support::MapFnTo;
37use crate::support::int;
38use std::convert::TryFrom;
39use std::ptr::null;
40
41unsafe extern "C" {
42 fn v8__Template__Set(
43 this: *const Template,
44 key: *const Name,
45 value: *const Data,
46 attr: PropertyAttribute,
47 );
48 fn v8__Template__SetIntrinsicDataProperty(
49 this: *const Template,
50 key: *const Name,
51 intrinsic: Intrinsic,
52 attr: PropertyAttribute,
53 );
54
55 fn v8__Signature__New(
56 isolate: *mut RealIsolate,
57 templ: *const FunctionTemplate,
58 ) -> *const Signature;
59 fn v8__FunctionTemplate__New(
60 isolate: *mut RealIsolate,
61 callback: FunctionCallback,
62 data_or_null: *const Value,
63 signature_or_null: *const Signature,
64 length: i32,
65 constructor_behavior: ConstructorBehavior,
66 side_effect_type: SideEffectType,
67 c_functions: *const CFunction,
68 c_functions_len: usize,
69 ) -> *const FunctionTemplate;
70 fn v8__FunctionTemplate__GetFunction(
71 this: *const FunctionTemplate,
72 context: *const Context,
73 ) -> *const Function;
74 fn v8__FunctionTemplate__PrototypeTemplate(
75 this: *const FunctionTemplate,
76 ) -> *const ObjectTemplate;
77 fn v8__FunctionTemplate__InstanceTemplate(
78 this: *const FunctionTemplate,
79 ) -> *const ObjectTemplate;
80 fn v8__FunctionTemplate__SetClassName(
81 this: *const FunctionTemplate,
82 name: *const String,
83 );
84 fn v8__FunctionTemplate__SetAccessorProperty(
85 this: *const FunctionTemplate,
86 key: *const Name,
87 getter: *const FunctionTemplate,
88 setter: *const FunctionTemplate,
89 attr: PropertyAttribute,
90 );
91 fn v8__FunctionTemplate__Inherit(
92 this: *const FunctionTemplate,
93 parent: *const FunctionTemplate,
94 );
95 fn v8__FunctionTemplate__ReadOnlyPrototype(this: *const FunctionTemplate);
96 fn v8__FunctionTemplate__RemovePrototype(this: *const FunctionTemplate);
97
98 fn v8__ObjectTemplate__New(
99 isolate: *mut RealIsolate,
100 templ: *const FunctionTemplate,
101 ) -> *const ObjectTemplate;
102 fn v8__ObjectTemplate__NewInstance(
103 this: *const ObjectTemplate,
104 context: *const Context,
105 ) -> *const Object;
106 fn v8__ObjectTemplate__InternalFieldCount(this: *const ObjectTemplate)
107 -> int;
108 fn v8__ObjectTemplate__SetInternalFieldCount(
109 this: *const ObjectTemplate,
110 value: int,
111 );
112
113 fn v8__ObjectTemplate__SetNativeDataProperty(
114 this: *const ObjectTemplate,
115 key: *const Name,
116 getter: AccessorNameGetterCallback,
117 setter: Option<AccessorNameSetterCallback>,
118 data_or_null: *const Value,
119 attr: PropertyAttribute,
120 );
121 fn v8__ObjectTemplate__SetAccessorProperty(
122 this: *const ObjectTemplate,
123 key: *const Name,
124 getter: *const FunctionTemplate,
125 setter: *const FunctionTemplate,
126 attr: PropertyAttribute,
127 );
128
129 fn v8__ObjectTemplate__SetNamedPropertyHandler(
130 this: *const ObjectTemplate,
131 getter: Option<NamedPropertyGetterCallback>,
132 setter: Option<NamedPropertySetterCallback>,
133 query: Option<NamedPropertyQueryCallback>,
134 deleter: Option<NamedPropertyDeleterCallback>,
135 enumerator: Option<NamedPropertyEnumeratorCallback>,
136 definer: Option<NamedPropertyDefinerCallback>,
137 descriptor: Option<NamedPropertyDescriptorCallback>,
138 data_or_null: *const Value,
139 flags: PropertyHandlerFlags,
140 );
141
142 fn v8__ObjectTemplate__SetIndexedPropertyHandler(
143 this: *const ObjectTemplate,
144 getter: Option<IndexedPropertyGetterCallback>,
145 setter: Option<IndexedPropertySetterCallback>,
146 query: Option<IndexedPropertyQueryCallback>,
147 deleter: Option<IndexedPropertyDeleterCallback>,
148 enumerator: Option<IndexedPropertyEnumeratorCallback>,
149 definer: Option<IndexedPropertyDefinerCallback>,
150 descriptor: Option<IndexedPropertyDescriptorCallback>,
151 data_or_null: *const Value,
152 );
153
154 fn v8__ObjectTemplate__SetImmutableProto(this: *const ObjectTemplate);
155}
156
157pub type AccessorNameGetterCallback = NamedGetterCallbackForAccessor;
158
159pub type AccessorNameSetterCallback = NamedSetterCallbackForAccessor;
161
162pub type NamedPropertyGetterCallback = NamedGetterCallback;
170
171pub type NamedPropertySetterCallback = NamedSetterCallback;
182
183pub type NamedPropertyQueryCallback = NamedQueryCallback;
196
197pub type NamedPropertyDeleterCallback = NamedDeleterCallback;
213
214pub type NamedPropertyEnumeratorCallback = PropertyEnumeratorCallback;
220
221pub type NamedPropertyDefinerCallback = NamedDefinerCallback;
232
233pub type NamedPropertyDescriptorCallback = NamedGetterCallback;
245
246pub type IndexedPropertyGetterCallback = IndexedGetterCallback;
248
249pub type IndexedPropertySetterCallback = IndexedSetterCallback;
251
252pub type IndexedPropertyQueryCallback = IndexedQueryCallback;
254
255pub type IndexedPropertyDeleterCallback = IndexedDeleterCallback;
257
258pub type IndexedPropertyEnumeratorCallback = PropertyEnumeratorCallback;
260
261pub type IndexedPropertyDefinerCallback = IndexedDefinerCallback;
263
264pub type IndexedPropertyDescriptorCallback = IndexedGetterCallback;
266
267pub struct AccessorConfiguration<'s> {
268 pub(crate) getter: AccessorNameGetterCallback,
269 pub(crate) setter: Option<AccessorNameSetterCallback>,
270 pub(crate) data: Option<Local<'s, Value>>,
271 pub(crate) property_attribute: PropertyAttribute,
272}
273
274impl<'s> AccessorConfiguration<'s> {
275 pub fn new(getter: impl MapFnTo<AccessorNameGetterCallback>) -> Self {
276 Self {
277 getter: getter.map_fn_to(),
278 setter: None,
279 data: None,
280 property_attribute: PropertyAttribute::NONE,
281 }
282 }
283
284 pub fn setter(
285 mut self,
286 setter: impl MapFnTo<AccessorNameSetterCallback>,
287 ) -> Self {
288 self.setter = Some(setter.map_fn_to());
289 self
290 }
291
292 pub fn property_attribute(
293 mut self,
294 property_attribute: PropertyAttribute,
295 ) -> Self {
296 self.property_attribute = property_attribute;
297 self
298 }
299
300 pub fn data(mut self, data: Local<'s, Value>) -> Self {
302 self.data = Some(data);
303 self
304 }
305}
306
307#[derive(Default)]
308pub struct NamedPropertyHandlerConfiguration<'s> {
309 pub(crate) getter: Option<NamedPropertyGetterCallback>,
310 pub(crate) setter: Option<NamedPropertySetterCallback>,
311 pub(crate) query: Option<NamedPropertyQueryCallback>,
312 pub(crate) deleter: Option<NamedPropertyDeleterCallback>,
313 pub(crate) enumerator: Option<NamedPropertyEnumeratorCallback>,
314 pub(crate) definer: Option<NamedPropertyDefinerCallback>,
315 pub(crate) descriptor: Option<NamedPropertyDescriptorCallback>,
316 pub(crate) data: Option<Local<'s, Value>>,
317 pub(crate) flags: PropertyHandlerFlags,
318}
319
320impl<'s> NamedPropertyHandlerConfiguration<'s> {
321 pub fn new() -> Self {
322 Self {
323 getter: None,
324 setter: None,
325 query: None,
326 deleter: None,
327 enumerator: None,
328 definer: None,
329 descriptor: None,
330 data: None,
331 flags: PropertyHandlerFlags::NONE,
332 }
333 }
334
335 pub fn is_some(&self) -> bool {
336 self.getter.is_some()
337 || self.setter.is_some()
338 || self.query.is_some()
339 || self.deleter.is_some()
340 || self.enumerator.is_some()
341 || self.definer.is_some()
342 || self.descriptor.is_some()
343 || !self.flags.is_none()
344 }
345
346 pub fn getter(
347 mut self,
348 getter: impl MapFnTo<NamedPropertyGetterCallback>,
349 ) -> Self {
350 self.getter = Some(getter.map_fn_to());
351 self
352 }
353
354 pub fn getter_raw(mut self, getter: NamedPropertyGetterCallback) -> Self {
355 self.getter = Some(getter);
356 self
357 }
358
359 pub fn setter(
360 mut self,
361 setter: impl MapFnTo<NamedPropertySetterCallback>,
362 ) -> Self {
363 self.setter = Some(setter.map_fn_to());
364 self
365 }
366
367 pub fn setter_raw(mut self, setter: NamedPropertySetterCallback) -> Self {
368 self.setter = Some(setter);
369 self
370 }
371
372 pub fn query(
373 mut self,
374 query: impl MapFnTo<NamedPropertyQueryCallback>,
375 ) -> Self {
376 self.query = Some(query.map_fn_to());
377 self
378 }
379
380 pub fn query_raw(mut self, query: NamedPropertyQueryCallback) -> Self {
381 self.query = Some(query);
382 self
383 }
384
385 pub fn deleter(
386 mut self,
387 deleter: impl MapFnTo<NamedPropertyDeleterCallback>,
388 ) -> Self {
389 self.deleter = Some(deleter.map_fn_to());
390 self
391 }
392
393 pub fn deleter_raw(mut self, deleter: NamedPropertyDeleterCallback) -> Self {
394 self.deleter = Some(deleter);
395 self
396 }
397
398 pub fn enumerator(
399 mut self,
400 enumerator: impl MapFnTo<NamedPropertyEnumeratorCallback>,
401 ) -> Self {
402 self.enumerator = Some(enumerator.map_fn_to());
403 self
404 }
405
406 pub fn enumerator_raw(
407 mut self,
408 enumerator: NamedPropertyEnumeratorCallback,
409 ) -> Self {
410 self.enumerator = Some(enumerator);
411 self
412 }
413
414 pub fn definer(
415 mut self,
416 definer: impl MapFnTo<NamedPropertyDefinerCallback>,
417 ) -> Self {
418 self.definer = Some(definer.map_fn_to());
419 self
420 }
421
422 pub fn definer_raw(mut self, definer: NamedPropertyDefinerCallback) -> Self {
423 self.definer = Some(definer);
424 self
425 }
426
427 pub fn descriptor(
428 mut self,
429 descriptor: impl MapFnTo<NamedPropertyDescriptorCallback>,
430 ) -> Self {
431 self.descriptor = Some(descriptor.map_fn_to());
432 self
433 }
434
435 pub fn descriptor_raw(
436 mut self,
437 descriptor: NamedPropertyDescriptorCallback,
438 ) -> Self {
439 self.descriptor = Some(descriptor);
440 self
441 }
442
443 pub fn data(mut self, data: Local<'s, Value>) -> Self {
445 self.data = Some(data);
446 self
447 }
448
449 pub fn flags(mut self, flags: PropertyHandlerFlags) -> Self {
451 self.flags = flags;
452 self
453 }
454}
455
456#[derive(Default)]
457pub struct IndexedPropertyHandlerConfiguration<'s> {
458 pub(crate) getter: Option<IndexedPropertyGetterCallback>,
459 pub(crate) setter: Option<IndexedPropertySetterCallback>,
460 pub(crate) query: Option<IndexedPropertyQueryCallback>,
461 pub(crate) deleter: Option<IndexedPropertyDeleterCallback>,
462 pub(crate) enumerator: Option<IndexedPropertyEnumeratorCallback>,
463 pub(crate) definer: Option<IndexedPropertyDefinerCallback>,
464 pub(crate) descriptor: Option<IndexedPropertyDescriptorCallback>,
465 pub(crate) data: Option<Local<'s, Value>>,
466 pub(crate) flags: PropertyHandlerFlags,
467}
468
469impl<'s> IndexedPropertyHandlerConfiguration<'s> {
470 pub fn new() -> Self {
471 Self {
472 getter: None,
473 setter: None,
474 query: None,
475 deleter: None,
476 enumerator: None,
477 definer: None,
478 descriptor: None,
479 data: None,
480 flags: PropertyHandlerFlags::NONE,
481 }
482 }
483
484 pub fn is_some(&self) -> bool {
485 self.getter.is_some()
486 || self.setter.is_some()
487 || self.query.is_some()
488 || self.deleter.is_some()
489 || self.enumerator.is_some()
490 || self.definer.is_some()
491 || self.descriptor.is_some()
492 || !self.flags.is_none()
493 }
494
495 pub fn getter(
496 mut self,
497 getter: impl MapFnTo<IndexedPropertyGetterCallback>,
498 ) -> Self {
499 self.getter = Some(getter.map_fn_to());
500 self
501 }
502
503 pub fn getter_raw(mut self, getter: IndexedPropertyGetterCallback) -> Self {
504 self.getter = Some(getter);
505 self
506 }
507
508 pub fn setter(
509 mut self,
510 setter: impl MapFnTo<IndexedPropertySetterCallback>,
511 ) -> Self {
512 self.setter = Some(setter.map_fn_to());
513 self
514 }
515
516 pub fn setter_raw(mut self, setter: IndexedPropertySetterCallback) -> Self {
517 self.setter = Some(setter);
518 self
519 }
520
521 pub fn query(
522 mut self,
523 query: impl MapFnTo<IndexedPropertyQueryCallback>,
524 ) -> Self {
525 self.query = Some(query.map_fn_to());
526 self
527 }
528
529 pub fn query_raw(mut self, query: IndexedPropertyQueryCallback) -> Self {
530 self.query = Some(query);
531 self
532 }
533
534 pub fn deleter(
535 mut self,
536 deleter: impl MapFnTo<IndexedPropertyDeleterCallback>,
537 ) -> Self {
538 self.deleter = Some(deleter.map_fn_to());
539 self
540 }
541
542 pub fn deleter_raw(
543 mut self,
544 deleter: IndexedPropertyDeleterCallback,
545 ) -> Self {
546 self.deleter = Some(deleter);
547 self
548 }
549
550 pub fn enumerator(
551 mut self,
552 enumerator: impl MapFnTo<IndexedPropertyEnumeratorCallback>,
553 ) -> Self {
554 self.enumerator = Some(enumerator.map_fn_to());
555 self
556 }
557
558 pub fn enumerator_raw(
559 mut self,
560 enumerator: IndexedPropertyEnumeratorCallback,
561 ) -> Self {
562 self.enumerator = Some(enumerator);
563 self
564 }
565
566 pub fn definer(
567 mut self,
568 definer: impl MapFnTo<IndexedPropertyDefinerCallback>,
569 ) -> Self {
570 self.definer = Some(definer.map_fn_to());
571 self
572 }
573
574 pub fn definer_raw(
575 mut self,
576 definer: IndexedPropertyDefinerCallback,
577 ) -> Self {
578 self.definer = Some(definer);
579 self
580 }
581
582 pub fn descriptor(
583 mut self,
584 descriptor: impl MapFnTo<IndexedPropertyDescriptorCallback>,
585 ) -> Self {
586 self.descriptor = Some(descriptor.map_fn_to());
587 self
588 }
589
590 pub fn descriptor_raw(
591 mut self,
592 descriptor: IndexedPropertyDescriptorCallback,
593 ) -> Self {
594 self.descriptor = Some(descriptor);
595 self
596 }
597
598 pub fn data(mut self, data: Local<'s, Value>) -> Self {
600 self.data = Some(data);
601 self
602 }
603
604 pub fn flags(mut self, flags: PropertyHandlerFlags) -> Self {
606 self.flags = flags;
607 self
608 }
609}
610
611#[derive(Debug, Clone, Copy)]
612#[repr(C)]
613pub enum Intrinsic {
614 ArrayProtoEntries,
615 ArrayProtoForEach,
616 ArrayProtoKeys,
617 ArrayProtoValues,
618 ArrayPrototype,
619 AsyncIteratorPrototype,
620 ErrorPrototype,
621 IteratorPrototype,
622 MapIteratorPrototype,
623 ObjProtoValueOf,
624 SetIteratorPrototype,
625}
626
627impl Template {
628 #[inline(always)]
630 pub fn set(&self, key: Local<Name>, value: Local<Data>) {
631 self.set_with_attr(key, value, PropertyAttribute::NONE);
632 }
633
634 #[inline(always)]
637 pub fn set_with_attr(
638 &self,
639 key: Local<Name>,
640 value: Local<Data>,
641 attr: PropertyAttribute,
642 ) {
643 unsafe { v8__Template__Set(self, &*key, &*value, attr) }
644 }
645
646 #[inline(always)]
649 pub fn set_intrinsic_data_property(
650 &self,
651 key: Local<Name>,
652 intrinsic: Intrinsic,
653 attr: PropertyAttribute,
654 ) {
655 unsafe {
656 v8__Template__SetIntrinsicDataProperty(self, &*key, intrinsic, attr);
657 }
658 }
659}
660
661impl<'s> FunctionBuilder<'s, FunctionTemplate> {
662 #[inline(always)]
664 pub fn signature(mut self, signature: Local<'s, Signature>) -> Self {
665 self.signature = Some(signature);
666 self
667 }
668
669 #[inline(always)]
671 pub fn build<'i>(
672 self,
673 scope: &PinScope<'s, 'i, ()>,
674 ) -> Local<'s, FunctionTemplate> {
675 unsafe {
676 scope.cast_local(|sd| {
677 v8__FunctionTemplate__New(
678 sd.get_isolate_ptr(),
679 self.callback,
680 self.data.map_or_else(null, |p| &*p),
681 self.signature.map_or_else(null, |p| &*p),
682 self.length,
683 self.constructor_behavior,
684 self.side_effect_type,
685 null(),
686 0,
687 )
688 })
689 }
690 .unwrap()
691 }
692
693 pub fn build_fast<'i>(
699 self,
700 scope: &PinScope<'s, 'i>,
701 overloads: &[CFunction],
702 ) -> Local<'s, FunctionTemplate> {
703 unsafe {
704 scope.cast_local(|sd| {
705 v8__FunctionTemplate__New(
706 sd.get_isolate_ptr(),
707 self.callback,
708 self.data.map_or_else(null, |p| &*p),
709 self.signature.map_or_else(null, |p| &*p),
710 self.length,
711 ConstructorBehavior::Throw,
712 self.side_effect_type,
713 overloads.as_ptr(),
714 overloads.len(),
715 )
716 })
717 }
718 .unwrap()
719 }
720}
721
722impl Signature {
729 #[inline(always)]
730 pub fn new<'s>(
731 scope: &PinScope<'s, '_, ()>,
732 templ: Local<FunctionTemplate>,
733 ) -> Local<'s, Self> {
734 unsafe {
735 scope.cast_local(|sd| v8__Signature__New(sd.get_isolate_ptr(), &*templ))
736 }
737 .unwrap()
738 }
739}
740
741impl FunctionTemplate {
742 #[inline(always)]
745 pub fn builder<'s>(
746 callback: impl MapFnTo<FunctionCallback>,
747 ) -> FunctionBuilder<'s, Self> {
748 FunctionBuilder::new(callback)
749 }
750
751 #[inline(always)]
752 pub fn builder_raw<'s>(
753 callback: FunctionCallback,
754 ) -> FunctionBuilder<'s, Self> {
755 FunctionBuilder::new_raw(callback)
756 }
757
758 #[inline(always)]
760 pub fn new<'s>(
761 scope: &PinScope<'s, '_, ()>,
762 callback: impl MapFnTo<FunctionCallback>,
763 ) -> Local<'s, FunctionTemplate> {
764 Self::builder(callback).build(scope)
765 }
766
767 #[inline(always)]
768 pub fn new_raw<'s>(
769 scope: &PinScope<'s, '_, ()>,
770 callback: FunctionCallback,
771 ) -> Local<'s, FunctionTemplate> {
772 Self::builder_raw(callback).build(scope)
773 }
774
775 #[inline(always)]
777 pub fn get_function<'s>(
778 &self,
779 scope: &PinScope<'s, '_>,
780 ) -> Option<Local<'s, Function>> {
781 unsafe {
782 scope.cast_local(|sd| {
783 v8__FunctionTemplate__GetFunction(self, sd.get_current_context())
784 })
785 }
786 }
787
788 #[inline(always)]
792 pub fn set_class_name(&self, name: Local<String>) {
793 unsafe { v8__FunctionTemplate__SetClassName(self, &*name) };
794 }
795
796 #[inline(always)]
799 pub fn prototype_template<'s>(
800 &self,
801 scope: &PinScope<'s, '_, ()>,
802 ) -> Local<'s, ObjectTemplate> {
803 unsafe {
804 scope.cast_local(|_sd| v8__FunctionTemplate__PrototypeTemplate(self))
805 }
806 .unwrap()
807 }
808
809 #[inline(always)]
812 pub fn instance_template<'s>(
813 &self,
814 scope: &PinScope<'s, '_, ()>,
815 ) -> Local<'s, ObjectTemplate> {
816 unsafe {
817 scope.cast_local(|_sd| v8__FunctionTemplate__InstanceTemplate(self))
818 }
819 .unwrap()
820 }
821
822 #[inline(always)]
825 pub fn inherit(&self, parent: Local<FunctionTemplate>) {
826 unsafe { v8__FunctionTemplate__Inherit(self, &*parent) };
827 }
828
829 #[inline(always)]
832 pub fn read_only_prototype(&self) {
833 unsafe { v8__FunctionTemplate__ReadOnlyPrototype(self) };
834 }
835
836 #[inline(always)]
838 pub fn remove_prototype(&self) {
839 unsafe { v8__FunctionTemplate__RemovePrototype(self) };
840 }
841
842 #[inline(always)]
849 pub fn set_accessor_property(
850 &self,
851 key: Local<Name>,
852 getter: Option<Local<FunctionTemplate>>,
853 setter: Option<Local<FunctionTemplate>>,
854 attr: PropertyAttribute,
855 ) {
856 assert!(getter.is_some() || setter.is_some());
857
858 unsafe {
859 let getter = getter.map_or_else(std::ptr::null, |v| &*v);
860 let setter = setter.map_or_else(std::ptr::null, |v| &*v);
861 v8__FunctionTemplate__SetAccessorProperty(
862 self, &*key, getter, setter, attr,
863 );
864 }
865 }
866}
867
868impl ObjectTemplate {
869 #[inline(always)]
871 pub fn new<'s>(scope: &PinScope<'s, '_, ()>) -> Local<'s, ObjectTemplate> {
872 unsafe {
873 scope.cast_local(|sd| {
874 v8__ObjectTemplate__New(sd.get_isolate_ptr(), std::ptr::null())
875 })
876 }
877 .unwrap()
878 }
879
880 #[inline(always)]
882 pub fn new_from_template<'s>(
883 scope: &PinScope<'s, '_, ()>,
884 templ: Local<FunctionTemplate>,
885 ) -> Local<'s, ObjectTemplate> {
886 unsafe {
887 scope
888 .cast_local(|sd| v8__ObjectTemplate__New(sd.get_isolate_ptr(), &*templ))
889 }
890 .unwrap()
891 }
892
893 #[inline(always)]
895 pub fn new_instance<'s>(
896 &self,
897 scope: &PinScope<'s, '_>,
898 ) -> Option<Local<'s, Object>> {
899 unsafe {
900 scope.cast_local(|sd| {
901 v8__ObjectTemplate__NewInstance(self, sd.get_current_context())
902 })
903 }
904 }
905
906 #[inline(always)]
909 pub fn internal_field_count(&self) -> usize {
910 let count = unsafe { v8__ObjectTemplate__InternalFieldCount(self) };
911 usize::try_from(count).expect("bad internal field count") }
913
914 #[inline(always)]
917 pub fn set_internal_field_count(&self, value: usize) -> bool {
918 match int::try_from(value) {
921 Err(_) => false,
922 Ok(value) => {
923 unsafe { v8__ObjectTemplate__SetInternalFieldCount(self, value) };
924 true
925 }
926 }
927 }
928
929 #[inline(always)]
930 pub fn set_accessor(
931 &self,
932 key: Local<Name>,
933 getter: impl MapFnTo<AccessorNameGetterCallback>,
934 ) {
935 self
936 .set_accessor_with_configuration(key, AccessorConfiguration::new(getter));
937 }
938
939 #[inline(always)]
940 pub fn set_accessor_with_setter(
941 &self,
942 key: Local<Name>,
943 getter: impl MapFnTo<AccessorNameGetterCallback>,
944 setter: impl MapFnTo<AccessorNameSetterCallback>,
945 ) {
946 self.set_accessor_with_configuration(
947 key,
948 AccessorConfiguration::new(getter).setter(setter),
949 );
950 }
951
952 #[inline(always)]
953 pub fn set_accessor_with_configuration(
954 &self,
955 key: Local<Name>,
956 configuration: AccessorConfiguration,
957 ) {
958 unsafe {
959 v8__ObjectTemplate__SetNativeDataProperty(
960 self,
961 &*key,
962 configuration.getter,
963 configuration.setter,
964 configuration.data.map_or_else(null, |p| &*p),
965 configuration.property_attribute,
966 );
967 }
968 }
969
970 pub fn set_named_property_handler(
973 &self,
974 configuration: NamedPropertyHandlerConfiguration,
975 ) {
976 assert!(configuration.is_some());
977 unsafe {
978 v8__ObjectTemplate__SetNamedPropertyHandler(
979 self,
980 configuration.getter,
981 configuration.setter,
982 configuration.query,
983 configuration.deleter,
984 configuration.enumerator,
985 configuration.definer,
986 configuration.descriptor,
987 configuration.data.map_or_else(null, |p| &*p),
988 configuration.flags,
989 );
990 }
991 }
992
993 pub fn set_indexed_property_handler(
994 &self,
995 configuration: IndexedPropertyHandlerConfiguration,
996 ) {
997 assert!(configuration.is_some());
998 unsafe {
999 v8__ObjectTemplate__SetIndexedPropertyHandler(
1000 self,
1001 configuration.getter,
1002 configuration.setter,
1003 configuration.query,
1004 configuration.deleter,
1005 configuration.enumerator,
1006 configuration.definer,
1007 configuration.descriptor,
1008 configuration.data.map_or_else(null, |p| &*p),
1009 );
1010 }
1011 }
1012
1013 #[inline(always)]
1020 pub fn set_accessor_property(
1021 &self,
1022 key: Local<Name>,
1023 getter: Option<Local<FunctionTemplate>>,
1024 setter: Option<Local<FunctionTemplate>>,
1025 attr: PropertyAttribute,
1026 ) {
1027 assert!(getter.is_some() || setter.is_some());
1028
1029 unsafe {
1030 let getter = getter.map_or_else(std::ptr::null, |v| &*v);
1031 let setter = setter.map_or_else(std::ptr::null, |v| &*v);
1032 v8__ObjectTemplate__SetAccessorProperty(
1033 self, &*key, getter, setter, attr,
1034 );
1035 }
1036 }
1037
1038 #[inline(always)]
1041 pub fn set_immutable_proto(&self) {
1042 unsafe { v8__ObjectTemplate__SetImmutableProto(self) };
1043 }
1044}