es.reflect.define-property.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. var $ = require('../internals/export');
  2. var DESCRIPTORS = require('../internals/descriptors');
  3. var anObject = require('../internals/an-object');
  4. var toPrimitive = require('../internals/to-primitive');
  5. var definePropertyModule = require('../internals/object-define-property');
  6. var fails = require('../internals/fails');
  7. // MS Edge has broken Reflect.defineProperty - throwing instead of returning false
  8. var ERROR_INSTEAD_OF_FALSE = fails(function () {
  9. // eslint-disable-next-line no-undef
  10. Reflect.defineProperty(definePropertyModule.f({}, 1, { value: 1 }), 1, { value: 2 });
  11. });
  12. // `Reflect.defineProperty` method
  13. // https://tc39.github.io/ecma262/#sec-reflect.defineproperty
  14. $({ target: 'Reflect', stat: true, forced: ERROR_INSTEAD_OF_FALSE, sham: !DESCRIPTORS }, {
  15. defineProperty: function defineProperty(target, propertyKey, attributes) {
  16. anObject(target);
  17. var key = toPrimitive(propertyKey, true);
  18. anObject(attributes);
  19. try {
  20. definePropertyModule.f(target, key, attributes);
  21. return true;
  22. } catch (error) {
  23. return false;
  24. }
  25. }
  26. });