source: imaps-frontend/node_modules/string.prototype.matchall/regexp-matchall.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.1 KB
Line 
1'use strict';
2
3// var Construct = require('es-abstract/2023/Construct');
4var CreateRegExpStringIterator = require('es-abstract/2024/CreateRegExpStringIterator');
5var Get = require('es-abstract/2024/Get');
6var Set = require('es-abstract/2024/Set');
7var SpeciesConstructor = require('es-abstract/2024/SpeciesConstructor');
8var ToLength = require('es-abstract/2024/ToLength');
9var ToString = require('es-abstract/2024/ToString');
10var Type = require('es-abstract/2024/Type');
11var flagsGetter = require('regexp.prototype.flags');
12var setFunctionName = require('set-function-name');
13var callBound = require('call-bind/callBound');
14var GetIntrinsic = require('get-intrinsic');
15var $TypeError = require('es-errors/type');
16
17var $indexOf = callBound('String.prototype.indexOf');
18
19var OrigRegExp = GetIntrinsic('%RegExp%');
20
21var supportsConstructingWithFlags = 'flags' in OrigRegExp.prototype;
22
23var 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
38var 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
59module.exports = regexMatchAll;
Note: See TracBrowser for help on using the repository browser.