summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/classPrototype.js
blob: 0d2296037ccfd2259dfba0fa93523ca91622e54e (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
63
64
65
// The prototype of a class is a non-writable, non-configurable, non-enumerable data property.
class a { constructor() { } }
let b = class { constructor() { } };
for (let test of [a,b]) {
    var protoDesc = Object.getOwnPropertyDescriptor(test, "prototype");
    assertEq(protoDesc.writable, false);
    assertEq(protoDesc.configurable, false);
    assertEq(protoDesc.enumerable, false);

    var prototype = protoDesc.value;
    assertEq(typeof prototype, "object");
    assertEq(Object.getPrototypeOf(prototype), Object.prototype);
    assertEq(Object.isExtensible(prototype), true);

    var desiredPrototype = {};
    Object.defineProperty(desiredPrototype, "constructor", { writable: true,
                                                            configurable: true,
                                                            enumerable: false,
                                                            value: test });
    assertDeepEq(prototype, desiredPrototype);
}

// As such, it should by a TypeError to try and overwrite "prototype" with a
// static member. The only way to try is with a computed property name; the rest
// are early errors.
assertThrowsInstanceOf(() => eval(`
                                  class a {
                                    constructor() { };
                                    static ["prototype"]() { }
                                  }
                                  `), TypeError);
assertThrowsInstanceOf(() => eval(`
                                  class a {
                                    constructor() { };
                                    static get ["prototype"]() { }
                                  }
                                  `), TypeError);
assertThrowsInstanceOf(() => eval(`
                                  class a {
                                    constructor() { };
                                    static set ["prototype"](x) { }
                                  }
                                  `), TypeError);

assertThrowsInstanceOf(() => eval(`(
                                  class a {
                                    constructor() { };
                                    static ["prototype"]() { }
                                  }
                                  )`), TypeError);
assertThrowsInstanceOf(() => eval(`(
                                  class a {
                                    constructor() { };
                                    static get ["prototype"]() { }
                                  }
                                  )`), TypeError);
assertThrowsInstanceOf(() => eval(`(
                                  class a {
                                    constructor() { };
                                    static set ["prototype"](x) { }
                                  }
                                  )`), TypeError);

if (typeof reportCompare === "function")
    reportCompare(0, 0, "OK");