_set.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _set;
  6. var _definePropertyMjs = _interopRequireDefault(require("./_define_property.js"));
  7. var _superPropBaseMjs = _interopRequireDefault(require("./_super_prop_base.js"));
  8. function _set(target, property, value, receiver, isStrict) {
  9. var s = set(target, property, value, receiver || target);
  10. if (!s && isStrict) {
  11. throw new Error('failed to set property');
  12. }
  13. return value;
  14. }
  15. function _interopRequireDefault(obj) {
  16. return obj && obj.__esModule ? obj : {
  17. default: obj
  18. };
  19. }
  20. function set(target1, property1, value1, receiver1) {
  21. if (typeof Reflect !== "undefined" && Reflect.set) {
  22. set = Reflect.set;
  23. } else {
  24. set = function set(target, property, value, receiver) {
  25. var base = (0, _superPropBaseMjs).default(target, property);
  26. var desc;
  27. if (base) {
  28. desc = Object.getOwnPropertyDescriptor(base, property);
  29. if (desc.set) {
  30. desc.set.call(receiver, value);
  31. return true;
  32. } else if (!desc.writable) {
  33. return false;
  34. }
  35. }
  36. desc = Object.getOwnPropertyDescriptor(receiver, property);
  37. if (desc) {
  38. if (!desc.writable) {
  39. return false;
  40. }
  41. desc.value = value;
  42. Object.defineProperty(receiver, property, desc);
  43. } else {
  44. (0, _definePropertyMjs).default(receiver, property, value);
  45. }
  46. return true;
  47. };
  48. }
  49. return set(target1, property1, value1, receiver1);
  50. }