diff --git a/boa/src/builtins/map/mod.rs b/boa/src/builtins/map/mod.rs index 7975484c39f..29733065f70 100644 --- a/boa/src/builtins/map/mod.rs +++ b/boa/src/builtins/map/mod.rs @@ -364,16 +364,17 @@ impl Map { // 4. For each Record { [[Key]], [[Value]] } p of entries, do // a. Set p.[[Key]] to empty. // b. Set p.[[Value]] to empty. + Self::set_size(this, 0); if let Some(object) = this.as_object() { if let Some(map) = object.borrow_mut().as_map_mut() { map.clear(); - Ok(JsValue::undefined()) } else { - context.throw_type_error("'this' is not a Map") + return context.throw_type_error("'this' is not a Map"); } } else { - context.throw_type_error("'this' is not a Map") + return context.throw_type_error("'this' is not a Map"); } + Ok(JsValue::undefined()) } /// `Map.prototype.has( key )` diff --git a/boa/src/builtins/map/ordered_map.rs b/boa/src/builtins/map/ordered_map.rs index 1ff94364cfb..e240a177846 100644 --- a/boa/src/builtins/map/ordered_map.rs +++ b/boa/src/builtins/map/ordered_map.rs @@ -143,7 +143,7 @@ impl OrderedMap { } pub fn clear(&mut self) { - self.map = IndexMap::new(); + self.map.truncate(0); } /// Return a reference to the value stored for `key`, if it is present,