GetMethod.js 728 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var GetV = require('./GetV');
  5. var IsCallable = require('./IsCallable');
  6. var IsPropertyKey = require('./IsPropertyKey');
  7. var inspect = require('object-inspect');
  8. // https://262.ecma-international.org/6.0/#sec-getmethod
  9. module.exports = function GetMethod(O, P) {
  10. // 7.3.9.1
  11. if (!IsPropertyKey(P)) {
  12. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  13. }
  14. // 7.3.9.2
  15. var func = GetV(O, P);
  16. // 7.3.9.4
  17. if (func == null) {
  18. return void 0;
  19. }
  20. // 7.3.9.5
  21. if (!IsCallable(func)) {
  22. throw new $TypeError(inspect(P) + ' is not a function: ' + inspect(func));
  23. }
  24. // 7.3.9.6
  25. return func;
  26. };