set.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var _Reflect$set = require("@babel/runtime-corejs3/core-js/reflect/set");
  2. var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js/object/get-own-property-descriptor");
  3. var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property");
  4. var superPropBase = require("./superPropBase.js");
  5. var defineProperty = require("./defineProperty.js");
  6. function set(target, property, value, receiver) {
  7. if (typeof Reflect !== "undefined" && _Reflect$set) {
  8. set = _Reflect$set;
  9. } else {
  10. set = function set(target, property, value, receiver) {
  11. var base = superPropBase(target, property);
  12. var desc;
  13. if (base) {
  14. desc = _Object$getOwnPropertyDescriptor(base, property);
  15. if (desc.set) {
  16. desc.set.call(receiver, value);
  17. return true;
  18. } else if (!desc.writable) {
  19. return false;
  20. }
  21. }
  22. desc = _Object$getOwnPropertyDescriptor(receiver, property);
  23. if (desc) {
  24. if (!desc.writable) {
  25. return false;
  26. }
  27. desc.value = value;
  28. _Object$defineProperty(receiver, property, desc);
  29. } else {
  30. defineProperty(receiver, property, value);
  31. }
  32. return true;
  33. };
  34. }
  35. return set(target, property, value, receiver);
  36. }
  37. function _set(target, property, value, receiver, isStrict) {
  38. var s = set(target, property, value, receiver || target);
  39. if (!s && isStrict) {
  40. throw new Error('failed to set property');
  41. }
  42. return value;
  43. }
  44. module.exports = _set;
  45. module.exports["default"] = module.exports, module.exports.__esModule = true;