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