1'use strict';
2
3var anObject = require('./_an-object');
4var sameValue = require('./_same-value');
5var regExpExec = require('./_regexp-exec-abstract');
6
7// @@search logic
8require('./_fix-re-wks')('search', 1, function (defined, SEARCH, $search, maybeCallNative) {
9  return [
10    // `String.prototype.search` method
11    // https://tc39.github.io/ecma262/#sec-string.prototype.search
12    function search(regexp) {
13      var O = defined(this);
14      var fn = regexp == undefined ? undefined : regexp[SEARCH];
15      return fn !== undefined ? fn.call(regexp, O) : new RegExp(regexp)[SEARCH](String(O));
16    },
17    // `RegExp.prototype[@@search]` method
18    // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@search
19    function (regexp) {
20      var res = maybeCallNative($search, regexp, this);
21      if (res.done) return res.value;
22      var rx = anObject(regexp);
23      var S = String(this);
24      var previousLastIndex = rx.lastIndex;
25      if (!sameValue(previousLastIndex, 0)) rx.lastIndex = 0;
26      var result = regExpExec(rx, S);
27      if (!sameValue(rx.lastIndex, previousLastIndex)) rx.lastIndex = previousLastIndex;
28      return result === null ? -1 : result.index;
29    }
30  ];
31});
32