CompletePropertyDescriptor.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var hasOwn = require('hasown');
  4. var IsDataDescriptor = require('./IsDataDescriptor');
  5. var IsGenericDescriptor = require('./IsGenericDescriptor');
  6. var isPropertyDescriptor = require('../helpers/records/property-descriptor');
  7. // https://262.ecma-international.org/6.0/#sec-completepropertydescriptor
  8. module.exports = function CompletePropertyDescriptor(Desc) {
  9. if (!isPropertyDescriptor(Desc)) {
  10. throw new $TypeError('Assertion failed: `Desc` must be a Property Descriptor');
  11. }
  12. /* eslint no-param-reassign: 0 */
  13. if (IsGenericDescriptor(Desc) || IsDataDescriptor(Desc)) {
  14. if (!hasOwn(Desc, '[[Value]]')) {
  15. Desc['[[Value]]'] = void 0;
  16. }
  17. if (!hasOwn(Desc, '[[Writable]]')) {
  18. Desc['[[Writable]]'] = false;
  19. }
  20. } else {
  21. if (!hasOwn(Desc, '[[Get]]')) {
  22. Desc['[[Get]]'] = void 0;
  23. }
  24. if (!hasOwn(Desc, '[[Set]]')) {
  25. Desc['[[Set]]'] = void 0;
  26. }
  27. }
  28. if (!hasOwn(Desc, '[[Enumerable]]')) {
  29. Desc['[[Enumerable]]'] = false;
  30. }
  31. if (!hasOwn(Desc, '[[Configurable]]')) {
  32. Desc['[[Configurable]]'] = false;
  33. }
  34. return Desc;
  35. };