Skip to main content

v8/
get_property_names_args_builder.rs

1use crate::PropertyFilter;
2
3#[derive(Debug, Clone, Copy)]
4#[repr(C)]
5pub enum KeyConversionMode {
6  /// kConvertToString will convert integer indices to strings.
7  ConvertToString,
8  /// kKeepNumbers will return numbers for integer indices.
9  KeepNumbers,
10  NoNumbers,
11}
12
13/// Keys/Properties filter enums:
14///
15/// KeyCollectionMode limits the range of collected properties. kOwnOnly limits
16/// the collected properties to the given Object only. kIncludesPrototypes will
17/// include all keys of the objects's prototype chain as well.
18#[derive(Debug, Clone, Copy)]
19#[repr(C)]
20pub enum KeyCollectionMode {
21  /// OwnOnly limits the collected properties to the given Object only.
22  OwnOnly,
23  /// kIncludesPrototypes will include all keys of the objects's prototype chain
24  /// as well.
25  IncludePrototypes,
26}
27
28#[derive(Debug, Clone, Copy)]
29#[repr(C)]
30pub enum IndexFilter {
31  /// kIncludesIndices allows for integer indices to be collected.
32  IncludeIndices,
33  /// kSkipIndices will exclude integer indices from being collected.
34  SkipIndices,
35}
36
37pub struct GetPropertyNamesArgs {
38  pub mode: KeyCollectionMode,
39  pub property_filter: PropertyFilter,
40  pub index_filter: IndexFilter,
41  pub key_conversion: KeyConversionMode,
42}
43
44impl Default for GetPropertyNamesArgs {
45  fn default() -> Self {
46    GetPropertyNamesArgs {
47      mode: KeyCollectionMode::IncludePrototypes,
48      property_filter: PropertyFilter::ONLY_ENUMERABLE
49        | PropertyFilter::SKIP_SYMBOLS,
50      index_filter: IndexFilter::IncludeIndices,
51      key_conversion: KeyConversionMode::KeepNumbers,
52    }
53  }
54}
55
56pub struct GetPropertyNamesArgsBuilder {
57  mode: KeyCollectionMode,
58  property_filter: PropertyFilter,
59  index_filter: IndexFilter,
60  key_conversion: KeyConversionMode,
61}
62
63impl Default for GetPropertyNamesArgsBuilder {
64  fn default() -> Self {
65    Self::new()
66  }
67}
68
69impl GetPropertyNamesArgsBuilder {
70  #[inline(always)]
71  pub fn new() -> Self {
72    Self {
73      mode: KeyCollectionMode::IncludePrototypes,
74      property_filter: PropertyFilter::ONLY_ENUMERABLE
75        | PropertyFilter::SKIP_SYMBOLS,
76      index_filter: IndexFilter::IncludeIndices,
77      key_conversion: KeyConversionMode::KeepNumbers,
78    }
79  }
80
81  #[inline(always)]
82  pub fn build(&self) -> GetPropertyNamesArgs {
83    GetPropertyNamesArgs {
84      mode: self.mode,
85      property_filter: self.property_filter,
86      index_filter: self.index_filter,
87      key_conversion: self.key_conversion,
88    }
89  }
90
91  #[inline(always)]
92  pub fn mode(
93    &mut self,
94    mode: KeyCollectionMode,
95  ) -> &mut GetPropertyNamesArgsBuilder {
96    self.mode = mode;
97    self
98  }
99
100  #[inline(always)]
101  pub fn property_filter(
102    &mut self,
103    property_filter: PropertyFilter,
104  ) -> &mut GetPropertyNamesArgsBuilder {
105    self.property_filter = property_filter;
106    self
107  }
108
109  #[inline(always)]
110  pub fn index_filter(
111    &mut self,
112    index_filter: IndexFilter,
113  ) -> &mut GetPropertyNamesArgsBuilder {
114    self.index_filter = index_filter;
115    self
116  }
117
118  #[inline(always)]
119  pub fn key_conversion(
120    &mut self,
121    key_conversion: KeyConversionMode,
122  ) -> &mut Self {
123    self.key_conversion = key_conversion;
124    self
125  }
126}