Skip to content

Commit

Permalink
Added index_keys method to object
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Aug 5, 2020
1 parent 312f868 commit 8ea3fcd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions boa/src/builtins/object/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ impl Object {
indexes: self.indexed_properties.iter(),
}
}

#[inline]
pub fn indexe_keys(&self) -> IndexKeys<'_> {
IndexKeys {
indexes: self.indexed_properties.keys(),
}
}
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -232,3 +239,31 @@ impl ExactSizeIterator for Indexes<'_> {
}

impl FusedIterator for Indexes<'_> {}

#[derive(Debug, Clone)]
pub struct IndexKeys<'a> {
indexes: hash_map::Keys<'a, u32, Property>,
}

impl<'a> Iterator for IndexKeys<'a> {
type Item = &'a u32;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.indexes.next()
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.indexes.size_hint()
}
}

impl ExactSizeIterator for IndexKeys<'_> {
#[inline]
fn len(&self) -> usize {
self.indexes.len()
}
}

impl FusedIterator for IndexKeys<'_> {}

0 comments on commit 8ea3fcd

Please sign in to comment.