GetMethod.js 680 B

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