summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/realms/array-ctor.js
blob: b2e0497ae5f74eec89efeec39385a7389d9624d6 (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
function testArrayRealm() {
    var g = newGlobal();
    var A = g.Array;
    for (var i = 0; i < 100; i++) {
        var a;
        a = new A();
        assertEq(isSameCompartment(a, g), true);
        assertEq(Object.getPrototypeOf(a), A.prototype);

        a = new A(i);
        assertEq(isSameCompartment(a, g), true);
        assertEq(Object.getPrototypeOf(a), A.prototype);
    }
}
testArrayRealm();

function testErrorRealm() {
    var g = newGlobal();
    var A = g.Array;
    for (var i = 50; i > -50; i--) {
        var a = null;
        var ex = null;
        try {
            a = new A(i);
        } catch (e) {
            ex = e;
        }
        if (i >= 0) {
            assertEq(Object.getPrototypeOf(a), A.prototype);
        } else {
            assertEq(ex instanceof g.RangeError, true);
        }
    }
}
testErrorRealm();