You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

4 years ago
  1. import superPropBase from "./superPropBase";
  2. import defineProperty from "./defineProperty";
  3. function set(target, property, value, receiver) {
  4. if (typeof Reflect !== "undefined" && Reflect.set) {
  5. set = Reflect.set;
  6. } else {
  7. set = function set(target, property, value, receiver) {
  8. var base = superPropBase(target, property);
  9. var desc;
  10. if (base) {
  11. desc = Object.getOwnPropertyDescriptor(base, property);
  12. if (desc.set) {
  13. desc.set.call(receiver, value);
  14. return true;
  15. } else if (!desc.writable) {
  16. return false;
  17. }
  18. }
  19. desc = Object.getOwnPropertyDescriptor(receiver, property);
  20. if (desc) {
  21. if (!desc.writable) {
  22. return false;
  23. }
  24. desc.value = value;
  25. Object.defineProperty(receiver, property, desc);
  26. } else {
  27. defineProperty(receiver, property, value);
  28. }
  29. return true;
  30. };
  31. }
  32. return set(target, property, value, receiver);
  33. }
  34. export default function _set(target, property, value, receiver, isStrict) {
  35. var s = set(target, property, value, receiver || target);
  36. if (!s && isStrict) {
  37. throw new Error('failed to set property');
  38. }
  39. return value;
  40. }