blob: 30d5e57c7b5488a0138517751d714dc1fd4844c4 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = GetIntrinsic('%TypeError%');
6
7var IsPropertyKey = require('./IsPropertyKey');
8var Type = require('./Type');
9
10// https://ecma-international.org/ecma-262/6.0/#sec-deletepropertyorthrow
11
12module.exports = function DeletePropertyOrThrow(O, P) {
13 if (Type(O) !== 'Object') {
14 throw new $TypeError('Assertion failed: Type(O) is not Object');
15 }
16
17 if (!IsPropertyKey(P)) {
18 throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
19 }
20
21 // eslint-disable-next-line no-param-reassign
22 var success = delete O[P];
23 if (!success) {
24 throw new $TypeError('Attempt to delete property failed.');
25 }
26 return success;
27};