summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js')
-rw-r--r--js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js b/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js
new file mode 100644
index 0000000000..e83db0f656
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js
@@ -0,0 +1,41 @@
+// Copyright (c) 2021 Rick Waldron. All rights reserved.
+// This code is governed by the license found in the LICENSE file.
+
+/*---
+esid: sec-array.from
+description: >
+ Creates an array with length that is equal to the value of the
+ length property of the given array-like, regardless of
+ the presence of corresponding indices and values.
+info: |
+ Array.from ( items [ , mapfn [ , thisArg ] ] )
+
+ 7. Let arrayLike be ! ToObject(items).
+ 8. Let len be ? LengthOfArrayLike(arrayLike).
+ 9. If IsConstructor(C) is true, then
+ a. Let A be ? Construct(C, « 𝔽(len) »).
+ 10. Else,
+ a. Let A be ? ArrayCreate(len).
+
+includes: [compareArray.js]
+---*/
+
+const length = 5;
+
+const newlyCreatedArray = Array.from({ length });
+assert.sameValue(
+ newlyCreatedArray.length,
+ length,
+ "The newly created array's length is equal to the value of the length property for the provided array like object"
+);
+assert.compareArray(newlyCreatedArray, [undefined, undefined, undefined, undefined, undefined]);
+
+const newlyCreatedAndMappedArray = Array.from({ length }).map(x => 1);
+assert.sameValue(
+ newlyCreatedAndMappedArray.length,
+ length,
+ "The newly created and mapped array's length is equal to the value of the length property for the provided array like object"
+);
+assert.compareArray(newlyCreatedAndMappedArray, [1, 1, 1, 1, 1]);
+
+reportCompare(0, 0);