set.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import _Reflect$set from "@babel/runtime-corejs3/core-js/reflect/set";
  2. import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js/object/get-own-property-descriptor";
  3. import _Object$defineProperty from "@babel/runtime-corejs3/core-js/object/define-property";
  4. import superPropBase from "./superPropBase.js";
  5. import defineProperty from "./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. export default 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. }