1 // This test checks the behavior of the %ArrayIteratorPrototype%.next methods with call.
3 var array
= [0, 1, 2, 3, 4];
4 var arrayIterator
= array
[Symbol
.iterator
]();
5 var arrayIteratorPrototype
= arrayIterator
.__proto__
;
6 var arrayIteratorPrototypeNext
= arrayIteratorPrototype
.next
;
8 if (arrayIterator
.hasOwnProperty('next'))
9 throw "next method should exists on %ArrayIteratorPrototype%";
10 if (!arrayIteratorPrototype
.hasOwnProperty('next'))
11 throw "next method should exists on %ArrayIteratorPrototype%";
13 var array1
= [42, 43, 41];
14 var array1Iterator
= array1
[Symbol
.iterator
]();
17 var result
= arrayIteratorPrototypeNext
.call(array1Iterator
);
18 var value
= result
.value
;
22 if (value
!== array1
[index
++])
23 throw "Error: bad value: " + value
;
26 throw "Error: bad index: " + index
;
28 function increment(iter
) {
29 return arrayIteratorPrototypeNext
.call(iter
);
31 var array1
= [42, 43, -20];
32 var array2
= [42, 43, -20];
33 var array1Iterator
= array1
[Symbol
.iterator
]();
34 var array2Iterator
= array2
[Symbol
.iterator
]();
35 for (var i
= 0; i
< 3; ++i
) {
36 var value1
= increment(array1Iterator
).value
;
37 var value2
= increment(array2Iterator
).value
;
38 if (value1
!== value2
)
39 throw "Error: bad value: " + value1
+ " " + value2
;
42 var array1
= [ 0, 1, 2, 4, 5, 6 ];
43 var array1Iterator
= array1
[Symbol
.iterator
]();
45 var value
= array1Iterator
.next().value
;
47 throw "Error: bad value: " + value
;
48 var value
= array1Iterator
.next().value
;
50 throw "Error: bad value: " + value
;
51 var value
= array1Iterator
.next().value
;
53 throw "Error: bad value: " + value
;
54 var value
= arrayIteratorPrototypeNext
.call(array1Iterator
).value
;
56 throw "Error: bad value: " + value
;
57 var value
= arrayIteratorPrototypeNext
.call(array1Iterator
).value
;
59 throw "Error: bad value: " + value
;
60 var value
= arrayIteratorPrototypeNext
.call(array1Iterator
).value
;
62 throw "Error: bad value: " + value
;
63 var value
= arrayIteratorPrototypeNext
.call(array1Iterator
).value
;
64 if (value
!== undefined)
65 throw "Error: bad value: " + value
;
77 for (var primitive
of primitives
) {
80 arrayIteratorPrototypeNext
.call(primitive
);
85 throw "Error: no error thrown";
86 var expectedMessage
= 'TypeError: %ArrayIteratorPrototype%.next requires that |this| be an Array Iterator instance';
87 if (primitive
== null)
88 expectedMessage
= 'TypeError: %ArrayIteratorPrototype%.next requires that |this| not be null or undefined';
89 if (String(didThrow
) !== expectedMessage
)
90 throw "Error: bad error thrown: " + didThrow
;
93 var nonRelatedObjects
= [
99 new String("Cappuccino"),
104 for (var object
of nonRelatedObjects
) {
107 arrayIteratorPrototypeNext
.call(object
);
112 throw "Error: no error thrown";
113 if (String(didThrow
) !== 'TypeError: %ArrayIteratorPrototype%.next requires that |this| be an Array Iterator instance')
114 throw "Error: bad error thrown: " + didThrow
;