15.2.3.6-4-5.js (1487B)
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. Step 6 of [[DefineOwnProperty]] returns if 8 every field of desc also occurs in current and every field in desc has 9 the same value as current. 10 es5id: 15.2.3.6-4-5 11 description: > 12 Object.defineProperty is no-op if current and desc are the same 13 data desc 14 ---*/ 15 16 function sameDataDescriptorValues(d1, d2) { 17 return (d1.value === d2.value && 18 d1.enumerable === d2.enumerable && 19 d1.writable === d2.writable && 20 d1.configurable === d2.configurable); 21 } 22 23 var o = {}; 24 25 // create a data valued property with the following attributes: 26 // value: 101, enumerable: true, writable: true, configurable: true 27 o["foo"] = 101; 28 29 // query for, and save, the desc. A subsequent call to defineProperty 30 // with the same desc should not disturb the property definition. 31 var d1 = Object.getOwnPropertyDescriptor(o, "foo"); 32 33 // now, redefine the property with the same descriptor 34 // the property defintion should not get disturbed. 35 var desc = { 36 value: 101, 37 enumerable: true, 38 writable: true, 39 configurable: true 40 }; 41 Object.defineProperty(o, "foo", desc); 42 43 var d2 = Object.getOwnPropertyDescriptor(o, "foo"); 44 45 assert.sameValue(sameDataDescriptorValues(d1, d2), true, 'sameDataDescriptorValues(d1, d2)'); 46 47 reportCompare(0, 0);