[6a3a178] | 1 | 'use strict';
|
---|
| 2 | var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
|
---|
| 3 | var anObject = require('../internals/an-object');
|
---|
| 4 | var toLength = require('../internals/to-length');
|
---|
| 5 | var toString = require('../internals/to-string');
|
---|
| 6 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
| 7 | var advanceStringIndex = require('../internals/advance-string-index');
|
---|
| 8 | var regExpExec = require('../internals/regexp-exec-abstract');
|
---|
| 9 |
|
---|
| 10 | // @@match logic
|
---|
| 11 | fixRegExpWellKnownSymbolLogic('match', function (MATCH, nativeMatch, maybeCallNative) {
|
---|
| 12 | return [
|
---|
| 13 | // `String.prototype.match` method
|
---|
| 14 | // https://tc39.es/ecma262/#sec-string.prototype.match
|
---|
| 15 | function match(regexp) {
|
---|
| 16 | var O = requireObjectCoercible(this);
|
---|
| 17 | var matcher = regexp == undefined ? undefined : regexp[MATCH];
|
---|
| 18 | return matcher !== undefined ? matcher.call(regexp, O) : new RegExp(regexp)[MATCH](toString(O));
|
---|
| 19 | },
|
---|
| 20 | // `RegExp.prototype[@@match]` method
|
---|
| 21 | // https://tc39.es/ecma262/#sec-regexp.prototype-@@match
|
---|
| 22 | function (string) {
|
---|
| 23 | var rx = anObject(this);
|
---|
| 24 | var S = toString(string);
|
---|
| 25 | var res = maybeCallNative(nativeMatch, rx, S);
|
---|
| 26 |
|
---|
| 27 | if (res.done) return res.value;
|
---|
| 28 |
|
---|
| 29 | if (!rx.global) return regExpExec(rx, S);
|
---|
| 30 |
|
---|
| 31 | var fullUnicode = rx.unicode;
|
---|
| 32 | rx.lastIndex = 0;
|
---|
| 33 | var A = [];
|
---|
| 34 | var n = 0;
|
---|
| 35 | var result;
|
---|
| 36 | while ((result = regExpExec(rx, S)) !== null) {
|
---|
| 37 | var matchStr = toString(result[0]);
|
---|
| 38 | A[n] = matchStr;
|
---|
| 39 | if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode);
|
---|
| 40 | n++;
|
---|
| 41 | }
|
---|
| 42 | return n === 0 ? null : A;
|
---|
| 43 | }
|
---|
| 44 | ];
|
---|
| 45 | });
|
---|