blob: 156aaba5f14bf3ffb38e21aa0e80b4a5dd8013fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Test that we can't confuse %ArrayIteratorPrototype% for an
// ArrayIterator object.
function TestArrayIteratorPrototypeConfusion() {
var iter = [][Symbol.iterator]();
try {
iter.next.call(Object.getPrototypeOf(iter))
throw new Error("Call did not throw");
} catch (e) {
assertEq(e instanceof TypeError, true);
assertEq(e.message, "next method called on incompatible Array Iterator");
}
}
TestArrayIteratorPrototypeConfusion();
// Tests that we can use %ArrayIteratorPrototype%.next on a
// cross-compartment iterator.
function TestArrayIteratorWrappers() {
var iter = [][Symbol.iterator]();
assertDeepEq(iter.next.call(newGlobal().eval('[5][Symbol.iterator]()')),
{ value: 5, done: false })
}
if (typeof newGlobal === "function") {
TestArrayIteratorWrappers();
}
// Tests that calling |next| on an array iterator after iteration has finished
// doesn't get the array's |length| property.
function TestIteratorNextGetLength() {
var lengthCalledTimes = 0;
var array = {
__proto__: Array.prototype,
get length() {
lengthCalledTimes += 1;
return {
valueOf() {
return 0;
}
};
}
};
var it = array[Symbol.iterator]();
it.next();
it.next();
assertEq(1, lengthCalledTimes);
}
TestIteratorNextGetLength();
if (typeof reportCompare === "function")
reportCompare(true, true);
|