2 // https://tc39.github.io/String.prototype.matchAll/
3 var $export = require('./_export')
4 , defined = require('./_defined')
5 , toLength = require('./_to-length')
6 , isRegExp = require('./_is-regexp')
7 , getFlags = require('./_flags')
8 , RegExpProto = RegExp.prototype;
10 var $RegExpStringIterator = function(regexp, string){
15 require('./_iter-create')($RegExpStringIterator, 'RegExp String', function next(){
16 var match = this._r.exec(this._s);
17 return {value: match, done: match === null};
20 $export($export.P, 'String', {
21 matchAll: function matchAll(regexp){
23 if(!isRegExp(regexp))throw TypeError(regexp + ' is not a regexp!');
25 , flags = 'flags' in RegExpProto ? String(regexp.flags) : getFlags.call(regexp)
26 , rx = new RegExp(regexp.source, ~flags.indexOf('g') ? flags : 'g' + flags);
27 rx.lastIndex = toLength(regexp.lastIndex);
28 return new $RegExpStringIterator(rx, S);