1 | 'use strict';
|
---|
2 |
|
---|
3 | // var Construct = require('es-abstract/2023/Construct');
|
---|
4 | var CreateRegExpStringIterator = require('es-abstract/2024/CreateRegExpStringIterator');
|
---|
5 | var Get = require('es-abstract/2024/Get');
|
---|
6 | var Set = require('es-abstract/2024/Set');
|
---|
7 | var SpeciesConstructor = require('es-abstract/2024/SpeciesConstructor');
|
---|
8 | var ToLength = require('es-abstract/2024/ToLength');
|
---|
9 | var ToString = require('es-abstract/2024/ToString');
|
---|
10 | var Type = require('es-abstract/2024/Type');
|
---|
11 | var flagsGetter = require('regexp.prototype.flags');
|
---|
12 | var setFunctionName = require('set-function-name');
|
---|
13 | var callBound = require('call-bind/callBound');
|
---|
14 | var GetIntrinsic = require('get-intrinsic');
|
---|
15 | var $TypeError = require('es-errors/type');
|
---|
16 |
|
---|
17 | var $indexOf = callBound('String.prototype.indexOf');
|
---|
18 |
|
---|
19 | var OrigRegExp = GetIntrinsic('%RegExp%');
|
---|
20 |
|
---|
21 | var supportsConstructingWithFlags = 'flags' in OrigRegExp.prototype;
|
---|
22 |
|
---|
23 | var constructRegexWithFlags = function constructRegex(C, R) {
|
---|
24 | var matcher;
|
---|
25 | // workaround for older engines that lack RegExp.prototype.flags
|
---|
26 | var flags = 'flags' in R ? Get(R, 'flags') : ToString(flagsGetter(R));
|
---|
27 | if (supportsConstructingWithFlags && typeof flags === 'string') {
|
---|
28 | matcher = new C(R, flags);
|
---|
29 | } else if (C === OrigRegExp) {
|
---|
30 | // workaround for older engines that can not construct a RegExp with flags
|
---|
31 | matcher = new C(R.source, flags);
|
---|
32 | } else {
|
---|
33 | matcher = new C(R, flags);
|
---|
34 | }
|
---|
35 | return { flags: flags, matcher: matcher };
|
---|
36 | };
|
---|
37 |
|
---|
38 | var regexMatchAll = setFunctionName(function SymbolMatchAll(string) {
|
---|
39 | var R = this;
|
---|
40 | if (Type(R) !== 'Object') {
|
---|
41 | throw new $TypeError('"this" value must be an Object');
|
---|
42 | }
|
---|
43 | var S = ToString(string);
|
---|
44 | var C = SpeciesConstructor(R, OrigRegExp);
|
---|
45 |
|
---|
46 | var tmp = constructRegexWithFlags(C, R);
|
---|
47 | // var flags = ToString(Get(R, 'flags'));
|
---|
48 | var flags = tmp.flags;
|
---|
49 | // var matcher = Construct(C, [R, flags]);
|
---|
50 | var matcher = tmp.matcher;
|
---|
51 |
|
---|
52 | var lastIndex = ToLength(Get(R, 'lastIndex'));
|
---|
53 | Set(matcher, 'lastIndex', lastIndex, true);
|
---|
54 | var global = $indexOf(flags, 'g') > -1;
|
---|
55 | var fullUnicode = $indexOf(flags, 'u') > -1;
|
---|
56 | return CreateRegExpStringIterator(matcher, S, global, fullUnicode);
|
---|
57 | }, '[Symbol.matchAll]', true);
|
---|
58 |
|
---|
59 | module.exports = regexMatchAll;
|
---|