CreateDataProperty.js 753 B

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