defineProperty.js 683 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var GetIntrinsic = require('../../GetIntrinsic');
  3. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  4. if ($defineProperty) {
  5. try {
  6. $defineProperty({}, 'a', { value: 1 });
  7. } catch (e) {
  8. // IE 8 has a broken defineProperty
  9. $defineProperty = null;
  10. }
  11. }
  12. module.exports = function defineProperty(O, P, Desc) {
  13. if ($defineProperty) {
  14. return $defineProperty(O, P, Desc);
  15. }
  16. if ((Desc.enumerable && Desc.configurable && Desc.writable) || !(P in O)) {
  17. O[P] = Desc.value; // eslint-disable-line no-param-reassign
  18. return O;
  19. }
  20. throw new SyntaxError('helper does not yet support this configuration');
  21. };
  22. module.exports.oDP = $defineProperty;