FromPropertyDescriptor.js 797 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var assertRecord = require('../helpers/assertRecord');
  3. var Type = require('./Type');
  4. // https://ecma-international.org/ecma-262/6.0/#sec-frompropertydescriptor
  5. module.exports = function FromPropertyDescriptor(Desc) {
  6. if (typeof Desc === 'undefined') {
  7. return Desc;
  8. }
  9. assertRecord(Type, 'Property Descriptor', 'Desc', Desc);
  10. var obj = {};
  11. if ('[[Value]]' in Desc) {
  12. obj.value = Desc['[[Value]]'];
  13. }
  14. if ('[[Writable]]' in Desc) {
  15. obj.writable = Desc['[[Writable]]'];
  16. }
  17. if ('[[Get]]' in Desc) {
  18. obj.get = Desc['[[Get]]'];
  19. }
  20. if ('[[Set]]' in Desc) {
  21. obj.set = Desc['[[Set]]'];
  22. }
  23. if ('[[Enumerable]]' in Desc) {
  24. obj.enumerable = Desc['[[Enumerable]]'];
  25. }
  26. if ('[[Configurable]]' in Desc) {
  27. obj.configurable = Desc['[[Configurable]]'];
  28. }
  29. return obj;
  30. };