Skip to content

Commit

Permalink
Fix remaining property tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Jul 30, 2021
1 parent a458dc7 commit b7c07ac
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 47 deletions.
6 changes: 5 additions & 1 deletion boa/src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ pub fn init(context: &mut Context) {

for init in &globals {
let (name, value, attribute) = init(context);
let property = PropertyDescriptor::builder().value(value).writable(attribute.writable()).enumerable(attribute.enumerable()).configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
global_object.borrow_mut().insert(name, property);
}
}
8 changes: 4 additions & 4 deletions boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,21 @@ impl Object {
}
DescriptorKind::Accessor { get, set } => {
if let Some(get) = get {
descriptor.property("get", get.clone(),Attribute::all() );
descriptor.property("get", get.clone(), Attribute::all());
}
if let Some(set) = set {
descriptor.property("set", set.clone(),Attribute::all());
descriptor.property("set", set.clone(), Attribute::all());
}
}
_ => {}
}

if let Some(enumerable) = desc.enumerable() {
descriptor.property("enumerable", enumerable,Attribute::all());
descriptor.property("enumerable", enumerable, Attribute::all());
}

if let Some(configurable) = desc.configurable() {
descriptor.property("configurable", configurable,Attribute::all());
descriptor.property("configurable", configurable, Attribute::all());
}

descriptor.build().into()
Expand Down
20 changes: 7 additions & 13 deletions boa/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl StandardObjects {
/// ## Execute Function of Script File
///
/// ```rust
/// use boa::{Context, object::ObjectInitializer, property::PropertyDescriptor};
/// use boa::{Context, object::ObjectInitializer, property::{Attribute, PropertyDescriptor}};
///
/// let script = r#"
/// function test(arg1) {
Expand All @@ -241,7 +241,7 @@ impl StandardObjects {
///
/// // Create an object that can be used in eval calls.
/// let arg = ObjectInitializer::new(&mut context)
/// .property("x", PropertyDescriptor::builder().value(12).writable(false))
/// .property("x", 12, Attribute::READONLY)
/// .build();
/// context.register_global_property(
/// "arg",
Expand Down Expand Up @@ -636,7 +636,7 @@ impl Context {
///
/// # Example
/// ```
/// use boa::{Context, property::PropertyDescriptor, object::ObjectInitializer};
/// use boa::{Context, property::{Attribute, PropertyDescriptor}, object::ObjectInitializer};
///
/// let mut context = Context::new();
///
Expand All @@ -652,19 +652,13 @@ impl Context {
/// let object = ObjectInitializer::new(&mut context)
/// .property(
/// "x",
/// PropertyDescriptor::builder()
/// .value(0)
/// .writable(true)
/// .enumerable(true)
/// .configurable(true)
/// 0,
/// Attribute::all()
/// )
/// .property(
/// "y",
/// PropertyDescriptor::builder()
/// .value(1)
/// .writable(true)
/// .enumerable(true)
/// .configurable(true)
/// 1,
/// Attribute::all()
/// )
/// .build();
/// context.register_global_property(
Expand Down
23 changes: 13 additions & 10 deletions boa/src/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl GcObject {
DescriptorKind::Data {
value: Some(value), ..
} => Ok(value.clone()),
DescriptorKind::Accessor { get: Some(get), .. } => {
DescriptorKind::Accessor { get: Some(get), .. } if !get.is_undefined() => {
context.call(get, &receiver, &[])
}
_ => Ok(Value::undefined()),
Expand Down Expand Up @@ -351,19 +351,22 @@ impl GcObject {
if !existing_desc.expect_writable() {
return Ok(false);
}
receiver.__define_own_property__(
return receiver.__define_own_property__(
key,
PropertyDescriptor::builder().value(value).build(),
context,
)
);
} else {
receiver.create_data_property(key, value, context)
return receiver.create_data_property(key, value, context);
}
} else if let Some(set) = own_desc.set() {
context.call(set, &receiver, &[value])?;
Ok(true)
} else {
Ok(false)
}

match own_desc.set() {
Some(set) if !set.is_undefined() => {
context.call(set, &receiver, &[value])?;
Ok(true)
}
_ => Ok(false),
}
}

Expand Down Expand Up @@ -702,7 +705,7 @@ impl GcObject {
}

for (p, d) in descriptors {
self.__define_own_property__(p, d, context)?;
self.define_property_or_throw(p, d, context)?;
}

Ok(())
Expand Down
49 changes: 30 additions & 19 deletions boa/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,24 +804,18 @@ impl<'context> FunctionBuilder<'context> {
/// # Examples
///
/// ```
/// # use boa::{Context, Value, object::ObjectInitializer, property::PropertyDescriptor};
/// # use boa::{Context, Value, object::ObjectInitializer, property::Attribute};
/// let mut context = Context::new();
/// let object = ObjectInitializer::new(&mut context)
/// .property(
/// "hello",
/// PropertyDescriptor::builder()
/// .value("world")
/// .writable(true)
/// .enumerable(true)
/// .configurable(true)
/// "world",
/// Attribute::all()
/// )
/// .property(
/// 1,
/// PropertyDescriptor::builder()
/// .value(1)
/// .writable(true)
/// .enumerable(true)
/// .configurable(true)
/// 1,
/// Attribute::all()
/// )
/// .function(|_, _, _| Ok(Value::undefined()), "func", 0)
/// .build();
Expand Down Expand Up @@ -881,10 +875,11 @@ impl<'context> ObjectInitializer<'context> {
K: Into<PropertyKey>,
V: Into<Value>,
{
let property = PropertyDescriptor::builder().value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.object.borrow_mut().insert(key, property);
self
}
Expand Down Expand Up @@ -1021,7 +1016,11 @@ impl<'context> ConstructorBuilder<'context> {
K: Into<PropertyKey>,
V: Into<Value>,
{
let property = PropertyDescriptor::builder().value(value).writable(attribute.writable()).enumerable(attribute.enumerable()).configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.prototype.borrow_mut().insert(key, property);
self
}
Expand All @@ -1033,7 +1032,11 @@ impl<'context> ConstructorBuilder<'context> {
K: Into<PropertyKey>,
V: Into<Value>,
{
let property = PropertyDescriptor::builder().value(value).writable(attribute.writable()).enumerable(attribute.enumerable()).configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.value(value)
.writable(attribute.writable())
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.constructor_object.borrow_mut().insert(key, property);
self
}
Expand All @@ -1050,7 +1053,11 @@ impl<'context> ConstructorBuilder<'context> {
where
K: Into<PropertyKey>,
{
let property = PropertyDescriptor::builder().maybe_get(get).maybe_set(set).enumerable(attribute.enumerable()).configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.maybe_get(get)
.maybe_set(set)
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.prototype.borrow_mut().insert(key, property);
self
}
Expand All @@ -1067,7 +1074,11 @@ impl<'context> ConstructorBuilder<'context> {
where
K: Into<PropertyKey>,
{
let property = PropertyDescriptor::builder().maybe_get(get).maybe_set(set).enumerable(attribute.enumerable()).configurable(attribute.configurable());
let property = PropertyDescriptor::builder()
.maybe_get(get)
.maybe_set(set)
.enumerable(attribute.enumerable())
.configurable(attribute.configurable());
self.constructor_object.borrow_mut().insert(key, property);
self
}
Expand Down

0 comments on commit b7c07ac

Please sign in to comment.