summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Proxy/revoked-get-function-realm-typeerror.js
blob: 8214b3c9a712d507fe8f6b9910ef5cb774e2c1e2 (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
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
var constructors = [
    // 19.1 Object Objects
    {constructor: Object},

    // 19.2 Function Objects
    {constructor: Function},

    // 19.3 Boolean Objects
    {constructor: Boolean},

    // 19.5 Error Objects
    {constructor: Error},

    // 19.5.5 Native Error Types Used in This Standard
    {constructor: EvalError},
    {constructor: RangeError},
    {constructor: ReferenceError},
    {constructor: SyntaxError},
    {constructor: TypeError},
    {constructor: URIError},

    // 20.1 Number Objects
    {constructor: Number},

    // 20.3 Date Objects
    {constructor: Date},

    // 21.1 String Objects
    {constructor: String},

    // 21.2 RegExp (Regular Expression) Objects
    {constructor: RegExp},

    // 22.1 Array Objects
    {constructor: Array},

    // 22.2 TypedArray Objects
    {constructor: Int8Array},

    // 23.1 Map Objects
    {constructor: Map},

    // 23.2 Set Objects
    {constructor: Set},

    // 23.3 WeakMap Objects
    {constructor: WeakMap},

    // 23.4 WeakSet Objects
    {constructor: WeakSet},

    // 24.1 ArrayBuffer Objects
    {constructor: ArrayBuffer},

    // 24.2 SharedArrayBuffer Objects
    ...(typeof SharedArrayBuffer === "function" ? [{constructor: SharedArrayBuffer}] : []),

    // 24.3 DataView Objects
    {constructor: DataView, args: [new ArrayBuffer(0)]},

    // 25.2 GeneratorFunction Objects
    {constructor: function*(){}.constructor},

    // 25.3 AsyncGeneratorFunction Objects
    {constructor: async function*(){}.constructor},

    // 25.6 Promise Objects
    {constructor: Promise, args: [function(){}]},

    // 25.7 AsyncFunction Objects
    {constructor: async function(){}.constructor},

    // 9.2 ECMAScript Function Objects
    {constructor: function(){}},

    // Intl can be disabled at compile-time.
    ...(typeof Intl !== "undefined" ? [
        // 10 Collator Objects
        {constructor: Intl.Collator},

        // 11 NumberFormat Objects
        {constructor: Intl.NumberFormat},

        // 12 DateTimeFormat Objects
        {constructor: Intl.DateTimeFormat},

        // 13 PluralRules Objects
        {constructor: Intl.PluralRules},

        // Intl.RelativeTimeFormat proposal
        {constructor: Intl.RelativeTimeFormat},

        // Intl.Locale is not yet enabled by default.
        ...(Intl.Locale ? [Intl.Locale] : []),
    ] : []),
];

for (let {constructor, args = []} of constructors) {
    let revoked = 0;
    let {proxy, revoke} = Proxy.revocable(function(){}, {
        get(t, pk, r) {
            if (pk === "prototype") {
                revoked++;
                revoke();
                return undefined;
            }
            return Reflect.get(t, pk, r);
        }
    });

    assertThrowsInstanceOf(() => {
        Reflect.construct(constructor, args, proxy);
    }, TypeError);

    assertEq(revoked, 1);
}

if (typeof reportCompare === "function")
    reportCompare(true, true);