summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/class/throwOnCallConstructor.js
blob: 2bde725702805bdc81add24bf213e72d9c6f75db (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
// Count constructor calls
var cnt = 0;
class Base { constructor() { ++cnt; } }

// Force |JSFunction->hasScript()|
new Base();
assertEq(cnt, 1);

// Calling a ClassConstructor must throw
(function() {
    function f() { Base(); }
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Spread-calling a ClassConstructor must throw
(function() {
    function f() { Base(...[]); }
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Function.prototype.call must throw on ClassConstructor
(function() {
    function f() { Base.call(null); }
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Function.prototype.apply must throw on ClassConstructor
(function() {
    function f() { Base.apply(null, []); }
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Getter must throw if it is a ClassConstructor
(function() {
    var o = {};
    Object.defineProperty(o, "prop", { get: Base });
    function f() { o.prop };
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Setter must throw if it is a ClassConstructor
(function() {
    var o = {};
    Object.defineProperty(o, "prop", { set: Base });
    function f() { o.prop = 1 };
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Proxy apply must throw if it is a ClassConstructor
(function() {
    var o = new Proxy(function() { }, { apply: Base });
    function f() { o() };
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();

// Proxy get must throw if it is a ClassConstructor
(function() {
    var o = new Proxy({}, { get: Base });
    function f() { o.x }
    try { f() } catch (e) {}
    try { f() } catch (e) {}
    assertEq(cnt, 1);
})();