CreateMethodProperty.js 979 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var DefineOwnProperty = require('../helpers/DefineOwnProperty');
  5. var FromPropertyDescriptor = require('./FromPropertyDescriptor');
  6. var IsDataDescriptor = require('./IsDataDescriptor');
  7. var IsPropertyKey = require('./IsPropertyKey');
  8. var SameValue = require('./SameValue');
  9. var Type = require('./Type');
  10. // https://ecma-international.org/ecma-262/6.0/#sec-createmethodproperty
  11. module.exports = function CreateMethodProperty(O, P, V) {
  12. if (Type(O) !== 'Object') {
  13. throw new $TypeError('Assertion failed: Type(O) is not Object');
  14. }
  15. if (!IsPropertyKey(P)) {
  16. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  17. }
  18. var newDesc = {
  19. '[[Configurable]]': true,
  20. '[[Enumerable]]': false,
  21. '[[Value]]': V,
  22. '[[Writable]]': true
  23. };
  24. return DefineOwnProperty(
  25. IsDataDescriptor,
  26. SameValue,
  27. FromPropertyDescriptor,
  28. O,
  29. P,
  30. newDesc
  31. );
  32. };