blob: 489f6ececb04e7a86249366460c05339239197fb (
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
|
// Test GETPROP_SUPER with megamorphic variation
const NCLASS = 20;
var g_prop = "prop";
var g_THIS = "THIS";
// Define array of base classes with a data property and a getter property.
let C = [];
for (let i = 0; i < NCLASS; ++i) {
let klass = class {
get THIS() { return this; }
};
klass.prototype.prop = i;
C.push(klass);
}
// Derive class using super property access
class D extends C[0] {
get prop() { return super.prop; }
get elem() { return super[g_prop]; }
get prop_this() { return super.THIS; }
get elem_this() { return super[g_THIS]; }
}
let d = new D();
for (var j = 0; j < 4; ++j) {
for (var i = 0; i < 15; ++i) {
// Change base class by overriding [[HomeObject]].[[Prototype]]
Object.setPrototypeOf(D.prototype, C[j].prototype);
// Check we get property of correct class
assertEq(d.prop, j);
assertEq(d.elem, j);
// Check super getter gets |this| of object not base class
assertEq(d.prop_this, d);
assertEq(d.elem_this, d);
}
}
|