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