From e0fb21e9e830362b0d0ec93597b2cc4fec75a77d Mon Sep 17 00:00:00 2001 From: tofpie Date: Wed, 16 Dec 2020 16:58:00 +0100 Subject: [PATCH 1/3] Fix enumerable attribute on array length property --- boa/src/builtins/array/mod.rs | 6 +++++- boa/src/builtins/array/tests.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index f4bf412b2b1..d588027ab4e 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -221,7 +221,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) } diff --git a/boa/src/builtins/array/tests.rs b/boa/src/builtins/array/tests.rs index e4b3a6c5cce..d87fa171f96 100644 --- a/boa/src/builtins/array/tests.rs +++ b/boa/src/builtins/array/tests.rs @@ -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()); +} From 956e012480ccfdcb9638376f8d47e2e7fc2fdcaf Mon Sep 17 00:00:00 2001 From: tofpie Date: Thu, 17 Dec 2020 09:22:08 +0100 Subject: [PATCH 2/3] Fix enumerable attribute on Array.prototype length property --- boa/src/builtins/array/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index d588027ab4e..54e17267076 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -58,7 +58,7 @@ impl BuiltIn for Array { ) .name(Self::NAME) .length(Self::LENGTH) - .property("length", 0, Attribute::all()) + .property("length", 0, Attribute::WRITABLE | Attribute::NON_ENUMERABLE) .property( "values", values_function.clone(), From b9daa0e1a63a910ba9c056524f0705c903de5f83 Mon Sep 17 00:00:00 2001 From: tofpie Date: Thu, 17 Dec 2020 09:51:32 +0100 Subject: [PATCH 3/3] Add Attribute::Permanent to property length of Array.prototype --- boa/src/builtins/array/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boa/src/builtins/array/mod.rs b/boa/src/builtins/array/mod.rs index 54e17267076..2cf29826309 100644 --- a/boa/src/builtins/array/mod.rs +++ b/boa/src/builtins/array/mod.rs @@ -58,7 +58,11 @@ impl BuiltIn for Array { ) .name(Self::NAME) .length(Self::LENGTH) - .property("length", 0, Attribute::WRITABLE | Attribute::NON_ENUMERABLE) + .property( + "length", + 0, + Attribute::WRITABLE | Attribute::NON_ENUMERABLE | Attribute::PERMANENT, + ) .property( "values", values_function.clone(),