1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
6 |
|
|
|
7 |
|
|
var GetV = require('./GetV');
|
8 |
|
|
var IsCallable = require('./IsCallable');
|
9 |
|
|
var 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 |
|
|
|
21 |
|
|
module.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 |
|
|
};
|