27b461aa2feed976a54d9e74b9dd5245b5eeaf021b3d5ba96df7e36f27fefa923a0173975b490da69bc818b65c55170c7a61d8049a6d4fa64d896270bd0def 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var gOPD = require('gopd');
  4. var isObject = require('../helpers/isObject');
  5. var isPropertyKey = require('../helpers/isPropertyKey');
  6. var CreateDataPropertyOrThrow = require('./CreateDataPropertyOrThrow');
  7. var SameValue = require('./SameValue');
  8. var Set = require('./Set');
  9. // https://262.ecma-international.org/16.0/#sec-SetterThatIgnoresPrototypeProperties
  10. module.exports = function SetterThatIgnoresPrototypeProperties(thisValue, home, p, v) {
  11. if (!isObject(home)) {
  12. throw new $TypeError('Assertion failed: `home` must be an object');
  13. }
  14. if (!isPropertyKey(p)) {
  15. throw new $TypeError('Assertion failed: `p` must be a Property Key');
  16. }
  17. if (!isObject(thisValue)) { // step 1
  18. throw new $TypeError('Assertion failed: `thisValue` must be an Object'); // step 1.a
  19. }
  20. if (SameValue(thisValue, home)) { // step 2
  21. throw new $TypeError('Throwing here emulates assignment to a non-writable data property on the `home` object in strict mode code'); // step 2.b
  22. }
  23. var desc = gOPD(thisValue, p); // step 3
  24. if (typeof desc === 'undefined') { // step 4
  25. CreateDataPropertyOrThrow(thisValue, p, v); // step 4.a
  26. } else { // step 5
  27. Set(thisValue, p, v, true); // step 5.a
  28. }
  29. };