CreateMethodProperty.js 926 B

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