blob: 775d3fb95bff000929523514a9c3c6dc0fac98ce [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 GetV = require('./GetV');
8var IsCallable = require('./IsCallable');
9var IsPropertyKey = require('./IsPropertyKey');
10
11/**
12 * 7.3.9 - https://ecma-international.org/ecma-262/6.0/#sec-getmethod
13 * 1. Assert: IsPropertyKey(P) is true.
14 * 2. Let func be GetV(O, P).
15 * 3. ReturnIfAbrupt(func).
16 * 4. If func is either undefined or null, return undefined.
17 * 5. If IsCallable(func) is false, throw a TypeError exception.
18 * 6. Return func.
19 */
20
21module.exports = function GetMethod(O, P) {
22 // 7.3.9.1
23 if (!IsPropertyKey(P)) {
24 throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
25 }
26
27 // 7.3.9.2
28 var func = GetV(O, P);
29
30 // 7.3.9.4
31 if (func == null) {
32 return void 0;
33 }
34
35 // 7.3.9.5
36 if (!IsCallable(func)) {
37 throw new $TypeError(P + 'is not a function');
38 }
39
40 // 7.3.9.6
41 return func;
42};