Debian Codegraph @

js/src/tests/test262/built-ins/Array/from/array-like-has-length-but-no-indexes-with-values.js

raw
1 // Copyright (c) 2021 Rick Waldron. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /*---
5 esid: sec-array.from
6 description: >
7 Creates an array with length that is equal to the value of the
8 length property of the given array-like, regardless of
9 the presence of corresponding indices and values.
10 info: |
11 Array.from ( items [ , mapfn [ , thisArg ] ] )
12
13 7. Let arrayLike be ! ToObject(items).
14 8. Let len be ? LengthOfArrayLike(arrayLike).
15 9. If IsConstructor(C) is true, then
16 a. Let A be ? Construct(C, « 𝔽(len) »).
17 10. Else,
18 a. Let A be ? ArrayCreate(len).
19
20 includes: [compareArray.js]
21 ---*/
22
23 const length = 5;
24
25 const newlyCreatedArray = Array.from({ length });
26 assert.sameValue(
27 newlyCreatedArray.length,
28 length,
29 "The newly created array's length is equal to the value of the length property for the provided array like object"
30 );
31 assert.compareArray(newlyCreatedArray, [undefined, undefined, undefined, undefined, undefined]);
32
33 const newlyCreatedAndMappedArray = Array.from({ length }).map(x => 1);
34 assert.sameValue(
35 newlyCreatedAndMappedArray.length,
36 length,
37 "The newly created and mapped array's length is equal to the value of the length property for the provided array like object"
38 );
39 assert.compareArray(newlyCreatedAndMappedArray, [1, 1, 1, 1, 1]);
40
41 reportCompare(0, 0);