Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Array/from/source-object-iterator-2.js

raw
1 // Copyright 2015 Microsoft Corporation. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /*---
5 description: Source object has iterator
6 esid: sec-array.from
7 es6id: 22.1.2.1
8 features: [Symbol.iterator]
9 ---*/
10
11 var array = [2, 4, 8, 16, 32, 64, 128];
12 var obj = {
13 [Symbol.iterator]() {
14 return {
15 index: 0,
16 next() {
17 return {
18 value: this.val,
19 done: this.isDone
20 };
21 },
22 isDone: false,
23 get val() {
24 this.index++;
25 if (this.index > 7) {
26 this.isDone = true;
27 }
28 return 1 << this.index;
29 }
30 };
31 }
32 };
33 var a = Array.from.call(Object, obj);
34 assert.sameValue(typeof a, typeof {}, "The returned type is expected to be object.");
35 for (var j = 0; j < a.length; j++) {
36 assert.sameValue(a[j], array[j], "Elements mismatch at " + j + ".");
37 }