implementation.js 894 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var hasPropertyDescriptors = require('has-property-descriptors')();
  4. var $TypeError = require('es-errors/type');
  5. var $defineProperty = hasPropertyDescriptors && GetIntrinsic('%Object.defineProperty%', true);
  6. var iterProto = require('iterator.prototype');
  7. var callBound = require('call-bind/callBound');
  8. var $isPrototypeOf = callBound('Object.prototype.isPrototypeOf');
  9. var $Iterator = typeof Iterator === 'function' ? Iterator : function Iterator() {
  10. if (
  11. !(this instanceof Iterator)
  12. || this.constructor === Iterator
  13. || !$isPrototypeOf(Iterator, this.constructor)
  14. ) {
  15. throw new $TypeError('`Iterator` can not be called or constructed directly');
  16. }
  17. };
  18. if ($Iterator.prototype !== iterProto) {
  19. $Iterator.prototype = iterProto;
  20. }
  21. $defineProperty($Iterator, 'prototype', { writable: false });
  22. module.exports = $Iterator;