blob: 1c2ee9ef7020a885e69115c29bca6d6bb3759973 [file] [log] [blame]
Tim van der Lippefdbd42e2020-04-07 14:14:361'use strict';
2
Nikolay Vitkovd76576c2024-12-02 14:10:153var $TypeError = require('es-errors/type');
Tim van der Lippefdbd42e2020-04-07 14:14:364
5var GetV = require('./GetV');
6var IsCallable = require('./IsCallable');
7var IsPropertyKey = require('./IsPropertyKey');
8
Nikolay Vitkovd76576c2024-12-02 14:10:159var inspect = require('object-inspect');
10
11// https://262.ecma-international.org/6.0/#sec-getmethod
Tim van der Lippefdbd42e2020-04-07 14:14:3612
13module.exports = function GetMethod(O, P) {
14 // 7.3.9.1
15 if (!IsPropertyKey(P)) {
16 throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
17 }
18
19 // 7.3.9.2
20 var func = GetV(O, P);
21
22 // 7.3.9.4
23 if (func == null) {
24 return void 0;
25 }
26
27 // 7.3.9.5
28 if (!IsCallable(func)) {
Nikolay Vitkovd76576c2024-12-02 14:10:1529 throw new $TypeError(inspect(P) + ' is not a function: ' + inspect(func));
Tim van der Lippefdbd42e2020-04-07 14:14:3630 }
31
32 // 7.3.9.6
33 return func;
34};