Debian Codegraph @

js/src/tests/test262/built-ins/Array/from/Array.from_forwards-length-for-array-likes.js

raw
1 // Copyright (c) 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 /*---
5 esid: sec-array.from
6 description: >
7 If this is a constructor, and items doesn't have an @@iterator,
8 returns a new instance of this
9 info: |
10 22.1.2.1 Array.from ( items [ , mapfn [ , thisArg ] ] )
11
12 4. Let usingIterator be GetMethod(items, @@iterator).
13 ...
14 6. If usingIterator is not undefined, then
15 ...
16 12. If IsConstructor(C) is true, then
17 a. Let A be Construct(C, «len»).
18 13. Else,
19 a. Let A be ArrayCreate(len).
20 ...
21 19. Return A.
22 ---*/
23
24 var result;
25
26 function MyCollection() {
27 this.args = arguments;
28 }
29
30 result = Array.from.call(MyCollection, {
31 length: 42
32 });
33
34 assert.sameValue(result.args.length, 1, 'The value of result.args.length is expected to be 1');
35 assert.sameValue(result.args[0], 42, 'The value of result.args[0] is expected to be 42');
36 assert(
37 result instanceof MyCollection,
38 'The result of evaluating (result instanceof MyCollection) is expected to be true'
39 );
40
41 reportCompare(0, 0);