isPropertyDescriptor.js 721 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var has = require('has');
  4. var $TypeError = GetIntrinsic('%TypeError%');
  5. module.exports = function IsPropertyDescriptor(ES, Desc) {
  6. if (ES.Type(Desc) !== 'Object') {
  7. return false;
  8. }
  9. var allowed = {
  10. '[[Configurable]]': true,
  11. '[[Enumerable]]': true,
  12. '[[Get]]': true,
  13. '[[Set]]': true,
  14. '[[Value]]': true,
  15. '[[Writable]]': true
  16. };
  17. for (var key in Desc) { // eslint-disable-line no-restricted-syntax
  18. if (has(Desc, key) && !allowed[key]) {
  19. return false;
  20. }
  21. }
  22. if (ES.IsDataDescriptor(Desc) && ES.IsAccessorDescriptor(Desc)) {
  23. throw new $TypeError('Property Descriptors may not be both accessor and data descriptors');
  24. }
  25. return true;
  26. };