diff --git a/boa/src/builtins/object/internal_methods.rs b/boa/src/builtins/object/internal_methods.rs index 7b79c0c0544..1dcb5e87721 100644 --- a/boa/src/builtins/object/internal_methods.rs +++ b/boa/src/builtins/object/internal_methods.rs @@ -73,7 +73,7 @@ impl Object { { return true; } - if desc.configurable.expect("unable to get value") { + if desc.configurable { self.remove_property(&prop_key.to_string()); return true; } @@ -184,18 +184,12 @@ impl Object { } // 4 - if !current.configurable.unwrap_or(false) { - if desc.configurable.is_some() && desc.configurable.expect("unable to get prop desc") { + if !current.configurable { + if desc.configurable { return false; } - if desc.enumerable.is_some() - && (desc.enumerable.as_ref().expect("unable to get prop desc") - != current - .enumerable - .as_ref() - .expect("unable to get prop desc")) - { + if desc.enumerable != current.enumerable { return false; } } @@ -205,7 +199,7 @@ impl Object { // 6 } else if current.is_data_descriptor() != desc.is_data_descriptor() { // a - if !current.configurable.expect("unable to get prop desc") { + if !current.configurable { return false; } // b @@ -224,9 +218,7 @@ impl Object { // 7 } else if current.is_data_descriptor() && desc.is_data_descriptor() { // a - if !current.configurable.expect("unable to get prop desc") - && !current.writable.expect("unable to get prop desc") - { + if !current.configurable && !current.writable.expect("unable to get prop desc") { if desc.writable.is_some() && desc.writable.expect("unable to get prop desc") { return false; } @@ -244,7 +236,7 @@ impl Object { } // 8 } else { - if !current.configurable.unwrap() { + if !current.configurable { if desc.set.is_some() && !same_value(&desc.set.clone().unwrap(), ¤t.set.clone().unwrap()) { diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 45cfbaa65c5..1e1d4067efe 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -528,7 +528,7 @@ pub fn property_is_enumerable(this: &Value, args: &[Value], ctx: &mut Interprete }); Ok(own_property.map_or(Value::from(false), |own_prop| { - Value::from(own_prop.enumerable.unwrap_or(false)) + Value::from(own_prop.enumerable) })) } diff --git a/boa/src/builtins/property/mod.rs b/boa/src/builtins/property/mod.rs index 5496e6256c2..855eccc6a31 100644 --- a/boa/src/builtins/property/mod.rs +++ b/boa/src/builtins/property/mod.rs @@ -17,6 +17,9 @@ use crate::builtins::value::Value; use gc::{Finalize, Trace}; +#[cfg(test)] +mod tests; + /// This represents a Javascript Property AKA The Property Descriptor. /// /// Property descriptors present in objects come in two main flavors: @@ -38,9 +41,9 @@ use gc::{Finalize, Trace}; #[derive(Trace, Finalize, Clone, Debug)] pub struct Property { /// If the type of this can be changed and this can be deleted - pub configurable: Option, + pub configurable: bool, /// If the property shows up in enumeration of the object - pub enumerable: Option, + pub enumerable: bool, /// If this property can be changed with an assignment pub writable: Option, /// The value associated with the property @@ -64,8 +67,8 @@ impl Property { /// Default: Defaults according to the spec pub fn new() -> Self { Self { - configurable: None, - enumerable: None, + configurable: false, + enumerable: false, writable: None, value: None, get: None, @@ -75,13 +78,13 @@ impl Property { /// Set configurable pub fn configurable(mut self, configurable: bool) -> Self { - self.configurable = Some(configurable); + self.configurable = configurable; self } /// Set enumerable pub fn enumerable(mut self, enumerable: bool) -> Self { - self.enumerable = Some(enumerable); + self.enumerable = enumerable; self } @@ -113,11 +116,7 @@ impl Property { /// /// `true` if all fields are set to none pub fn is_none(&self) -> bool { - self.get.is_none() - && self.set.is_none() - && self.writable.is_none() - && self.configurable.is_none() - && self.enumerable.is_none() + self.get.is_none() && self.set.is_none() && self.writable.is_none() } /// An accessor Property Descriptor is one that includes any fields named either [[Get]] or [[Set]]. @@ -160,8 +159,8 @@ impl Default for Property { /// [spec]: https://tc39.es/ecma262/#table-default-attribute-values fn default() -> Self { Self { - configurable: None, - enumerable: None, + configurable: false, + enumerable: false, writable: None, value: None, get: None, @@ -188,15 +187,12 @@ impl<'a> From<&'a Value> for Property { /// if they're not there default to false fn from(value: &Value) -> Self { Self { - configurable: { Some(bool::from(&value.get_field("configurable"))) }, - enumerable: { Some(bool::from(&value.get_field("enumerable"))) }, - writable: { Some(bool::from(&value.get_field("writable"))) }, + configurable: bool::from(&value.get_field("configurable")), + enumerable: bool::from(&value.get_field("enumerable")), + writable: Some(bool::from(&value.get_field("writable"))), value: Some(value.get_field("value")), get: Some(value.get_field("get")), set: Some(value.get_field("set")), } } } - -#[cfg(test)] -mod tests; diff --git a/boa/src/builtins/value/mod.rs b/boa/src/builtins/value/mod.rs index 8d5447dfe15..12f817b6d43 100644 --- a/boa/src/builtins/value/mod.rs +++ b/boa/src/builtins/value/mod.rs @@ -510,9 +510,9 @@ impl Value { &self, field: &str, value: Option, - enumerable: Option, + enumerable: bool, writable: Option, - configurable: Option, + configurable: bool, ) { let _timer = BoaProfiler::global().start_event("Value::update_property", "value"); diff --git a/boa/src/environment/global_environment_record.rs b/boa/src/environment/global_environment_record.rs index b04ec34d482..00068692e15 100644 --- a/boa/src/environment/global_environment_record.rs +++ b/boa/src/environment/global_environment_record.rs @@ -41,7 +41,7 @@ impl GlobalEnvironmentRecord { let existing_prop = global_object.get_property(name); match existing_prop { Some(prop) => { - if prop.value.is_none() || prop.configurable.unwrap_or(false) { + if prop.value.is_none() || prop.configurable { return false; } true @@ -70,23 +70,11 @@ impl GlobalEnvironmentRecord { let global_object = &mut self.object_record.bindings; let existing_prop = global_object.get_property(&name); if let Some(prop) = existing_prop { - if prop.value.is_none() || prop.configurable.unwrap_or(false) { - global_object.update_property( - name, - Some(value), - Some(true), - Some(true), - Some(deletion), - ); + if prop.value.is_none() || prop.configurable { + global_object.update_property(name, Some(value), true, Some(true), deletion); } } else { - global_object.update_property( - name, - Some(value), - Some(true), - Some(true), - Some(deletion), - ); + global_object.update_property(name, Some(value), true, Some(true), deletion); } } } diff --git a/boa/src/environment/object_environment_record.rs b/boa/src/environment/object_environment_record.rs index aada300d7a7..85016f9498b 100644 --- a/boa/src/environment/object_environment_record.rs +++ b/boa/src/environment/object_environment_record.rs @@ -63,7 +63,7 @@ impl EnvironmentRecordTrait for ObjectEnvironmentRecord { debug_assert!(value.is_object() || value.is_function()); let bindings = &mut self.bindings; - bindings.update_property(name, Some(value), None, None, Some(strict)); + bindings.update_property(name, Some(value), false, None, strict); } fn get_binding_value(&self, name: &str, strict: bool) -> Value {