source: imaps-frontend/node_modules/string.prototype.matchall/implementation.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.0 KB
Line 
1'use strict';
2
3var Call = require('es-abstract/2024/Call');
4var Get = require('es-abstract/2024/Get');
5var GetMethod = require('es-abstract/2024/GetMethod');
6var IsRegExp = require('es-abstract/2024/IsRegExp');
7var ToString = require('es-abstract/2024/ToString');
8var RequireObjectCoercible = require('es-object-atoms/RequireObjectCoercible');
9var callBound = require('call-bind/callBound');
10var hasSymbols = require('has-symbols')();
11var flagsGetter = require('regexp.prototype.flags');
12var GetIntrinsic = require('get-intrinsic');
13var $TypeError = require('es-errors/type');
14
15var $RegExp = GetIntrinsic('%RegExp%');
16var $indexOf = callBound('String.prototype.indexOf');
17
18var regexpMatchAllPolyfill = require('./polyfill-regexp-matchall');
19
20var getMatcher = function getMatcher(regexp) { // eslint-disable-line consistent-return
21 var matcherPolyfill = regexpMatchAllPolyfill();
22 if (hasSymbols && typeof Symbol.matchAll === 'symbol') {
23 var matcher = GetMethod(regexp, Symbol.matchAll);
24 if (matcher === $RegExp.prototype[Symbol.matchAll] && matcher !== matcherPolyfill) {
25 return matcherPolyfill;
26 }
27 return matcher;
28 }
29 // fallback for pre-Symbol.matchAll environments
30 if (IsRegExp(regexp)) {
31 return matcherPolyfill;
32 }
33};
34
35module.exports = function matchAll(regexp) {
36 var O = RequireObjectCoercible(this);
37
38 if (typeof regexp !== 'undefined' && regexp !== null) {
39 var isRegExp = IsRegExp(regexp);
40 if (isRegExp) {
41 // workaround for older engines that lack RegExp.prototype.flags
42 var flags = 'flags' in regexp ? Get(regexp, 'flags') : flagsGetter(regexp);
43 RequireObjectCoercible(flags);
44 if ($indexOf(ToString(flags), 'g') < 0) {
45 throw new $TypeError('matchAll requires a global regular expression');
46 }
47 }
48
49 var matcher = getMatcher(regexp);
50 if (typeof matcher !== 'undefined') {
51 return Call(matcher, regexp, [O]);
52 }
53 }
54
55 var S = ToString(O);
56 // var rx = RegExpCreate(regexp, 'g');
57 var rx = new $RegExp(regexp, 'g');
58 return Call(getMatcher(rx), rx, [S]);
59};
Note: See TracBrowser for help on using the repository browser.