From 4ec340c8ffe48dbc05a2f6010a4c9dae2bf3d1e9 Mon Sep 17 00:00:00 2001 From: Haled Odat Date: Sat, 25 Mar 2023 10:23:23 +0100 Subject: [PATCH] Fix deletion of a single property object --- boa_engine/src/object/shape/shared_shape.rs | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/boa_engine/src/object/shape/shared_shape.rs b/boa_engine/src/object/shape/shared_shape.rs index c4d8b919758..552b5f1ce6f 100644 --- a/boa_engine/src/object/shape/shared_shape.rs +++ b/boa_engine/src/object/shape/shared_shape.rs @@ -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() @@ -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 { @@ -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()), @@ -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, @@ -357,7 +360,7 @@ impl SharedShape { pub(crate) fn keys(&self) -> Vec { 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 = property_table .keys() @@ -365,6 +368,7 @@ impl SharedShape { .filter(|key| matches!(key, PropertyKey::String(_))) .cloned() .collect(); + keys.extend( property_table .keys()