CreateDataPropertyOrThrow.js 681 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var CreateDataProperty = require('./CreateDataProperty');
  4. var IsPropertyKey = require('./IsPropertyKey');
  5. var Type = require('./Type');
  6. // // https://262.ecma-international.org/6.0/#sec-createdatapropertyorthrow
  7. module.exports = function CreateDataPropertyOrThrow(O, P, V) {
  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. var success = CreateDataProperty(O, P, V);
  15. if (!success) {
  16. throw new $TypeError('unable to create data property');
  17. }
  18. return success;
  19. };