DeletePropertyOrThrow.js 699 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  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-deletepropertyorthrow
  7. module.exports = function DeletePropertyOrThrow(O, P) {
  8. if (Type(O) !== 'Object') {
  9. throw new $TypeError('Assertion failed: Type(O) is not Object');
  10. }
  11. if (!IsPropertyKey(P)) {
  12. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  13. }
  14. // eslint-disable-next-line no-param-reassign
  15. var success = delete O[P];
  16. if (!success) {
  17. throw new $TypeError('Attempt to delete property failed.');
  18. }
  19. return success;
  20. };