object-define-property.js 805 B

1234567891011121314151617181920
  1. var DESCRIPTORS = require('../internals/descriptors');
  2. var IE8_DOM_DEFINE = require('../internals/ie8-dom-define');
  3. var anObject = require('../internals/an-object');
  4. var toPrimitive = require('../internals/to-primitive');
  5. var nativeDefineProperty = Object.defineProperty;
  6. // `Object.defineProperty` method
  7. // https://tc39.github.io/ecma262/#sec-object.defineproperty
  8. exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
  9. anObject(O);
  10. P = toPrimitive(P, true);
  11. anObject(Attributes);
  12. if (IE8_DOM_DEFINE) try {
  13. return nativeDefineProperty(O, P, Attributes);
  14. } catch (error) { /* empty */ }
  15. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  16. if ('value' in Attributes) O[P] = Attributes.value;
  17. return O;
  18. };