verifyProperty-restore-accessor.js (935B)
1 // Copyright (C) 2017 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 description: > 6 verifyProperty allows restoring the original accessor descriptor 7 includes: [propertyHelper.js] 8 ---*/ 9 10 var obj; 11 var prop = "prop"; 12 var desc = { enumerable: true, configurable: true, get() { return 42; }, set() {} }; 13 14 obj = {}; 15 Object.defineProperty(obj, prop, desc); 16 17 verifyProperty(obj, prop, desc); 18 19 assert.sameValue( 20 Object.prototype.hasOwnProperty.call(obj, prop), 21 false 22 ); 23 24 obj = {}; 25 Object.defineProperty(obj, prop, desc); 26 27 verifyProperty(obj, prop, desc, { restore: true }); 28 29 assert.sameValue( 30 Object.prototype.hasOwnProperty.call(obj, prop), 31 true 32 ); 33 assert.sameValue(obj[prop], 42); 34 assert.sameValue( 35 Object.getOwnPropertyDescriptor(obj, prop).get, 36 desc.get 37 ); 38 39 assert.sameValue( 40 Object.getOwnPropertyDescriptor(obj, prop).set, 41 desc.set 42 ); 43 44 reportCompare(0, 0);