GetMethod.js 663 B

12345678910111213141516171819202122232425262728293031323334
  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. // https://ecma-international.org/ecma-262/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(P + 'is not a function');
  22. }
  23. // 7.3.9.6
  24. return func;
  25. };