Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_8_5 / regress / regress-591846.js
1 /*
2  * Any copyright is dedicated to the Public Domain.
3  * http://creativecommons.org/licenses/publicdomain/
4  */
5
6 function check(obj, name, value, readonly) {
7     // Start with a non-configurable, writable data property implemented via
8     // js::PropertyOp getter and setter.
9     var pd = Object.getOwnPropertyDescriptor(obj, name);
10
11     assertEq(pd.configurable, false, "non-configurable " + name);
12     assertEq(pd.writable, !readonly, "writable " + name);
13
14     try {
15         // Do not allow a transition from js::PropertyOp to writable js::Value
16         // data property.
17         Object.defineProperty(obj, name, {writable: true});
18         assertEq(0, 1);
19     } catch (e) {
20         assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
21     }
22
23     if (!readonly) {
24         try {
25             // Do not allow the property denoted by name to become a true data
26             // property via a descriptor that preserves the native property's
27             // writable attribute.
28             Object.defineProperty(obj, name, {value: value});
29             assertEq(0, 1);
30         } catch (e) {
31             assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
32         }
33     }
34
35     try {
36         // Do not allow the property to be frozen at some bogus value.
37         Object.defineProperty(obj, name, {value: "bogus", writable: false});
38         assertEq(0, 1);
39     } catch (e) {
40         assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'");
41     }
42
43     // Now make name non-writable.
44     Object.defineProperty(obj, name, {writable: false})
45
46     // Assert that the right getter result "stuck".
47     assertEq(obj[name], value);
48
49     // Test that it is operationally non-writable now.
50     obj[name] = "eek!";
51     assertEq(obj[name], value);
52 }
53
54 check(Object, 'caller', null, false);
55 check(Object, 'arguments', null, false);
56
57 // Reset RegExp.leftContext to the empty string.
58 /x/.test('x');
59 check(RegExp, 'leftContext', '', true);
60
61 reportCompare(0, 0, "ok");