Skip to content

Commit

Permalink
Refactor: Clean-up some Set related functions, unwrap and naming
Browse files Browse the repository at this point in the history
Co-Authored-By: HalidOdat <[email protected]>
  • Loading branch information
RageKnify and HalidOdat committed Feb 16, 2021
1 parent 4c4bd84 commit f94e23b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 10 additions & 2 deletions boa/src/builtins/set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ impl Set {
.throw_type_error("Method Set.prototype.entries called on incompatible receiver");
}

SetIterator::create_set_iterator(context, this.clone(), SetIterationKind::KeyAndValue)
Ok(SetIterator::create_set_iterator(
context,
this.clone(),
SetIterationKind::KeyAndValue,
))
}

/// `Set.prototype.forEach( callbackFn [ , thisArg ] )`
Expand Down Expand Up @@ -383,7 +387,11 @@ impl Set {
.throw_type_error("Method Set.prototype.values called on incompatible receiver");
}

SetIterator::create_set_iterator(context, this.clone(), SetIterationKind::Value)
Ok(SetIterator::create_set_iterator(
context,
this.clone(),
SetIterationKind::Value,
))
}

fn size_getter(this: &Value, _: &[Value], context: &mut Context) -> Result<Value> {
Expand Down
18 changes: 9 additions & 9 deletions boa/src/builtins/set/set_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub enum SetIterationKind {
#[derive(Debug, Clone, Finalize, Trace)]
pub struct SetIterator {
iterated_set: Value,
set_next_index: usize,
set_iteration_kind: SetIterationKind,
next_index: usize,
iteration_kind: SetIterationKind,
}

impl SetIterator {
Expand All @@ -34,8 +34,8 @@ impl SetIterator {
fn new(set: Value, kind: SetIterationKind) -> Self {
SetIterator {
iterated_set: set,
set_next_index: 0,
set_iteration_kind: kind,
next_index: 0,
iteration_kind: kind,
}
}

Expand All @@ -51,14 +51,14 @@ impl SetIterator {
context: &Context,
set: Value,
kind: SetIterationKind,
) -> Result<Value> {
) -> Value {
let set_iterator = Value::new_object(context);
set_iterator.set_data(ObjectData::SetIterator(Self::new(set, kind)));
set_iterator
.as_object()
.expect("set iterator object")
.set_prototype_instance(context.iterator_prototypes().set_iterator().into());
Ok(set_iterator)
set_iterator
}

/// %SetIteratorPrototype%.next( )
Expand All @@ -74,8 +74,8 @@ impl SetIterator {
let mut object = object.borrow_mut();
if let Some(set_iterator) = object.as_set_iterator_mut() {
let m = &set_iterator.iterated_set;
let mut index = set_iterator.set_next_index;
let item_kind = &set_iterator.set_iteration_kind;
let mut index = set_iterator.next_index;
let item_kind = &set_iterator.iteration_kind;

if set_iterator.iterated_set.is_undefined() {
return Ok(create_iter_result_object(context, Value::undefined(), true));
Expand All @@ -87,7 +87,7 @@ impl SetIterator {
while index < num_entries {
let e = entries.get_index(index);
index += 1;
set_iterator.set_next_index = index;
set_iterator.next_index = index;
if let Some(value) = e {
match item_kind {
SetIterationKind::Value => {
Expand Down

0 comments on commit f94e23b

Please sign in to comment.