Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 3 | var $TypeError = require('es-errors/type'); |
Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 4 | |
| 5 | var GetV = require('./GetV'); |
| 6 | var IsCallable = require('./IsCallable'); |
| 7 | var IsPropertyKey = require('./IsPropertyKey'); |
| 8 | |
Nikolay Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 9 | var inspect = require('object-inspect'); |
| 10 | |
| 11 | // https://262.ecma-international.org/6.0/#sec-getmethod |
Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 12 | |
| 13 | module.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 Vitkov | d76576c | 2024-12-02 14:10:15 | [diff] [blame] | 29 | throw new $TypeError(inspect(P) + ' is not a function: ' + inspect(func)); |
Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // 7.3.9.6 |
| 33 | return func; |
| 34 | }; |