iterator-helper-without-closing-on-early-error.js 679 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var globalThis = require('../internals/global-this');
  3. // https://github.com/tc39/ecma262/pull/3467
  4. module.exports = function (METHOD_NAME, ExpectedError) {
  5. var Iterator = globalThis.Iterator;
  6. var IteratorPrototype = Iterator && Iterator.prototype;
  7. var method = IteratorPrototype && IteratorPrototype[METHOD_NAME];
  8. var CLOSED = false;
  9. if (method) try {
  10. method.call({
  11. next: function () { return { done: true }; },
  12. 'return': function () { CLOSED = true; }
  13. }, -1);
  14. } catch (error) {
  15. // https://bugs.webkit.org/show_bug.cgi?id=291195
  16. if (!(error instanceof ExpectedError)) CLOSED = false;
  17. }
  18. if (!CLOSED) return method;
  19. };