15.2.3.6-4-13.js (1223B)
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 9a of 8 [[DefineOwnProperty]] rejects changing the kind of a property. 9 es5id: 15.2.3.6-4-13 10 description: > 11 Object.defineProperty throws TypeError when changing 12 non-configurable accessor properties to data properties 13 ---*/ 14 15 var o = {}; 16 17 // create an accessor property; all other attributes default to false. 18 19 // dummy getter 20 var getter = function() { 21 return 1; 22 } 23 var d1 = { 24 get: getter, 25 configurable: false 26 }; 27 Object.defineProperty(o, "foo", d1); 28 29 // changing "foo" to be a data property should fail, since [[Configurable]] 30 // on the original property will be false. 31 var desc = { 32 value: 101 33 }; 34 assert.throws(TypeError, function() { 35 Object.defineProperty(o, "foo", desc); 36 }); 37 // the property should remain an accessor property. 38 var d2 = Object.getOwnPropertyDescriptor(o, "foo"); 39 assert.sameValue(d2.get, getter, 'd2.get'); 40 assert.sameValue(d2.configurable, false, 'd2.configurable'); 41 42 reportCompare(0, 0);