summaryrefslogtreecommitdiffstats
path: root/js/src/tests/js1_8_5/regress/regress-591846.js
blob: 68b1feca3c14577e7602689e10bcb6843a28fc83 (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
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

function check(obj, name, value, readonly) {
    // Start with a non-configurable, writable data property implemented via
    // js::PropertyOp getter and setter.
    var pd = Object.getOwnPropertyDescriptor(obj, name);

    assertEq(pd.configurable, false, "non-configurable " + name);
    assertEq(pd.writable, !readonly, "writable " + name);

    try {
        // Do not allow a transition from js::PropertyOp to writable js::Value
        // data property.
        Object.defineProperty(obj, name, {writable: true});
        assertEq(0, 1);
    } catch (e) {
        assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
    }

    if (!readonly) {
        try {
            // Do not allow the property denoted by name to become a true data
            // property via a descriptor that preserves the native property's
            // writable attribute.
            Object.defineProperty(obj, name, {value: value});
            assertEq(0, 1);
        } catch (e) {
            assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
        }
    }

    try {
        // Do not allow the property to be frozen at some bogus value.
        Object.defineProperty(obj, name, {value: "bogus", writable: false});
        assertEq(0, 1);
    } catch (e) {
        assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
    }

    // Now make name non-writable.
    Object.defineProperty(obj, name, {writable: false})

    // Assert that the right getter result "stuck".
    assertEq(obj[name], value);

    // Test that it is operationally non-writable now.
    obj[name] = "eek!";
    assertEq(obj[name], value);
}

// Reset RegExp.leftContext to the empty string.
/x/.test('x');

var d = Object.getOwnPropertyDescriptor(RegExp, "leftContext");
assertEq(d.set, undefined);
assertEq(typeof d.get, "function");
assertEq(d.enumerable, true);
assertEq(d.configurable, false);
assertEq(d.get.call(RegExp), "");

reportCompare(0, 0, "ok");