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.

Set.js 811B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. var GetIntrinsic = require('../GetIntrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var IsPropertyKey = require('./IsPropertyKey');
  5. var Type = require('./Type');
  6. // https://ecma-international.org/ecma-262/6.0/#sec-set-o-p-v-throw
  7. module.exports = function Set(O, P, V, Throw) {
  8. if (Type(O) !== 'Object') {
  9. throw new $TypeError('Assertion failed: `O` must be an Object');
  10. }
  11. if (!IsPropertyKey(P)) {
  12. throw new $TypeError('Assertion failed: `P` must be a Property Key');
  13. }
  14. if (Type(Throw) !== 'Boolean') {
  15. throw new $TypeError('Assertion failed: `Throw` must be a Boolean');
  16. }
  17. if (Throw) {
  18. O[P] = V; // eslint-disable-line no-param-reassign
  19. return true;
  20. } else {
  21. try {
  22. O[P] = V; // eslint-disable-line no-param-reassign
  23. } catch (e) {
  24. return false;
  25. }
  26. }
  27. };