Invoke.js 662 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var Call = require('./Call');
  4. var IsArray = require('./IsArray');
  5. var GetV = require('./GetV');
  6. var IsPropertyKey = require('./IsPropertyKey');
  7. // https://262.ecma-international.org/6.0/#sec-invoke
  8. module.exports = function Invoke(O, P) {
  9. if (!IsPropertyKey(P)) {
  10. throw new $TypeError('Assertion failed: P must be a Property Key');
  11. }
  12. var argumentsList = arguments.length > 2 ? arguments[2] : [];
  13. if (!IsArray(argumentsList)) {
  14. throw new $TypeError('Assertion failed: optional `argumentsList`, if provided, must be a List');
  15. }
  16. var func = GetV(O, P);
  17. return Call(func, O, argumentsList);
  18. };