15.2.3.6-4-16.js (1287B)
1 // Copyright (c) 2012 Ecma International. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: | 6 Step 4 of defineProperty calls the [[DefineOwnProperty]] internal method 7 of O to define the property. For non-configurable properties, step 10.a.i 8 of [[DefineOwnProperty]] rejects if relaxing the [[Writable]] attribute. 9 es5id: 15.2.3.6-4-16 10 description: > 11 Object.defineProperty throws TypeError when relaxing [[Writable]] 12 on non-configurable data properties 13 ---*/ 14 15 var o = {}; 16 17 // create a data valued property; all other attributes default to false. 18 var d1 = { 19 value: 101 20 }; 21 Object.defineProperty(o, "foo", d1); 22 23 // now, relaxing [[Writable]] on "foo" should fail, since both 24 // [[Configurable]] and [[Writable]] on the original property will be false. 25 var desc = { 26 value: 101, 27 writable: true 28 }; 29 assert.throws(TypeError, function() { 30 Object.defineProperty(o, "foo", desc); 31 }); 32 // the property should remain unchanged. 33 var d2 = Object.getOwnPropertyDescriptor(o, "foo"); 34 assert.sameValue(d2.value, 101, 'd2.value'); 35 assert.sameValue(d2.writable, false, 'd2.writable'); 36 assert.sameValue(d2.enumerable, false, 'd2.enumerable'); 37 assert.sameValue(d2.configurable, false, 'd2.configurable'); 38 39 reportCompare(0, 0);