-
Notifications
You must be signed in to change notification settings - Fork 0
/
Iterator-next.PoC.js
56 lines (49 loc) · 1.13 KB
/
Iterator-next.PoC.js
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
51
52
53
54
55
56
// SPDX-License-Identifier: BlueOak-1.0.0
const value = "foobar";
const subject = {
[Symbol.iterator]() {
return {};
}
};
export const about = {
function: "Iterator",
link: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator",
properties: ["'next'"],
description: `
Any functionality operating on iterators assumes iterators are implemented
correctly, i.e. they return an object with a 'next' function. If an operator
fails to do so, the 'next' method may be looked up in the prototype hierarchy
instead.`,
spectrace: [
"https://tc39.es/ecma262/#sec-getiteratorfrommethod",
],
};
export function prerequisite() {
try {
Array.from(subject);
return [false, "unexpected non-throw"];
} catch (_) {
return [true, null];
}
}
export function test() {
{
let flag = false;
Object.prototype.next = () => {
if (flag) {
return { done: true };
}
flag = true;
return { value, done: false };
};
}
const got = Array.from(subject);
if (got.length === 1 && got[0] === value) {
return true;
} else {
return false;
}
}
export function cleanup() {
delete Object.prototype.next;
}