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