blob: 2f7c410ba3d7fe1b403796f8f4c4fd14cc20cd82 [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 CreateDataProperty = require('./CreateDataProperty');
8var IsPropertyKey = require('./IsPropertyKey');
9var Type = require('./Type');
10
11// // https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow
12
13module.exports = function CreateDataPropertyOrThrow(O, P, V) {
14 if (Type(O) !== 'Object') {
15 throw new $TypeError('Assertion failed: Type(O) is not Object');
16 }
17 if (!IsPropertyKey(P)) {
18 throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
19 }
20 var success = CreateDataProperty(O, P, V);
21 if (!success) {
22 throw new $TypeError('unable to create data property');
23 }
24 return success;
25};