forked from dop251/goja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin_weakmap_test.go
76 lines (67 loc) · 1.27 KB
/
builtin_weakmap_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
package goja
import (
"testing"
)
func TestWeakMap(t *testing.T) {
vm := New()
_, err := vm.RunString(`
var m = new WeakMap();
var m1 = new WeakMap();
var key = {};
m.set(key, true);
m1.set(key, false);
if (!m.has(key)) {
throw new Error("has");
}
if (m.get(key) !== true) {
throw new Error("value does not match");
}
if (!m1.has(key)) {
throw new Error("has (m1)");
}
if (m1.get(key) !== false) {
throw new Error("m1 value does not match");
}
m.delete(key);
if (m.has(key)) {
throw new Error("m still has after delete");
}
if (!m1.has(key)) {
throw new Error("m1 does not have after delete from m");
}
`)
if err != nil {
t.Fatal(err)
}
}
func TestWeakMapGetAdderGetIteratorOrder(t *testing.T) {
const SCRIPT = `
let getterCalled = 0;
class M extends WeakMap {
get set() {
getterCalled++;
return null;
}
}
let getIteratorCalled = 0;
let iterable = {};
iterable[Symbol.iterator] = () => {
getIteratorCalled++
return {
next: 1
};
}
let thrown = false;
try {
new M(iterable);
} catch (e) {
if (e instanceof TypeError) {
thrown = true;
} else {
throw e;
}
}
thrown && getterCalled === 1 && getIteratorCalled === 0;
`
testScript(SCRIPT, valueTrue, t)
}