Skip to content

Commit

Permalink
Fix enumerable attribute on array length property (#972)
Browse files Browse the repository at this point in the history
* Fix enumerable attribute on array length property

* Fix enumerable attribute on Array.prototype length property

* Add Attribute::Permanent to property length of Array.prototype

Co-authored-by: tofpie <tofpie@users.noreply.github.com>
  • Loading branch information
tofpie and tofpie authored Dec 18, 2020
1 parent c49f225 commit b5cf0f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions boa/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ impl BuiltIn for Array {
)
.name(Self::NAME)
.length(Self::LENGTH)
.property("length", 0, Attribute::all())
.property(
"length",
0,
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
)
.property(
"values",
values_function.clone(),
Expand Down Expand Up @@ -221,7 +225,11 @@ impl Array {
.as_object()
.expect("array object")
.set_prototype_instance(context.standard_objects().array_object().prototype().into());
array.set_field("length", Value::from(0));
let length = DataDescriptor::new(
Value::from(0),
Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT,
);
array.set_property("length", length);
Ok(array)
}

Expand Down
9 changes: 9 additions & 0 deletions boa/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,3 +1361,12 @@ fn get_relative_end() {
Ok(10)
);
}

#[test]
fn array_length_is_not_enumerable() {
let mut context = Context::new();

let array = Array::new_array(&mut context).unwrap();
let desc = array.get_property("length").unwrap();
assert!(!desc.enumerable());
}

0 comments on commit b5cf0f0

Please sign in to comment.