CompletePropertyDescriptor.js 1008 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var hasOwn = require('hasown');
  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 (!hasOwn(Desc, '[[Value]]')) {
  13. Desc['[[Value]]'] = void 0;
  14. }
  15. if (!hasOwn(Desc, '[[Writable]]')) {
  16. Desc['[[Writable]]'] = false;
  17. }
  18. } else {
  19. if (!hasOwn(Desc, '[[Get]]')) {
  20. Desc['[[Get]]'] = void 0;
  21. }
  22. if (!hasOwn(Desc, '[[Set]]')) {
  23. Desc['[[Set]]'] = void 0;
  24. }
  25. }
  26. if (!hasOwn(Desc, '[[Enumerable]]')) {
  27. Desc['[[Enumerable]]'] = false;
  28. }
  29. if (!hasOwn(Desc, '[[Configurable]]')) {
  30. Desc['[[Configurable]]'] = false;
  31. }
  32. return Desc;
  33. };