diff --git a/src/template.rs b/src/template.rs index 2bffb995..98efbbe2 100644 --- a/src/template.rs +++ b/src/template.rs @@ -336,6 +336,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn getter_raw( + mut self, + getter: GenericNamedPropertyGetterCallback<'s>, + ) -> Self { + self.getter = Some(getter); + self + } + pub fn setter( mut self, setter: impl MapFnTo>, @@ -344,6 +352,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn setter_raw( + mut self, + setter: GenericNamedPropertySetterCallback<'s>, + ) -> Self { + self.setter = Some(setter); + self + } + pub fn query( mut self, query: impl MapFnTo>, @@ -352,6 +368,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn query_raw( + mut self, + query: GenericNamedPropertyQueryCallback<'s>, + ) -> Self { + self.query = Some(query); + self + } + pub fn deleter( mut self, deleter: impl MapFnTo>, @@ -360,6 +384,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn deleter_raw( + mut self, + deleter: GenericNamedPropertyDeleterCallback<'s>, + ) -> Self { + self.deleter = Some(deleter); + self + } + pub fn enumerator( mut self, enumerator: impl MapFnTo>, @@ -368,6 +400,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn enumerator_raw( + mut self, + enumerator: GenericNamedPropertyEnumeratorCallback<'s>, + ) -> Self { + self.enumerator = Some(enumerator); + self + } + pub fn definer( mut self, definer: impl MapFnTo>, @@ -376,6 +416,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn definer_raw( + mut self, + definer: GenericNamedPropertyDefinerCallback<'s>, + ) -> Self { + self.definer = Some(definer); + self + } + pub fn descriptor( mut self, descriptor: impl MapFnTo>, @@ -384,6 +432,14 @@ impl<'s> NamedPropertyHandlerConfiguration<'s> { self } + pub fn descriptor_raw( + mut self, + descriptor: GenericNamedPropertyDescriptorCallback<'s>, + ) -> Self { + self.descriptor = Some(descriptor); + self + } + /// Set the associated data. The default is no associated data. pub fn data(mut self, data: Local<'s, Value>) -> Self { self.data = Some(data); diff --git a/tests/test_api.rs b/tests/test_api.rs index d654b7fb..7281efc1 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -2437,6 +2437,35 @@ fn object_template_set_named_property_handler() { .unwrap() .boolean_value(scope)); assert!(eval(scope, "obj.panicOnGet").unwrap().is_string()); + + // Test `v8::NamedPropertyHandlerConfiguration::*_raw()` methods + { + let templ = v8::ObjectTemplate::new(scope); + templ.set_internal_field_count(1); + templ.set_named_property_handler( + v8::NamedPropertyHandlerConfiguration::new() + .getter_raw(getter.map_fn_to()) + .setter_raw(setter.map_fn_to()) + .query_raw(query.map_fn_to()) + .flags(v8::PropertyHandlerFlags::NON_MASKING), + ); + + let obj = templ.new_instance(scope).unwrap(); + obj.set_internal_field(0, int.into()); + scope.get_current_context().global(scope).set( + scope, + name.into(), + obj.into(), + ); + assert!(!eval(scope, "'panicOnGet' in obj") + .unwrap() + .boolean_value(scope)); + eval(scope, "obj.panicOnGet = 'x'").unwrap(); + assert!(eval(scope, "'panicOnGet' in obj") + .unwrap() + .boolean_value(scope)); + assert!(eval(scope, "obj.panicOnGet").unwrap().is_string()); + } } }