Skip to content

Commit

Permalink
Fix panics
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Sep 25, 2023
1 parent 61adb25 commit db420ed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/map/map_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsObject>,
map_next_index: usize,
Expand Down
15 changes: 5 additions & 10 deletions boa_engine/src/builtins/map/ordered_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,13 @@ impl<V> OrderedMap<V> {
/// 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();
}
Expand Down
14 changes: 5 additions & 9 deletions boa_engine/src/builtins/set/ordered_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/set/set_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit db420ed

Please sign in to comment.