-
Notifications
You must be signed in to change notification settings - Fork 381
/
builtin_weakset_test.go
101 lines (86 loc) · 1.79 KB
/
builtin_weakset_test.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package goja
import (
"testing"
)
func TestWeakSetBasic(t *testing.T) {
const SCRIPT = `
var s = new WeakSet();
var o = {};
s.add(o);
if (!s.has(o)) {
throw new Error("has");
}
s.delete(o);
if (s.has(o)) {
throw new Error("still has");
}
`
testScript(SCRIPT, _undefined, t)
}
func TestWeakSetArraySimple(t *testing.T) {
const SCRIPT = `
var o1 = {}, o2 = {}, o3 = {};
var s = new WeakSet([o1, o2, o3]);
s.has(o1) && s.has(o2) && s.has(o3);
`
testScript(SCRIPT, valueTrue, t)
}
func TestWeakSetArrayGeneric(t *testing.T) {
const SCRIPT = `
var o1 = {}, o2 = {}, o3 = {};
var a = new Array();
var s;
var thrown = false;
a[1] = o2;
try {
s = new WeakSet(a);
} catch (e) {
if (e instanceof TypeError) {
thrown = true;
}
}
if (!thrown) {
throw new Error("Case 1 does not throw");
}
Object.defineProperty(a.__proto__, "0", {value: o1, writable: true, enumerable: true, configurable: true});
s = new WeakSet(a);
if (!(s.has(o1) && s.has(o2) && !s.has(o3))) {
throw new Error("Case 2 failed");
}
Object.defineProperty(a, "2", {value: o3, configurable: true});
s = new WeakSet(a);
s.has(o1) && s.has(o2) && s.has(o3);
`
testScript(SCRIPT, valueTrue, t)
}
func TestWeakSetGetAdderGetIteratorOrder(t *testing.T) {
const SCRIPT = `
let getterCalled = 0;
class S extends WeakSet {
get add() {
getterCalled++;
return null;
}
}
let getIteratorCalled = 0;
let iterable = {};
iterable[Symbol.iterator] = () => {
getIteratorCalled++
return {
next: 1
};
}
let thrown = false;
try {
new S(iterable);
} catch (e) {
if (e instanceof TypeError) {
thrown = true;
} else {
throw e;
}
}
thrown && getterCalled === 1 && getIteratorCalled === 0;
`
testScript(SCRIPT, valueTrue, t)
}