blob: b3e67d6cd6fbf97e67252ae940d2c7dfe9bfb8c3 (
plain)
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
|
// Ensure private fields are stamped in order and that
// we can successfully partially initialize objects.
class Base {
constructor(o) {
return o;
}
}
let constructorThrow = false;
function maybeThrow() {
if (constructorThrow) {
throw 'fail'
}
return 'sometimes'
}
class A extends Base {
constructor(o) {
super(o);
constructorThrow = !constructorThrow;
}
#x = 'always';
#y = maybeThrow();
static gx(o) {
return o.#x;
}
static gy(o) {
return o.#y;
}
};
var obj1 = {};
var obj2 = {};
new A(obj1);
var threw = true;
try {
new A(obj2);
threw = false;
} catch (e) {
assertEq(e, 'fail');
}
assertEq(threw, true);
A.gx(obj1)
A.gx(obj2); // Both objects get x;
A.gy(obj1); // obj1 gets y
try {
A.gy(obj2); // shouldn't have x.
threw = false;
} catch (e) {
assertEq(e instanceof TypeError, true);
}
assertEq(threw, true);
|