Skip to content

Commit

Permalink
Merge 638229f into a933ae8
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Jul 8, 2020
2 parents a933ae8 + 638229f commit ffdf4de
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 54 deletions.
22 changes: 7 additions & 15 deletions boa/src/builtins/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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(), &current.set.clone().unwrap())
{
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
}

Expand Down
34 changes: 15 additions & 19 deletions boa/src/builtins/property/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<bool>,
pub configurable: bool,
/// If the property shows up in enumeration of the object
pub enumerable: Option<bool>,
pub enumerable: bool,
/// If this property can be changed with an assignment
pub writable: Option<bool>,
/// The value associated with the property
Expand All @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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]].
Expand Down Expand Up @@ -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,
Expand All @@ -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;
4 changes: 2 additions & 2 deletions boa/src/builtins/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ impl Value {
&self,
field: &str,
value: Option<Value>,
enumerable: Option<bool>,
enumerable: bool,
writable: Option<bool>,
configurable: Option<bool>,
configurable: bool,
) {
let _timer = BoaProfiler::global().start_event("Value::update_property", "value");

Expand Down
20 changes: 4 additions & 16 deletions boa/src/environment/global_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion boa/src/environment/object_environment_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ffdf4de

Please sign in to comment.