CreateDataPropertyOrThrow.js 734 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var CreateDataProperty = require('./CreateDataProperty');
  5. var IsPropertyKey = require('./IsPropertyKey');
  6. var Type = require('./Type');
  7. // // https://ecma-international.org/ecma-262/6.0/#sec-createdatapropertyorthrow
  8. module.exports = function CreateDataPropertyOrThrow(O, P, V) {
  9. if (Type(O) !== 'Object') {
  10. throw new $TypeError('Assertion failed: Type(O) is not Object');
  11. }
  12. if (!IsPropertyKey(P)) {
  13. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  14. }
  15. var success = CreateDataProperty(O, P, V);
  16. if (!success) {
  17. throw new $TypeError('unable to create data property');
  18. }
  19. return success;
  20. };