property-descriptor.js 871 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var hasOwn = require('hasown');
  4. var allowed = {
  5. __proto__: null,
  6. '[[Configurable]]': true,
  7. '[[Enumerable]]': true,
  8. '[[Get]]': true,
  9. '[[Set]]': true,
  10. '[[Value]]': true,
  11. '[[Writable]]': true
  12. };
  13. // https://262.ecma-international.org/6.0/#sec-property-descriptor-specification-type
  14. module.exports = function isPropertyDescriptor(Desc) {
  15. if (!Desc || typeof Desc !== 'object') {
  16. return false;
  17. }
  18. for (var key in Desc) { // eslint-disable-line
  19. if (hasOwn(Desc, key) && !allowed[key]) {
  20. return false;
  21. }
  22. }
  23. var isData = hasOwn(Desc, '[[Value]]') || hasOwn(Desc, '[[Writable]]');
  24. var IsAccessor = hasOwn(Desc, '[[Get]]') || hasOwn(Desc, '[[Set]]');
  25. if (isData && IsAccessor) {
  26. throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
  27. }
  28. return true;
  29. };