GetMethod.js 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. /**
  8. * 7.3.9 - https://ecma-international.org/ecma-262/6.0/#sec-getmethod
  9. * 1. Assert: IsPropertyKey(P) is true.
  10. * 2. Let func be GetV(O, P).
  11. * 3. ReturnIfAbrupt(func).
  12. * 4. If func is either undefined or null, return undefined.
  13. * 5. If IsCallable(func) is false, throw a TypeError exception.
  14. * 6. Return func.
  15. */
  16. module.exports = function GetMethod(O, P) {
  17. // 7.3.9.1
  18. if (!IsPropertyKey(P)) {
  19. throw new $TypeError('Assertion failed: IsPropertyKey(P) is not true');
  20. }
  21. // 7.3.9.2
  22. var func = GetV(O, P);
  23. // 7.3.9.4
  24. if (func == null) {
  25. return void 0;
  26. }
  27. // 7.3.9.5
  28. if (!IsCallable(func)) {
  29. throw new $TypeError(P + 'is not a function');
  30. }
  31. // 7.3.9.6
  32. return func;
  33. };