2022-09-03 21:41:40 +05:30
|
|
|
use crate::PropertyFilter;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub enum KeyConversionMode {
|
|
|
|
/// kConvertToString will convert integer indices to strings.
|
|
|
|
ConvertToString,
|
|
|
|
/// kKeepNumbers will return numbers for integer indices.
|
|
|
|
KeepNumbers,
|
|
|
|
NoNumbers,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Keys/Properties filter enums:
|
|
|
|
///
|
|
|
|
/// KeyCollectionMode limits the range of collected properties. kOwnOnly limits
|
|
|
|
/// the collected properties to the given Object only. kIncludesPrototypes will
|
|
|
|
/// include all keys of the objects's prototype chain as well.
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub enum KeyCollectionMode {
|
|
|
|
/// OwnOnly limits the collected properties to the given Object only.
|
|
|
|
OwnOnly,
|
|
|
|
/// kIncludesPrototypes will include all keys of the objects's prototype chain
|
|
|
|
/// as well.
|
|
|
|
IncludePrototypes,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
#[repr(C)]
|
|
|
|
pub enum IndexFilter {
|
|
|
|
/// kIncludesIndices allows for integer indices to be collected.
|
|
|
|
IncludeIndices,
|
|
|
|
/// kSkipIndices will exclude integer indices from being collected.
|
|
|
|
SkipIndices,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GetPropertyNamesArgs {
|
|
|
|
pub mode: KeyCollectionMode,
|
|
|
|
pub property_filter: PropertyFilter,
|
|
|
|
pub index_filter: IndexFilter,
|
|
|
|
pub key_conversion: KeyConversionMode,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for GetPropertyNamesArgs {
|
|
|
|
fn default() -> Self {
|
|
|
|
GetPropertyNamesArgs {
|
|
|
|
mode: KeyCollectionMode::IncludePrototypes,
|
2023-05-26 13:14:18 +02:00
|
|
|
property_filter: PropertyFilter::ONLY_ENUMERABLE
|
|
|
|
| PropertyFilter::SKIP_SYMBOLS,
|
2022-09-03 21:41:40 +05:30
|
|
|
index_filter: IndexFilter::IncludeIndices,
|
|
|
|
key_conversion: KeyConversionMode::KeepNumbers,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GetPropertyNamesArgsBuilder {
|
|
|
|
mode: KeyCollectionMode,
|
|
|
|
property_filter: PropertyFilter,
|
|
|
|
index_filter: IndexFilter,
|
|
|
|
key_conversion: KeyConversionMode,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for GetPropertyNamesArgsBuilder {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GetPropertyNamesArgsBuilder {
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
mode: KeyCollectionMode::IncludePrototypes,
|
2023-05-26 13:14:18 +02:00
|
|
|
property_filter: PropertyFilter::ONLY_ENUMERABLE
|
|
|
|
| PropertyFilter::SKIP_SYMBOLS,
|
2022-09-03 21:41:40 +05:30
|
|
|
index_filter: IndexFilter::IncludeIndices,
|
|
|
|
key_conversion: KeyConversionMode::KeepNumbers,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn build(&self) -> GetPropertyNamesArgs {
|
|
|
|
GetPropertyNamesArgs {
|
|
|
|
mode: self.mode,
|
|
|
|
property_filter: self.property_filter,
|
|
|
|
index_filter: self.index_filter,
|
|
|
|
key_conversion: self.key_conversion,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn mode(
|
|
|
|
&mut self,
|
|
|
|
mode: KeyCollectionMode,
|
|
|
|
) -> &mut GetPropertyNamesArgsBuilder {
|
|
|
|
self.mode = mode;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn property_filter(
|
|
|
|
&mut self,
|
|
|
|
property_filter: PropertyFilter,
|
|
|
|
) -> &mut GetPropertyNamesArgsBuilder {
|
|
|
|
self.property_filter = property_filter;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn index_filter(
|
|
|
|
&mut self,
|
|
|
|
index_filter: IndexFilter,
|
|
|
|
) -> &mut GetPropertyNamesArgsBuilder {
|
|
|
|
self.index_filter = index_filter;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2022-09-21 08:15:33 +05:30
|
|
|
#[inline(always)]
|
2022-09-03 21:41:40 +05:30
|
|
|
pub fn key_conversion(
|
|
|
|
&mut self,
|
|
|
|
key_conversion: KeyConversionMode,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.key_conversion = key_conversion;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|