get-iterator.js 652 B

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