diff --git a/boa_engine/src/object/property_map.rs b/boa_engine/src/object/property_map.rs index ed1cea1d66c..9a06080a130 100644 --- a/boa_engine/src/object/property_map.rs +++ b/boa_engine/src/object/property_map.rs @@ -244,7 +244,7 @@ impl PropertyMap { pub fn from_prototype_unique_shape(prototype: JsPrototype) -> Self { Self { indexed_properties: IndexedProperties::default(), - shape: Shape::unique(UniqueShape::new(prototype, PropertyTableInner::default())), + shape: UniqueShape::new(prototype, PropertyTableInner::default()).into(), storage: Vec::default(), } } @@ -259,7 +259,7 @@ impl PropertyMap { let shape = root_shape.shape().change_prototype_transition(prototype); Self { indexed_properties: IndexedProperties::default(), - shape: Shape::shared(shape), + shape: shape.into(), storage: Vec::default(), } } diff --git a/boa_engine/src/object/shape/mod.rs b/boa_engine/src/object/shape/mod.rs index 3527be4b247..e2b770628aa 100644 --- a/boa_engine/src/object/shape/mod.rs +++ b/boa_engine/src/object/shape/mod.rs @@ -66,7 +66,7 @@ pub struct Shape { impl Default for Shape { fn default() -> Self { - Shape::unique(UniqueShape::default()) + UniqueShape::default().into() } } @@ -77,20 +77,6 @@ impl Shape { /// NOTE: This only applies to [`SharedShape`]. const TRANSITION_COUNT_MAX: u16 = 1024; - /// Create a [`Shape`] from a [`SharedShape`]. - pub(crate) fn shared(inner: SharedShape) -> Self { - Self { - inner: Inner::Shared(inner), - } - } - - /// Create a [`Shape`] from a [`UniqueShape`]. - pub(crate) const fn unique(shape: UniqueShape) -> Self { - Self { - inner: Inner::Unique(shape), - } - } - /// Returns `true` if it's a shared shape, `false` otherwise. #[inline] pub const fn is_shared(&self) -> bool { @@ -118,11 +104,11 @@ impl Shape { Inner::Shared(shape) => { let shape = shape.insert_property_transition(key); if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { - return Self::unique(shape.to_unique()); + return shape.to_unique().into(); } - Self::shared(shape) + shape.into() } - Inner::Unique(shape) => Self::unique(shape.insert_property_transition(key)), + Inner::Unique(shape) => shape.insert_property_transition(key).into(), } } @@ -139,9 +125,9 @@ impl Shape { let change_transition = shape.change_attributes_transition(key); let shape = if change_transition.shape.transition_count() >= Self::TRANSITION_COUNT_MAX { - Self::unique(change_transition.shape.to_unique()) + change_transition.shape.to_unique().into() } else { - Self::shared(change_transition.shape) + change_transition.shape.into() }; ChangeTransition { shape, @@ -160,11 +146,11 @@ impl Shape { Inner::Shared(shape) => { let shape = shape.remove_property_transition(key); if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { - return Self::unique(shape.to_unique()); + return shape.to_unique().into(); } - Self::shared(shape) + shape.into() } - Inner::Unique(shape) => Self::unique(shape.remove_property_transition(key)), + Inner::Unique(shape) => shape.remove_property_transition(key).into(), } } @@ -174,11 +160,11 @@ impl Shape { Inner::Shared(shape) => { let shape = shape.change_prototype_transition(prototype); if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { - return Self::unique(shape.to_unique()); + return shape.to_unique().into(); } - Self::shared(shape) + shape.into() } - Inner::Unique(shape) => Self::unique(shape.change_prototype_transition(prototype)), + Inner::Unique(shape) => shape.change_prototype_transition(prototype).into(), } } @@ -217,3 +203,19 @@ impl Shape { } } } + +impl From for Shape { + fn from(shape: UniqueShape) -> Self { + Self { + inner: Inner::Unique(shape), + } + } +} + +impl From for Shape { + fn from(shape: SharedShape) -> Self { + Self { + inner: Inner::Shared(shape), + } + } +} diff --git a/boa_engine/src/object/shape/root_shape.rs b/boa_engine/src/object/shape/root_shape.rs index e025ff9da2f..da64191ee59 100644 --- a/boa_engine/src/object/shape/root_shape.rs +++ b/boa_engine/src/object/shape/root_shape.rs @@ -2,15 +2,16 @@ use boa_macros::{Finalize, Trace}; use super::SharedShape; -/// Represent the root shape that [`SharedShape`] transitions start from. +/// This is a wrapper around [`SharedShape`] that ensures it's root shape. /// -/// This is a wrapper around [`SharedShape`] that ensures that the shape the root shape. +/// Represent the root shape that [`SharedShape`] transitions start from. #[derive(Debug, Clone, Trace, Finalize)] pub struct RootShape { shape: SharedShape, } impl Default for RootShape { + #[inline] fn default() -> Self { Self { shape: SharedShape::root(), @@ -20,7 +21,7 @@ impl Default for RootShape { impl RootShape { /// Gets the inner [`SharedShape`]. - pub(crate) const fn shape(&self) -> &SharedShape { + pub const fn shape(&self) -> &SharedShape { &self.shape } } diff --git a/boa_engine/src/object/shape/shared_shape/template.rs b/boa_engine/src/object/shape/shared_shape/template.rs index 1f9d3b4141e..14316cd21fb 100644 --- a/boa_engine/src/object/shape/shared_shape/template.rs +++ b/boa_engine/src/object/shape/shared_shape/template.rs @@ -2,10 +2,7 @@ use boa_gc::{Finalize, Trace}; use thin_vec::ThinVec; use crate::{ - object::{ - shape::{slot::SlotAttributes, Shape}, - JsObject, Object, ObjectData, PropertyMap, - }, + object::{shape::slot::SlotAttributes, JsObject, Object, ObjectData, PropertyMap}, property::{Attribute, PropertyKey}, JsValue, }; @@ -21,15 +18,15 @@ pub(crate) struct ObjectTemplate { impl ObjectTemplate { /// Create a new [`ObjectTemplate`] - pub(crate) fn new(root_shape: &SharedShape) -> Self { + pub(crate) fn new(shape: &SharedShape) -> Self { Self { - shape: root_shape.clone(), + shape: shape.clone(), } } /// Create and [`ObjectTemplate`] with a prototype. - pub(crate) fn with_prototype(root_shape: &SharedShape, prototype: JsObject) -> Self { - let shape = root_shape.change_prototype_transition(Some(prototype)); + pub(crate) fn with_prototype(shape: &SharedShape, prototype: JsObject) -> Self { + let shape = shape.change_prototype_transition(Some(prototype)); Self { shape } } @@ -111,7 +108,7 @@ impl ObjectTemplate { let mut object = Object { kind: data.kind, extensible: true, - properties: PropertyMap::new(Shape::shared(self.shape.clone()), ThinVec::default()), + properties: PropertyMap::new(self.shape.clone().into(), ThinVec::default()), private_elements: ThinVec::new(), }; @@ -133,7 +130,7 @@ impl ObjectTemplate { let mut object = Object { kind: data.kind, extensible: true, - properties: PropertyMap::new(Shape::shared(self.shape.clone()), elements), + properties: PropertyMap::new(self.shape.clone().into(), elements), private_elements: ThinVec::new(), }; diff --git a/boa_engine/src/object/shape/unique_shape.rs b/boa_engine/src/object/shape/unique_shape.rs index 5e052fb02c7..68872a96c82 100644 --- a/boa_engine/src/object/shape/unique_shape.rs +++ b/boa_engine/src/object/shape/unique_shape.rs @@ -149,7 +149,7 @@ impl UniqueShape { property_table.keys[index].1.attributes = key.attributes; // TODO: invalidate the pointer. return ChangeTransition { - shape: Shape::unique(self.clone()), + shape: self.clone().into(), action: ChangeTransitionAction::Nothing, }; } @@ -211,7 +211,7 @@ impl UniqueShape { let shape = Self::new(prototype, property_table); ChangeTransition { - shape: Shape::unique(shape), + shape: shape.into(), action, } }