blob: 83024eeb8acc431cccfbac8418da8b60d180e3d4 (
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
|
// |reftest| skip-if(!this.hasOwnProperty('Iterator')) -- Iterator is not enabled unconditionally
//
// This test checks that %Iterator.prototype%.toArray only gets the `next` method off of the
// iterator once, and never accesses the @@iterator property.
const log = [];
const handlerProxy = new Proxy({}, {
get: (target, key, receiver) => (...args) => {
log.push(`${key}: ${args[1]?.toString()}`);
return Reflect[key](...args);
},
});
class Counter extends Iterator {
value = 0;
next() {
const value = this.value;
if (value < 2) {
this.value = value + 1;
return {done: false, value};
}
return {done: true};
}
}
const iter = new Proxy(new Counter(), handlerProxy);
const array = iter.toArray();
assertEq(
log.join('\n'),
`get: toArray
get: next
get: value
set: value
getOwnPropertyDescriptor: value
defineProperty: value
get: value
set: value
getOwnPropertyDescriptor: value
defineProperty: value
get: value`
);
if (typeof reportCompare === 'function')
reportCompare(0, 0);
|