/
exec.js
122 lines (103 loc) 路 4.86 KB
/
exec.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class Foo {
static #x = 1;
static #m = function() { return this.#x; };
static #self = Foo;
static self = Foo;
static getSelf() { return this }
static test() {
const o = { Foo: Foo };
const deep = { very: { o } };
function fn() {
return o;
}
function fnDeep() {
return deep;
}
expect(o?.Foo.#m()).toEqual(1);
expect(o?.Foo.#m().toString).toEqual(1..toString);
expect(o?.Foo.#m().toString()).toEqual('1');
expect(deep?.very.o?.Foo.#m()).toEqual(1);
expect(deep?.very.o?.Foo.#m().toString).toEqual(1..toString);
expect(deep?.very.o?.Foo.#m().toString()).toEqual('1');
expect(o?.Foo.#self.#m()).toEqual(1);
expect(o?.Foo.#self.self.#m()).toEqual(1);
expect(o?.Foo.#self?.self.#m()).toEqual(1);
expect(o?.Foo.#self.self?.self.#m()).toEqual(1);
expect(o?.Foo.#self?.self?.self.#m()).toEqual(1);
expect(o?.Foo.#self.getSelf().#m()).toEqual(1);
expect(o?.Foo.#self.getSelf?.().#m()).toEqual(1);
expect(o?.Foo.#self?.getSelf().#m()).toEqual(1);
expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(1);
expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(1);
expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(1);
expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(1);
expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(1);
expect(fn?.().Foo.#m()).toEqual(1);
expect(fn?.().Foo.#m().toString).toEqual(1..toString);
expect(fn?.().Foo.#m().toString()).toEqual('1');
expect(fnDeep?.().very.o?.Foo.#m()).toEqual(1);
expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(1..toString);
expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual('1');
expect(fn?.().Foo.#self.#m()).toEqual(1);
expect(fn?.().Foo.#self.self.#m()).toEqual(1);
expect(fn?.().Foo.#self?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self.self?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self.getSelf().#m()).toEqual(1);
expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(1);
expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(1);
expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(1);
expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(1);
expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(1);
}
static testNull() {
const o = null;;
const deep = { very: { o } };
const fn = null;
function fnDeep() {
return deep;
}
expect(o?.Foo.#m()).toEqual(undefined);
expect(o?.Foo.#m().toString).toEqual(undefined);
expect(o?.Foo.#m().toString()).toEqual(undefined);
expect(deep?.very.o?.Foo.#m()).toEqual(undefined);
expect(deep?.very.o?.Foo.#m().toString).toEqual(undefined);
expect(deep?.very.o?.Foo.#m().toString()).toEqual(undefined);
expect(o?.Foo.#self.#m()).toEqual(undefined);
expect(o?.Foo.#self.self.#m()).toEqual(undefined);
expect(o?.Foo.#self?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self.self?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self?.self?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self.getSelf().#m()).toEqual(undefined);
expect(o?.Foo.#self.getSelf?.().#m()).toEqual(undefined);
expect(o?.Foo.#self?.getSelf().#m()).toEqual(undefined);
expect(o?.Foo.#self?.getSelf?.().#m()).toEqual(undefined);
expect(o?.Foo.#self.getSelf()?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self?.getSelf()?.self.#m()).toEqual(undefined);
expect(o?.Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#m()).toEqual(undefined);
expect(fn?.().Foo.#m().toString).toEqual(undefined);
expect(fn?.().Foo.#m().toString()).toEqual(undefined);
expect(fnDeep?.().very.o?.Foo.#m()).toEqual(undefined);
expect(fnDeep?.().very.o?.Foo.#m().toString).toEqual(undefined);
expect(fnDeep?.().very.o?.Foo.#m().toString()).toEqual(undefined);
expect(fn?.().Foo.#self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self.self?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.self?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self.getSelf().#m()).toEqual(undefined);
expect(fn?.().Foo.#self.getSelf?.().#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.getSelf().#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.getSelf?.().#m()).toEqual(undefined);
expect(fn?.().Foo.#self.getSelf()?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self.getSelf?.()?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.getSelf()?.self.#m()).toEqual(undefined);
expect(fn?.().Foo.#self?.getSelf?.()?.self.#m()).toEqual(undefined);
}
}
Foo.test();
Foo.testNull();