forked from dop251/goja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin_weakset_test.go
63 lines (55 loc) · 1.19 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
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");
}
`
testScript1(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);
`
testScript1(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);
`
testScript1(SCRIPT, valueTrue, t)
}