CreateDataProperty.js 705 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsPropertyKey = require('./IsPropertyKey');
  4. var OrdinaryDefineOwnProperty = require('./OrdinaryDefineOwnProperty');
  5. var Type = require('./Type');
  6. // https://262.ecma-international.org/6.0/#sec-createdataproperty
  7. module.exports = function CreateDataProperty(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 newDesc = {
  15. '[[Configurable]]': true,
  16. '[[Enumerable]]': true,
  17. '[[Value]]': V,
  18. '[[Writable]]': true
  19. };
  20. return OrdinaryDefineOwnProperty(O, P, newDesc);
  21. };