15.2.3.6-4-17.js (1291B)
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.ii.1 8 of [[DefineOwnProperty]] rejects changing the value of non-writable properties. 9 es5id: 15.2.3.6-4-17 10 description: > 11 Object.defineProperty throws TypeError when changing value of 12 non-writable 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, trying to change the value of "foo" should fail, since both 24 // [[Configurable]] and [[Writable]] on the original property will be false. 25 var desc = { 26 value: 102 27 }; 28 assert.throws(TypeError, function() { 29 Object.defineProperty(o, "foo", desc); 30 }); 31 // the property should remain unchanged. 32 var d2 = Object.getOwnPropertyDescriptor(o, "foo"); 33 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);