Invoke.js 715 B

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