tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

verifyProperty-restore-accessor-symbol.js (957B)


      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 features: [Symbol]
      9 ---*/
     10 
     11 var obj;
     12 var prop = Symbol(1);
     13 var desc = { enumerable: true, configurable: true, get() { return 42; }, set() {} };
     14 
     15 obj = {};
     16 Object.defineProperty(obj, prop, desc);
     17 
     18 verifyProperty(obj, prop, desc);
     19 
     20 assert.sameValue(
     21  Object.prototype.hasOwnProperty.call(obj, prop),
     22  false
     23 );
     24 
     25 obj = {};
     26 Object.defineProperty(obj, prop, desc);
     27 
     28 verifyProperty(obj, prop, desc, { restore: true });
     29 
     30 assert.sameValue(
     31  Object.prototype.hasOwnProperty.call(obj, prop),
     32  true
     33 );
     34 assert.sameValue(obj[prop], 42);
     35 assert.sameValue(
     36  Object.getOwnPropertyDescriptor(obj, prop).get,
     37  desc.get
     38 );
     39 
     40 assert.sameValue(
     41  Object.getOwnPropertyDescriptor(obj, prop).set,
     42  desc.set
     43 );
     44 
     45 reportCompare(0, 0);