diff --git a/boa_engine/src/builtins/map/map_iterator.rs b/boa_engine/src/builtins/map/map_iterator.rs index 4d531d5bfc2..ca4c555b3c9 100644 --- a/boa_engine/src/builtins/map/map_iterator.rs +++ b/boa_engine/src/builtins/map/map_iterator.rs @@ -27,7 +27,7 @@ use boa_profiler::Profiler; /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-map-iterator-objects -#[derive(Debug, Clone, Finalize, Trace)] +#[derive(Debug, Finalize, Trace)] pub struct MapIterator { iterated_map: Option, map_next_index: usize, diff --git a/boa_engine/src/builtins/map/ordered_map.rs b/boa_engine/src/builtins/map/ordered_map.rs index 812d5c68ba5..8a9b262ed3c 100644 --- a/boa_engine/src/builtins/map/ordered_map.rs +++ b/boa_engine/src/builtins/map/ordered_map.rs @@ -217,18 +217,13 @@ impl OrderedMap { /// Increases the lock count of the map for the lifetime of the guard. This should not be dropped until iteration has completed. #[derive(Debug, Trace)] pub(crate) struct MapLock(JsObject); - -impl Clone for MapLock { - fn clone(&self) -> Self { - let mut map = self.0.borrow_mut(); - let map = map.as_map_mut().expect("MapLock does not point to a map"); - map.lock(self.0.clone()) - } -} - impl Finalize for MapLock { fn finalize(&self) { - let mut map = self.0.borrow_mut(); + // Avoids panicking inside `Finalize`, with the downside of slightly increasing + // memory usage if the map could not be borrowed. + let Ok(mut map) = self.0.try_borrow_mut() else { + return; + }; let map = map.as_map_mut().expect("MapLock does not point to a map"); map.unlock(); } diff --git a/boa_engine/src/builtins/set/ordered_set.rs b/boa_engine/src/builtins/set/ordered_set.rs index db6c56a8d9d..2ebb853bd81 100644 --- a/boa_engine/src/builtins/set/ordered_set.rs +++ b/boa_engine/src/builtins/set/ordered_set.rs @@ -173,17 +173,13 @@ impl OrderedSet { #[derive(Debug, Trace)] pub(crate) struct SetLock(JsObject); -impl Clone for SetLock { - fn clone(&self) -> Self { - let mut set = self.0.borrow_mut(); - let set = set.as_set_mut().expect("SetLock does not point to a set"); - set.lock(self.0.clone()) - } -} - impl Finalize for SetLock { fn finalize(&self) { - let mut set = self.0.borrow_mut(); + // Avoids panicking inside `Finalize`, with the downside of slightly increasing + // memory usage if the set could not be borrowed. + let Ok(mut set) = self.0.try_borrow_mut() else { + return; + }; let set = set.as_set_mut().expect("SetLock does not point to a set"); set.unlock(); } diff --git a/boa_engine/src/builtins/set/set_iterator.rs b/boa_engine/src/builtins/set/set_iterator.rs index f49eab2a46d..514331bb4a0 100644 --- a/boa_engine/src/builtins/set/set_iterator.rs +++ b/boa_engine/src/builtins/set/set_iterator.rs @@ -27,7 +27,7 @@ use boa_profiler::Profiler; /// - [ECMAScript reference][spec] /// /// [spec]: https://tc39.es/ecma262/#sec-set-iterator-objects -#[derive(Debug, Clone, Finalize, Trace)] +#[derive(Debug, Finalize, Trace)] pub struct SetIterator { iterated_set: JsValue, next_index: usize,