0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

Add v8::NamedPropertyHandlerConfiguration::*_raw methods (#1273)

This commit is contained in:
Bartek Iwańczuk 2023-07-09 22:40:15 +02:00 committed by GitHub
parent e2c6541ea3
commit 73dcb46674
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View file

@ -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<GenericNamedPropertySetterCallback<'s>>,
@ -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<GenericNamedPropertyQueryCallback<'s>>,
@ -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<GenericNamedPropertyDeleterCallback<'s>>,
@ -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<GenericNamedPropertyEnumeratorCallback<'s>>,
@ -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<GenericNamedPropertyDefinerCallback<'s>>,
@ -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<GenericNamedPropertyDescriptorCallback<'s>>,
@ -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);

View file

@ -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());
}
}
}