/
exec.js
48 lines (37 loc) 路 1.3 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
class Foo {
static #x = 1;
static self = Foo;
static #m = function() { return this.#x; };
static getSelf() { return Foo }
test() {
const o = { Foo: Foo };
const fn = function () {
return o;
};
expect((Foo?.#m)()).toEqual(1);
expect((Foo?.#m)().toString).toEqual(1..toString);
expect((Foo?.#m)().toString()).toEqual('1');
expect((o?.Foo.#m)()).toEqual(1);
expect((o?.Foo.#m)().toString).toEqual(1..toString);
expect((o?.Foo.#m)().toString()).toEqual('1');
expect((((o.Foo?.self.getSelf)())?.#m)()).toEqual(1);
expect((((o.Foo.self?.getSelf)())?.#m)()).toEqual(1);
expect((((fn()?.Foo?.self.getSelf)())?.#m)()).toEqual(1);
expect((((fn?.().Foo.self?.getSelf)())?.#m)()).toEqual(1);
}
testNull() {
const o = null;
const fn = function () {
return { o };
}
expect(() => { (o?.Foo.#m)() }).toThrow();
expect(() => { (o?.Foo.#m)().toString }).toThrow();
expect(() => { (o?.Foo.#m)().toString() }).toThrow();
expect(() => { (((o.Foo?.self.getSelf)())?.#m)() }).toThrow();
expect(() => { (((o.Foo.self?.getSelf)())?.#m)() }).toThrow();
expect(() => (((fn()?.Foo?.self.getSelf)())?.#m)()).toThrow();
expect(() => (((fn?.().Foo.self?.getSelf)())?.#m)()).toThrow();
}
}
(new Foo).test();
(new Foo).testNull();