1 | 'use strict';
|
2 | var fixRegExpWellKnownSymbolLogic = require('../internals/fix-regexp-well-known-symbol-logic');
|
3 | var anObject = require('../internals/an-object');
|
4 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
5 | var sameValue = require('../internals/same-value');
|
6 | var regExpExec = require('../internals/regexp-exec-abstract');
|
7 |
|
8 |
|
9 | fixRegExpWellKnownSymbolLogic('search', 1, function (SEARCH, nativeSearch, maybeCallNative) {
|
10 | return [
|
11 |
|
12 |
|
13 | function search(regexp) {
|
14 | var O = requireObjectCoercible(this);
|
15 | var searcher = regexp == undefined ? undefined : regexp[SEARCH];
|
16 | return searcher !== undefined ? searcher.call(regexp, O) : new RegExp(regexp)[SEARCH](String(O));
|
17 | },
|
18 |
|
19 |
|
20 | function (regexp) {
|
21 | var res = maybeCallNative(nativeSearch, regexp, this);
|
22 | if (res.done) return res.value;
|
23 |
|
24 | var rx = anObject(regexp);
|
25 | var S = String(this);
|
26 |
|
27 | var previousLastIndex = rx.lastIndex;
|
28 | if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
|
29 | var result = regExpExec(rx, S);
|
30 | if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
|
31 | return result === null ? -1 : result.index;
|
32 | }
|
33 | ];
|
34 | });
|