get-iterator.js 602 B

12345678910111213
  1. var call = require('../internals/function-call');
  2. var aCallable = require('../internals/a-callable');
  3. var anObject = require('../internals/an-object');
  4. var tryToString = require('../internals/try-to-string');
  5. var getIteratorMethod = require('../internals/get-iterator-method');
  6. var $TypeError = TypeError;
  7. module.exports = function (argument, usingIterator) {
  8. var iteratorMethod = arguments.length < 2 ? getIteratorMethod(argument) : usingIterator;
  9. if (aCallable(iteratorMethod)) return anObject(call(iteratorMethod, argument));
  10. throw $TypeError(tryToString(argument) + ' is not iterable');
  11. };