'use strict';

var _toObject = require('./_to-object-329a650b.js');
var es6_string_iterator = require('./es6.string.iterator-cc0bbaa4.js');

// call something on iterator step with safe closing on error

var _iterCall = function (iterator, fn, value, entries) {
  try {
    return entries ? fn(_toObject._anObject(value)[0], value[1]) : fn(value);
  // 7.4.6 IteratorClose(iterator, completion)
  } catch (e) {
    var ret = iterator['return'];
    if (ret !== undefined) _toObject._anObject(ret.call(iterator));
    throw e;
  }
};

// check on default Array iterator

var ITERATOR = es6_string_iterator._wks('iterator');
var ArrayProto = Array.prototype;

var _isArrayIter = function (it) {
  return it !== undefined && (es6_string_iterator._iterators.Array === it || ArrayProto[ITERATOR] === it);
};

var ITERATOR$1 = es6_string_iterator._wks('iterator');
var SAFE_CLOSING = false;

try {
  var riter = [7][ITERATOR$1]();
  riter['return'] = function () { SAFE_CLOSING = true; };
  // eslint-disable-next-line no-throw-literal
  Array.from(riter, function () { throw 2; });
} catch (e) { /* empty */ }

var _iterDetect = function (exec, skipClosing) {
  if (!skipClosing && !SAFE_CLOSING) return false;
  var safe = false;
  try {
    var arr = [7];
    var iter = arr[ITERATOR$1]();
    iter.next = function () { return { done: safe = true }; };
    arr[ITERATOR$1] = function () { return iter; };
    exec(arr);
  } catch (e) { /* empty */ }
  return safe;
};

exports._isArrayIter = _isArrayIter;
exports._iterCall = _iterCall;
exports._iterDetect = _iterDetect;
