Skip to content

Commit

Permalink
Fix deletion of a single property object
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Mar 25, 2023
1 parent 9006bef commit 4ec340c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions boa_engine/src/object/shape/shared_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ pub(crate) struct SharedShape {
impl SharedShape {
const DEBUG: bool = false;

fn property_table_count(&self) -> u32 {
if self.previous().is_some() {
return self.property_index() + 1;
}

// root has no elements
0
}

#[inline]
pub(crate) fn previous(&self) -> Option<&SharedShape> {
self.inner.previous.as_ref()
Expand All @@ -137,7 +146,7 @@ impl SharedShape {
let properties = self.inner.property_table.properties().borrow();
let (key, (index, attributes)) = properties
.get_index(self.inner.property_index as usize)
.expect("There should be a key in property table");
.expect("There should be a property");
(key.clone(), *index, *attributes)
}
fn transition_type(&self) -> TransitionType {
Expand Down Expand Up @@ -181,18 +190,12 @@ impl SharedShape {
(self.property_index() + 1) * 2
};

let self_property_count = if self.previous().is_none() {
0
} else {
self.property_index() + 1
};

let (property_index, property_table) =
self.inner.property_table.add_property_deep_clone_if_needed(
key.property_key.clone(),
key.attributes,
slot_index,
self_property_count,
self.property_table_count(),
);
let new_inner_shape = Inner {
forward_property_transitions: GcRefCell::new(FxHashMap::default()),
Expand Down Expand Up @@ -313,7 +316,7 @@ impl SharedShape {
current = current_shape.previous();
};

for (property_key, attributes) in IntoIterator::into_iter(transitions).rev() {
for (property_key, attributes) in transitions.into_iter().rev() {
let transition = TransitionKey {
property_key,
attributes,
Expand Down Expand Up @@ -357,14 +360,15 @@ impl SharedShape {
pub(crate) fn keys(&self) -> Vec<PropertyKey> {
let property_table = self.inner.property_table.properties().borrow();

let property_count = (self.property_index() + 1) as usize;
let property_count = self.property_table_count() as usize;

let mut keys: Vec<PropertyKey> = property_table
.keys()
.take(property_count)
.filter(|key| matches!(key, PropertyKey::String(_)))
.cloned()
.collect();

keys.extend(
property_table
.keys()
Expand Down

0 comments on commit 4ec340c

Please sign in to comment.