Truly independent web browser
LibJS: Drop the check for holes when promoting dictionary elements
Andreas Klinge3977f23a79a
diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rsindex 44cecdec982..cec368297f3 100644--- a/Libraries/LibJS/Rust/src/runtime/object.rs+++ b/Libraries/LibJS/Rust/src/runtime/object.rs@@ -4198,7 +4198,7 @@ impl Object {&& dictionary.sparse_elements().values()- .all(|element| element.attributes == DEFAULT_ATTRIBUTES && !element.value.is_empty())+ .all(|element| element.attributes == DEFAULT_ATTRIBUTES){Some(if dictionary.size() == length {IndexedStorageKind::Packeddiff --git a/Tests/LibJS/Runtime/builtins/Array/array-literal-with-many-holes.js b/Tests/LibJS/Runtime/builtins/Array/array-literal-with-many-holes.jsnew file mode 100644index 00000000000..f2876e8c553--- /dev/null+++ b/Tests/LibJS/Runtime/builtins/Array/array-literal-with-many-holes.js@@ -0,0 +1,20 @@+test("holes in a long, sparse array literal stay holes", () => {+ const x = {};+ // NB: Long array literals are built element by element, and this one becomes sparse enough to turn into a+ // dictionary while its holes go in.+ const array = eval("[x" + ",".repeat(401) + "x, , x]");+ expect(array.length).toBe(404);+ expect(Object.keys(array)).toEqual(["0", "401", "403"]);+ for (let i = 1; i < 401; ++i) {+ expect(i in array).toBeFalse();+ expect(Object.getOwnPropertyDescriptor(array, i)).toBeUndefined();+ }+ expect(402 in array).toBeFalse();+ expect(array[0]).toBe(x);+ expect(array[401]).toBe(x);+ expect(array[403]).toBe(x);++ const concatenated = Array(2).concat(array);+ expect(concatenated.length).toBe(406);+ expect(Object.keys(concatenated)).toEqual(["2", "403", "405"]);+});