CompletePropertyDescriptor.js 984 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var has = require('has');
  3. var assertRecord = require('../helpers/assertRecord');
  4. var IsDataDescriptor = require('./IsDataDescriptor');
  5. var IsGenericDescriptor = require('./IsGenericDescriptor');
  6. var Type = require('./Type');
  7. // https://262.ecma-international.org/6.0/#sec-completepropertydescriptor
  8. module.exports = function CompletePropertyDescriptor(Desc) {
  9. /* eslint no-param-reassign: 0 */
  10. assertRecord(Type, 'Property Descriptor', 'Desc', Desc);
  11. if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) {
  12. if (!has(Desc, '[[Value]]')) {
  13. Desc['[[Value]]'] = void 0;
  14. }
  15. if (!has(Desc, '[[Writable]]')) {
  16. Desc['[[Writable]]'] = false;
  17. }
  18. } else {
  19. if (!has(Desc, '[[Get]]')) {
  20. Desc['[[Get]]'] = void 0;
  21. }
  22. if (!has(Desc, '[[Set]]')) {
  23. Desc['[[Set]]'] = void 0;
  24. }
  25. }
  26. if (!has(Desc, '[[Enumerable]]')) {
  27. Desc['[[Enumerable]]'] = false;
  28. }
  29. if (!has(Desc, '[[Configurable]]')) {
  30. Desc['[[Configurable]]'] = false;
  31. }
  32. return Desc;
  33. };