DeletePropertyOrThrow.js 646 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsPropertyKey = require('./IsPropertyKey');
  4. var Type = require('./Type');
  5. // https://262.ecma-international.org/6.0/#sec-deletepropertyorthrow
  6. module.exports = function DeletePropertyOrThrow(O, P) {
  7. if (Type(O) !== 'Object') {
  8. throw new $TypeError('Assertion failed: Type(O) is not Object');
  9. }
  10. if (!IsPropertyKey(P)) {
  11. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  12. }
  13. // eslint-disable-next-line no-param-reassign
  14. var success = delete O[P];
  15. if (!success) {
  16. throw new $TypeError('Attempt to delete property failed.');
  17. }
  18. return success;
  19. };