|
1 // Superficial tests for iterators created by Array.prototype.iterator |
|
2 |
|
3 load(libdir + "iteration.js"); |
|
4 |
|
5 var proto = Object.getPrototypeOf([][std_iterator]()); |
|
6 assertEq(Object.getPrototypeOf(proto), Iterator.prototype); |
|
7 proto = Object.getPrototypeOf([].keys()); |
|
8 assertEq(Object.getPrototypeOf(proto), Iterator.prototype); |
|
9 proto = Object.getPrototypeOf([].entries()); |
|
10 assertEq(Object.getPrototypeOf(proto), Iterator.prototype); |
|
11 |
|
12 function check(it) { |
|
13 assertEq(typeof it, 'object'); |
|
14 assertEq(Object.getPrototypeOf(it), proto); |
|
15 assertEq(Object.getOwnPropertyNames(it).length, 0); |
|
16 assertEq(it[std_iterator](), it); |
|
17 |
|
18 // for-in enumerates the iterator's properties. |
|
19 it.x = 0; |
|
20 var s = ''; |
|
21 for (var p in it) |
|
22 s += p + '.'; |
|
23 assertEq(s, 'x.'); |
|
24 } |
|
25 |
|
26 check([][std_iterator]()); |
|
27 check(Array.prototype[std_iterator].call({})); |
|
28 check([].keys()); |
|
29 check(Array.prototype.keys.call({})); |
|
30 check([].entries()); |
|
31 check(Array.prototype.entries.call({})); |