Skip to content

Commit

Permalink
Fix set_create() and add()
Browse files Browse the repository at this point in the history
  • Loading branch information
lameferret committed Jul 6, 2022
1 parent fe7b144 commit 7d66bfc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
14 changes: 3 additions & 11 deletions boa_engine/src/builtins/set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,13 @@ impl Set {
}

/// Utility for constructing `Set` objects.
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn set_create(
prototype: Option<JsObject>,
context: &mut Context,
) -> JsResult<JsObject> {
pub(crate) fn set_create(prototype: Option<JsObject>, context: &mut Context) -> JsObject {
let prototype = match prototype {
Some(prototype) => prototype,
None => context.intrinsics().constructors().set().prototype(),
};

Ok(JsObject::from_proto_and_data(
prototype,
ObjectData::set(OrderedSet::new()),
))
JsObject::from_proto_and_data(prototype, ObjectData::set(OrderedSet::new()))
}

/// Utility for constructing `Set` objects from an iterator of `JsValue`'s.
Expand All @@ -187,8 +180,7 @@ impl Set {
I: IntoIterator<Item = JsValue>,
{
// Create empty Set
let set = Self::set_create(None, context)
.expect("creating an empty set with default prototype must not fail");
let set = Self::set_create(None, context);
// For each element e of elements, do
for elem in elements {
Self::add(&set.clone().into(), &[elem], context)
Expand Down
11 changes: 1 addition & 10 deletions boa_engine/src/object/jsset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ impl JsSet {
/// similar to Rust initialization.
#[inline]
pub fn new(context: &mut Context) -> Self {
let inner = Set::set_create(None, context)
.expect("creating an empty set with the default prototype must not fail");
let inner = Set::set_create(None, context);

Self { inner }
}
Expand All @@ -44,14 +43,6 @@ impl JsSet {
where
T: Into<JsValue>,
{
// let object = Set::add(&self.inner.clone().into(), &[value.into()], context)?
// .as_object()
// .cloned()
// .expect("Set.prototype.add should always return `Set` object.");

// Self::from_object(object, context)

// TEST
self.add_items(&[value.into()], context)
}

Expand Down

0 comments on commit 7d66bfc

Please sign in to comment.