| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | var GetIntrinsic = require('get-intrinsic'); |
| 4 | |
| 5 | var $TypeError = GetIntrinsic('%TypeError%'); |
| 6 | |
| 7 | var Call = require('./Call'); |
| 8 | var IsArray = require('./IsArray'); |
| 9 | var GetV = require('./GetV'); |
| 10 | var IsPropertyKey = require('./IsPropertyKey'); |
| 11 | |
| 12 | // https://ecma-international.org/ecma-262/6.0/#sec-invoke |
| 13 | |
| 14 | module.exports = function Invoke(O, P) { |
| 15 | if (!IsPropertyKey(P)) { |
| 16 | throw new $TypeError('Assertion failed: P must be a Property Key'); |
| 17 | } |
| 18 | var argumentsList = arguments.length > 2 ? arguments[2] : []; |
| 19 | if (!IsArray(argumentsList)) { |
| 20 | throw new $TypeError('Assertion failed: optional `argumentsList`, if provided, must be a List'); |
| 21 | } |
| 22 | var func = GetV(O, P); |
| 23 | return Call(func, O, argumentsList); |
| 24 | }; |