Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Array/from/iter-cstm-ctor.js

raw
1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-array.from
5 es6id: 22.1.2.1
6 description: Creating object with custom constructor (traversed via iterator)
7 info: |
8 [...]
9 6. If usingIterator is not undefined, then
10 a. If IsConstructor(C) is true, then
11 i. Let A be Construct(C).
12 b. Else,
13 i. Let A be ArrayCreate(0).
14 c. ReturnIfAbrupt(A).
15 features: [Symbol.iterator]
16 ---*/
17
18 var thisVal, args;
19 var callCount = 0;
20 var C = function() {
21 thisVal = this;
22 args = arguments;
23 callCount += 1;
24 };
25 var result;
26 var items = {};
27 items[Symbol.iterator] = function() {
28 return {
29 next: function() {
30 return {
31 done: true
32 };
33 }
34 };
35 };
36
37 result = Array.from.call(C, items);
38
39 assert(
40 result instanceof C, 'Constructed value is an instance of the constructor'
41 );
42 assert.sameValue(
43 result.constructor,
44 C,
45 'Constructed value correctly defines a `constructor` property'
46 );
47 assert.sameValue(callCount, 1, 'Constructor invoked exactly once');
48 assert.sameValue(thisVal, result, 'Constructed value is returned');
49 assert.sameValue(args.length, 0, 'Constructor invoked without arguments');