set.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var superPropBase = require("./superPropBase.js");
  2. var defineProperty = require("./defineProperty.js");
  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. function _set(target, property, value, receiver, isStrict) {
  35. var s = set(target, property, value, receiver || target);
  36. if (!s && isStrict) {
  37. throw new TypeError('failed to set property');
  38. }
  39. return value;
  40. }
  41. module.exports = _set, module.exports.__esModule = true, module.exports["default"] = module.exports;