_iter-detect.js 645 B

12345678910111213141516171819202122
  1. var ITERATOR = require('./_wks')('iterator');
  2. var SAFE_CLOSING = false;
  3. try {
  4. var riter = [7][ITERATOR]();
  5. riter['return'] = function () { SAFE_CLOSING = true; };
  6. // eslint-disable-next-line no-throw-literal
  7. Array.from(riter, function () { throw 2; });
  8. } catch (e) { /* empty */ }
  9. module.exports = function (exec, skipClosing) {
  10. if (!skipClosing && !SAFE_CLOSING) return false;
  11. var safe = false;
  12. try {
  13. var arr = [7];
  14. var iter = arr[ITERATOR]();
  15. iter.next = function () { return { done: safe = true }; };
  16. arr[ITERATOR] = function () { return iter; };
  17. exec(arr);
  18. } catch (e) { /* empty */ }
  19. return safe;
  20. };