michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: function check(obj, name, value, readonly) { michael@0: // Start with a non-configurable, writable data property implemented via michael@0: // js::PropertyOp getter and setter. michael@0: var pd = Object.getOwnPropertyDescriptor(obj, name); michael@0: michael@0: assertEq(pd.configurable, false, "non-configurable " + name); michael@0: assertEq(pd.writable, !readonly, "writable " + name); michael@0: michael@0: try { michael@0: // Do not allow a transition from js::PropertyOp to writable js::Value michael@0: // data property. michael@0: Object.defineProperty(obj, name, {writable: true}); michael@0: assertEq(0, 1); michael@0: } catch (e) { michael@0: assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'"); michael@0: } michael@0: michael@0: if (!readonly) { michael@0: try { michael@0: // Do not allow the property denoted by name to become a true data michael@0: // property via a descriptor that preserves the native property's michael@0: // writable attribute. michael@0: Object.defineProperty(obj, name, {value: value}); michael@0: assertEq(0, 1); michael@0: } catch (e) { michael@0: assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'"); michael@0: } michael@0: } michael@0: michael@0: try { michael@0: // Do not allow the property to be frozen at some bogus value. michael@0: Object.defineProperty(obj, name, {value: "bogus", writable: false}); michael@0: assertEq(0, 1); michael@0: } catch (e) { michael@0: assertEq('' + e, "TypeError: can't redefine non-configurable property '" + name + "'"); michael@0: } michael@0: michael@0: // Now make name non-writable. michael@0: Object.defineProperty(obj, name, {writable: false}) michael@0: michael@0: // Assert that the right getter result "stuck". michael@0: assertEq(obj[name], value); michael@0: michael@0: // Test that it is operationally non-writable now. michael@0: obj[name] = "eek!"; michael@0: assertEq(obj[name], value); michael@0: } michael@0: michael@0: check(Object, 'caller', null, false); michael@0: check(Object, 'arguments', null, false); michael@0: michael@0: // Reset RegExp.leftContext to the empty string. michael@0: /x/.test('x'); michael@0: michael@0: var d = Object.getOwnPropertyDescriptor(RegExp, "leftContext"); michael@0: assertEq(d.set, undefined); michael@0: assertEq(typeof d.get, "function"); michael@0: assertEq(d.enumerable, true); michael@0: assertEq(d.configurable, false); michael@0: assertEq(d.get.call(RegExp), ""); michael@0: michael@0: reportCompare(0, 0, "ok");